Robot explodes when setting position

Typically: "How do I... ", "How can I... " questions
Post Reply
bwdrop

Robot explodes when setting position

Post by bwdrop » 06 Nov 2014, 16:21

Hello,

I am trying to run many simulations of a robot in order to find the best movement sequence for him to move.
To do so, our robot is controlled by a child script and we need to frequently reset the robot's position and orientation.

However, every time we try to reset its position (through the simxSetObjectPosition function), the robot "explodes".
I tried looking at the scene and checking whether the joints were dynamically enabled or not, but I couldn't find anything.

Can anyone take a look at my scene ?
http://www.speedyshare.com/crgST/2W1A.ttt

Thanks in advance,

Sincerely,
Bwdrop

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

Re: Robot explodes when setting position

Post by coppelia » 06 Nov 2014, 17:22

Hello,

if you try to instantaneously change the position/orientation of the robot, you try to do something that is impossible in reality. So if you simply move one body to a different position, the other attached bodies will have very high constraints acting on them.

You have several options to overcome this:
  • the best would be to erase the robot, and load it again (simxLoadModel when using the remote API)
  • another option would be to dynamically reset all objects in the model once you have changed the position of the base. Have a look at this post.
When resetting all the objects in a model, and doing this from a threaded child script, you need to make sure you won't be interrupted during the whole procedure. That's why you need to disable the thread automatic switching temporarily:

Code: Select all

simSetThreadAutomaticSwitch(false)
-- do your thing
simSetThreadAutomaticSwitch(true)
Cheers

Eric
Posts: 186
Joined: 11 Feb 2013, 16:39

Re: Robot explodes when setting position

Post by Eric » 07 Nov 2014, 03:56

hi

From an old post:

Code: Select all

simSetThreadAutomaticSwitch(false)
    --moving the dynamic object
    t={robotHandle}
    while (#t~=0) do
       h=t[1]
       simResetDynamicObject(h)
       table.remove(t,1)
       ind=0
       child=simGetObjectChild(h,ind)
       while (child~=-1) do
          table.insert(t,child)
          ind=ind+1
          child=simGetObjectChild(h,ind)
       end
    end
    --moving the robot to the new position  and orientation 
    simSetObjectPosition(robotHandle,-1,newPosition)
    simSetObjectOrientation(robotHandle,-1,newOrientation)
simSetThreadAutomaticSwitch(true)
Cheers

Eric

bwdrop

Re: Robot explodes when setting position

Post by bwdrop » 27 Nov 2014, 12:12

Hello again, and thanks for the replies !

I have been testing again with the remote API, trying to reset the robot's position through it.
I am using the remote API in C/C++, and I have some trouble trying to access the robot's childs to erase them.

To access the robot's childs, I use the function simxGetObjectChild like this:

Code: Select all

std::vector<int> handles;
handles.push_back(_robot);
setOperationMode(opmode_oneshot_wait);

for (int i = 0; i < handles.size(); ++i)
{
	printf("handle n.%d = %d\n", i, handles[i]);
	int idx = 0;
	int child = -1;
	simxGetObjectChild(_clientID, handles[i], idx, &child, _operationMode);
	while (child != -1)
	{
		handles.push_back(child);
		printf(" -> child n.%d = %d\n", idx, child);
		++idx;
		simxGetObjectChild(_clientID, handles[i], idx, &child, _operationMode);
	}
}
The thing is, child's value isn't changed after I called the function.
Even if I initialize the child variable to 2 for example, it's still the same value after I called the function, resulting in an infinite loop.

Did I use the function incorrectly ?

Sincerely yours,
bwdrop

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

Re: Robot explodes when setting position

Post by coppelia » 28 Nov 2014, 00:29

Hello,

the code looks ok, and works here. Are you sure _operationMode is really set to simx_opmode_oneshot_wait? You use a strange value of opmode_oneshot_wait (missing simx_).

Cheers

bwdrop

Re: Robot explodes when setting position

Post by bwdrop » 28 Nov 2014, 01:13

Hello,

The value opmode_oneshot_wait is only a custom enumeration set to simx_opmode_oneshot_wait.
When I initialize child's value to 2, I get this output:

Image

I'll see if I can find a workaround, and update if it's the case ! :)

Sincerely,
bwdrop

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

Re: Robot explodes when setting position

Post by coppelia » 30 Nov 2014, 21:21

you must be doing something wrong. Try to use the value of simx_opmode_oneshot_wait, and text it maybe inside of the bubbleRobClient project (located in programming/bubbleRobClient). Again, it is working fine here.

Cheers

Post Reply