sim.getObjectPosition

Typically: "How do I... ", "How can I... " questions
Post Reply
Sirena
Posts: 4
Joined: 30 Oct 2018, 16:54

sim.getObjectPosition

Post by Sirena » 31 Oct 2018, 11:22

hi guys!
I'm using vrep with matlab through ROS to simulate a drone.
To implement the control strategy in Matlab I need the signals from the sensors and the speed and position of my drone, changing in time during the simulation.
In Simulink and Matlab the data of sensors are available with the same values in Vrep, but the position and speed values are still the same (I mean the start conditon).
I used suggestions that I found in other topics, to use LUA command sim.getObjectposition and sim.getVelocity.
These are my commands:
sim.getObjectPosition(sim.getObjectHandle("Hexacopter"),-1)
sim.getVelocity(hexaHandle)
In your opinion, are there something wrong?
Thanks for yours support and suggestions
Sirena

coppelia
Site Admin
Posts: 6800
Joined: 14 Dec 2012, 00:25

Re: sim.getObjectPosition

Post by coppelia » 07 Nov 2018, 07:46

Hello,

how exactly are you using those commands from Matlab? Via blocking call or streaming?

Cheers

Sirena
Posts: 4
Joined: 30 Oct 2018, 16:54

Re: sim.getObjectPosition

Post by Sirena » 07 Nov 2018, 13:48

Hello,
I'm using ROS to let Simulink and V-rep communicate.
I tried to use the remote API via blocking call, but I understood that it isn't possible to enter data directly in Simulink.

Thanks for your assistance,

Sirena

coppelia
Site Admin
Posts: 6800
Joined: 14 Dec 2012, 00:25

Re: sim.getObjectPosition

Post by coppelia » 09 Nov 2018, 16:11

Are you using the correct values for publishing? e.g. is the object really moving, or are you mistakenly using the handle of an object that is not moving? Try adding print directives just before publishing the data to see what the data is, and so that you can locate where the problem occurs.

Cheers

Sirena
Posts: 4
Joined: 30 Oct 2018, 16:54

Re: sim.getObjectPosition

Post by Sirena » 12 Nov 2018, 11:45

Hi!
I tried your suggestion. As you said, on the console in V-rep I can see the same values I read on Simulink display. (These values are different from zero, as in the initial condition.)
At the same time I added a graph with the object position and Z-velocity and these values change during the simulation. So the object is really moving.
What can I do now? Is there anything wrong with the reference frames?

Regards,

Sirena

coppelia
Site Admin
Posts: 6800
Joined: 14 Dec 2012, 00:25

Re: sim.getObjectPosition

Post by coppelia » 14 Nov 2018, 07:41

Best would be to prepare a minimalistic, self-contained example that illustrates your problem (e.g. a scene when you print the values to the console, and where you draw the same values to a graph).

Cheers

Sirena
Posts: 4
Joined: 30 Oct 2018, 16:54

Re: sim.getObjectPosition

Post by Sirena » 15 Nov 2018, 17:02

Unfortunately I have already tried with a simplified example: a cube that moved from its original position to another one. And the result of the prevoius commands was still the initial condition, even if the cube was moving.
However today I probably found the solution for the problem: the command strings were under sysCall_actuation and not under sysCall_sensing. After this change, now my commands seem to work correctly.
Thanks for your help,

Sirena

Post Reply