Gazebo | Ignition | Community
Ask Your Question

Setting initial velocity in plugin

asked 2018-02-07 03:19:47 -0500

Edwin Walsh gravatar image

updated 2018-02-28 06:04:00 -0500

I am trying to have a model rotate along a Lissajous curve. I am using torques to set the angular acceleration to be able to simulate this movement.

For this to work, I have to set the initial angular velocity.

I tried this by adding a parameter which checks if the update method has run before, and then set the angular velocity the first time the Update method of the plugin is called.

if (!this->dataPtr->runOnce){
    this->dataPtr->runOnce = true;

However, if I print out the


I can see that it is set, but the next time the Update method is called, it is already set to a value close to zero.

Just to be sure I added a delay before setting the torques, but they don't have any influence on the initial value, so they must be reset somewhere else...

Any idea what I am doing wrong?

EDIT 1 Based on the comments some additional information:

Each timestep I set the forces/torques working on the model. If I do not set an initial velocity, I can see that my velocity changes each timestep according to the formula v = v0 + a*dT, with a = F/m. I set the mass of the model to 1 for easy calculation of the required force.

However, if I do set the initial velocity (using the instantaneous method) I can see that in t=0, the velocity is set to the requested value, but that in the next timestep, the velocity is calculated as in the formula above, but with v0 = 0 instead of v0 = "the requested value"

I want to have my model move according to a set pattern, and for this to work I need to be able to set an initial velocity.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-02-07 09:02:37 -0500

Brosseau.F gravatar image

I suggest you to take a look at this tutorial :

Maybe you will have to play with some parameters of your link like the friction to make it enable to keep some velocity.

Take a look at the surface tag which contains friction parameters.

edit flag offensive delete link more


Your answer does not make sense to me. In a friction-less environment you would expect a velocity to stay constant, since no forces are applied (other then gravity, but that is turned off on the link in this case). Adding friction would add a force that would slow the object down. This would only explain the results I see (having a speed during only one timestep), if friction is so high that the speed is instantly reduced to zero. There is however no collision tag set (so no friction).

Edwin Walsh gravatar imageEdwin Walsh ( 2018-02-12 05:43:41 -0500 )edit

It's not because you didn't put a collision tag that there is no friction. According to this : Default values for mu1 and mu2 are set to 1.0 (max friction).

Brosseau.F gravatar imageBrosseau.F ( 2018-02-15 01:48:53 -0500 )edit

You may try to add a collision tag with low (or 0) value or you can try to set your link to be kinematic (

Brosseau.F gravatar imageBrosseau.F ( 2018-02-15 01:58:14 -0500 )edit

Thank you very much! I totally missed that the default values for mu1 and mu2 are set to the max friction. Both solutions you provided now give me the expected results.

Edwin Walsh gravatar imageEdwin Walsh ( 2018-02-21 05:48:41 -0500 )edit

I was a little premature with my previous comment. Making it kinematic obviously disables the friction, but setting the values for mu and mu2 does not seem to do the trick. I tried setting these values only on the canonical link, but also on all other links of the model. I also tried setting the friction values for bullet (just in case for some reason gazebo was using bullet), but none of these seem to remove the friction.

Edwin Walsh gravatar imageEdwin Walsh ( 2018-02-21 06:42:11 -0500 )edit

Perhaps I should also add that the element that I am trying to give an initial velocity has gravity turned off, and is floating in the air. That is one of the other reasons why I suspect that there is an other issue other then friction.

Edwin Walsh gravatar imageEdwin Walsh ( 2018-02-21 06:45:34 -0500 )edit

As said in one of the tutorials, it seems that SetVelocity need to be set at each iteration step. You can try to directly apply a force on your link. There is a link that may help you in that way :

Brosseau.F gravatar imageBrosseau.F ( 2018-02-22 05:00:02 -0500 )edit

I added some extra information to the question, since it doesn't fit in a comment.

Edwin Walsh gravatar imageEdwin Walsh ( 2018-02-28 06:05:04 -0500 )edit

Question Tools

1 follower


Asked: 2018-02-07 03:19:47 -0500

Seen: 872 times

Last updated: Feb 28 '18