Search code examples
webots

Motor as Velocity Sensor?


I have read the FAQ on how to get velocities from nodes. Yet, of the methods described, none feature a way to get the velocity from a passive servo motor (motor sensing).

I'm trying to use a motor, set to torque 0, which makes it 'loose', as a velocity sensor for an attached inversed pendulum.

The standard motor node has the .getVelocity() method which should allow to receive velocity applied to the motor. In real servos, these would even provide data in passive mode. However in webots, the API describes:

Note that if the velocity is not explicitly set using the wb_motor_set_velocity function, then the wb_motor_get_velocity and wb_motor_get_max_velocity functions return the same value.

Why is that so, and is there any way to use a passive motor/servo for velocity measurment, like one would do with a real servo?


Solution

  • To get the velocity you should not rely on the Motor API, but rather use a position sensor: https://www.cyberbotics.com/doc/reference/positionsensor

    The position sensor allows you to get the current position of a joint (e.g. its angle for a rotational joint). Then, from the position, you can easily compute the speed of the joint (simply take the difference between current position and position at previous step and divide it by the time difference (i.e. the time step fo the controller)).