Sheila
Sheila

Reputation: 35

Motor/Sensor in Webots vs. Pycharm

When I am debugging my webots controller in Pycharm, I noticed that a motor will have two constants: LINEAR and ROTATIONAL.

The proto for the NAO lists "RShoulderPitch" as a rotational motor (for a Hinge2Joint), but in PyCharm, the motor returned by the following code

r_shoulder_pitch = getMotor("RShoulderPitch")

has the constants as follows: LINEAR=1 and ROTATIONAL=0.

Maybe I am misunderstanding these constants, but should it not be the reverse (i.e. ROTATIONAL=1 and LINEAR=0)?

Note: A position sensor returned by

r_shoulder_pitch.getPositionSensor()

also has the following constants in PyCharm: ANGULAR=0, LINEAR=1, ROTATIONAL=0.

Upvotes: 1

Views: 136

Answers (1)

FabienRohrer
FabienRohrer

Reputation: 1834

This is not very "pythonic", but Motor.LINEAR and Motor.ROTATIONAL are constants to compare the return values of the Motor.getType() function. These constants do not contain the type of the current motor.

A typical usage is:

my_motor = my_robot.getMotor('RShoulderPitch')
if my_motor.getType() == Motor.ROTATIONAL:
    print('my motor is rotational')
else:
    print('my motor is linear')

I also have 2 advices:

  • I would recommend you to use the Webots reference manual rather than digging in the Python object states. Indeed, the Python library is created automatically using SWIG, so the resulting objects are quite complex.
  • The Nao shoulders are indeed modeled using an Hinge2Joint. This allows to deal with 2 joints with the performance of one. But this is an optimization. The API only sees the device level (the Motors in this case). So there is no need to know that it's an Hinge2Joint to use it.

Upvotes: 1

Related Questions