Pololu

class Pololu(*args, **kwargs)

Bases: pybind11_object

Interface for the Pololu Maestro USB Servo Controllers.

See https://www.pololu.com/category/102/maestro-usb-servo-controllers for more details.

This class give a position and velocity control for the servo motors plugged into the board on a given channel. If you want to control two or more servo motors, you need to instanciate a new object for each additional servo motor. An example is given in the vpRobotPololuPtu class that allows to control a pan-tilt unit with two servo motors.

It implements a velocity controller that runs in a separate thread.

  • A servomotor can be position-controlled by giving it position commands in pwm units using setPwmPosition() or in angles expressed in radians using setAngularPosition() .

  • It can be also velocity-controller by giving it velocity commands in pwm units using setPwmVelocity() or in ras/s using setAngularVelocity() .

The conversion between pwm units and radians positions is done using radToPwm() or pwmToRad() . For velocity control conversion from pwm units and rad/s is done using speedToRadS() and radSToSpeed() .

Each servo has a pwm position range that could be retrieved using calibrate() and set using set using setPwmRange() .

It is the user responsability to set the corresponding angular range using setAngularRange() .

Overloaded function.

  1. __init__(self: visp._visp.robot.Pololu, verbose: bool = false) -> None

Default constructor.

You need to call connect() to setup the serial link with the Pololu board.

Parameters:
verbose

When true enable verbose mode.

  1. __init__(self: visp._visp.robot.Pololu, device: str, baudrate: int = 38400, channel: int = 0, verbose: bool = false) -> None

Constructor that enables the serial link with the Pololu board calling internally connect() . The velocity controller thread is created in the constructor and will run independently of the rest of the class. You can set velocity commands using setPwmVelocity() or setAngularVelocity() .

Parameters:
device

Serial device name to dial with Pololu board.

baudrate

Baudrate used to dial with Pololu board. Note that this parameter is only used on Windows.

channel

Channel to which the servo is connected to the Pololu board.

verbose

When true enable verbose mode.

Methods

__init__

Overloaded function.

calibrate

Move servo motor to minimal pwm position and then to maximal pwm position to retrieve min and max pwm values.

connect

Open a connection with the Pololu board.

connected

Check if the serial connection is still up.

getAngularPosition

Return angular position in rad.

getPwmPosition

Return PWM position.

getRangeAngles

Get min, max and range for angle cmd.

getRangePwm

Get min, max range for PWM cmd.

pwmToRad

Convert a PWM value to an angle in radians.

radSToSpeed

Convert deg/s speed into Pololu's speed.

radToPwm

Convert angles in radians to PWM for servo commands.

setAngularPosition

Set the position to reach in angle.

setAngularRange

Set min and max axis angles range in rad.

setAngularVelocity

Set the angular velocity of the motor movements in rad/s.

setPwmPosition

Set the position to reach in PWM.

setPwmRange

Set min, max PWM cmd.

setPwmVelocity

Set the pwm velocity of the motor movements.

setVerbose

Enable/disable verbose mode.

speedToRadS

Convert Pololu's pwm velocity to rad/s velocity.

stopVelocityCmd

Stop the velocity command thread.

Inherited Methods

Operators

__doc__

__init__

Overloaded function.

__module__

Attributes

__annotations__

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.robot.Pololu, verbose: bool = false) -> None

Default constructor.

You need to call connect() to setup the serial link with the Pololu board.

Parameters:
verbose

When true enable verbose mode.

  1. __init__(self: visp._visp.robot.Pololu, device: str, baudrate: int = 38400, channel: int = 0, verbose: bool = false) -> None

Constructor that enables the serial link with the Pololu board calling internally connect() . The velocity controller thread is created in the constructor and will run independently of the rest of the class. You can set velocity commands using setPwmVelocity() or setAngularVelocity() .

Parameters:
device

Serial device name to dial with Pololu board.

baudrate

Baudrate used to dial with Pololu board. Note that this parameter is only used on Windows.

channel

Channel to which the servo is connected to the Pololu board.

verbose

When true enable verbose mode.

calibrate(self, pwm_min: int, pwm_max: int) None

Move servo motor to minimal pwm position and then to maximal pwm position to retrieve min and max pwm values.

Parameters:
pwm_min: int

Min position (pwm).

pwm_max: int

Max position (pwm).

connect(self, device: str, baudrate: int, channel: int) None

Open a connection with the Pololu board.

Parameters:
device: str

Serial device name to dial with Pololu board.

baudrate: int

Baudrate used to dial with Pololu board. Note that this parameter is only used on Windows.

channel: int

Channel to which the servo is connected to the Pololu board.

connected(self) bool

Check if the serial connection is still up.

Returns:

true is the connection is enabled, false if the board is not connected.

getAngularPosition(self) float

Return angular position in rad.

Returns:

Current position in rad.

getPwmPosition(self) int

Return PWM position.

Returns:

Current PWM position.

getRangeAngles(self, minAngle: float, maxAngle: float) tuple[float, float]

Get min, max and range for angle cmd.

Note

See setAngularRange()

Parameters:
minAngle: float

Min range value for angle control.

maxAngle: float

Max range value for angle control.

Returns:

A tuple containing:

  • minAngle: Min range value for angle control.

  • maxAngle: Max range value for angle control.

getRangePwm(self, min: int, max: int) None

Get min, max range for PWM cmd.

Note

See setPwmRange()

Parameters:
min: int

Min value for PWM control.

max: int

Max value for PWM control.

pwmToRad(self, pwm: int) float

Convert a PWM value to an angle in radians.

Note

See radToPwm()

Parameters:
pwm: int

PWM value.

Returns:

Corresponding angle value in radian for the PWM.

radSToSpeed(self, speed_rad_s: float) int

Convert deg/s speed into Pololu’s speed.

Note

See speedToRadS()

Parameters:
speed_rad_s: float

Speed converted to rad/s.

Returns:

Signed speed in units of (0.25 us)/(10 ms).

radToPwm(self, angle: float) int

Convert angles in radians to PWM for servo commands.

Note

See pwmToRad()

Parameters:
angle: float

Angle in radian to convert.

Returns:

Corresponding PWM value for the angle.

setAngularPosition(self: visp._visp.robot.Pololu, pos_rad: float, vel_rad_s: float = 0.f) None

Set the position to reach in angle.

Parameters:
pos_rad

Position to reach in radians.

vel_rad_s

Velocity to use for the positioning in rad/s. Default is ‘0’ and will use maximum speed.

setAngularRange(self, min_angle: float, max_angle: float) None

Set min and max axis angles range in rad.

Note

See getRangeAngles()

Parameters:
min_angle: float

Min value for angle (rad).

max_angle: float

Max value for angle (rad).

setAngularVelocity(self, vel_rad_s: float) None

Set the angular velocity of the motor movements in rad/s.

Parameters:
vel_rad_s: float

Velocity to apply for movement in rad/s.

setPwmPosition(self, pos_pwm: int, speed_pwm: int) None

Set the position to reach in PWM.

Parameters:
pos_pwm: int

Position in PWM to reach.

speed_pwm: int

Speed to use for movement in units of (0.25 us)/(10 ms). Default is 0, maximum speed.

setPwmRange(self, min_pwm: int, max_pwm: int) None

Set min, max PWM cmd.

Note

See getRangePwm()

Parameters:
min_pwm: int

Min value for PWM control.

max_pwm: int

Max value for PWM control.

setPwmVelocity(self, pwm_vel: int) None

Set the pwm velocity of the motor movements. The motor will move to the edge of the range at the given speed.

Parameters:
pwm_vel: int

PWM velocity to use for movement in units of (0.25 us)/(10 ms). When set to 0, will use the maximum speed.

setVerbose(self, verbose: bool) None

Enable/disable verbose mode.

Parameters:
verbose: bool

Set to true to enable verbose mode, false otherwise.

speedToRadS(self, speed: int) float

Convert Pololu’s pwm velocity to rad/s velocity.

Note

See radSToSpeed()

Parameters:
speed: int

Signed speed in units of (0.25 us)/(10 ms).

Returns:

Speed converted to rad/s.

stopVelocityCmd(self) None

Stop the velocity command thread.