Visual Servoing Platform
version 3.6.1 under development (2024-12-17)
|
#include <visp3/robot/vpPololu.h>
Public Member Functions | |
vpPololu (bool verbose=false) | |
vpPololu (const std::string &device, int baudrate=38400, int channel=0, bool verbose=false) | |
virtual | ~vpPololu () |
void | calibrate (unsigned short &pwm_min, unsigned short &pwm_max) |
void | connect (const std::string &device, int baudrate, int channel) |
bool | connected () const |
float | getAngularPosition () const |
unsigned short | getPwmPosition () const |
void | getRangeAngles (float &minAngle, float &maxAngle) const |
void | getRangePwm (unsigned short &min, unsigned short &max) |
void | setAngularPosition (float pos_rad, float vel_rad_s=0.f) |
void | setAngularRange (float min_angle, float max_angle) |
void | setAngularVelocity (float vel_rad_s) |
void | setPwmPosition (unsigned short pos_pwm, unsigned short speed_pwm=0) |
void | setPwmRange (unsigned short min_pwm, unsigned short max_pwm) |
void | setPwmVelocity (short pwm_vel) |
void | setVerbose (bool verbose) |
void | stopVelocityCmd () |
Public Member Functions for Conversion | |
float | pwmToRad (unsigned short pwm) const |
unsigned short | radToPwm (float angle) const |
short | radSToSpeed (float speed_rad_s) const |
float | speedToRadS (short speed) const |
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.
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().
Definition at line 75 of file vpPololu.h.
vpPololu::vpPololu | ( | bool | verbose = false | ) |
Default constructor.
[in] | verbose | : When true enable verbose mode. |
You need to call connect() to setup the serial link with the Pololu board.
Definition at line 54 of file vpPololu.cpp.
vpPololu::vpPololu | ( | const std::string & | device, |
int | baudrate = 38400 , |
||
int | channel = 0 , |
||
bool | verbose = false |
||
) |
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().
[in] | device | : Serial device name to dial with Pololu board. |
[in] | baudrate | : Baudrate used to dial with Pololu board. Note that this parameter is only used on Windows. |
[in] | channel | : Channel to which the servo is connected to the Pololu board. |
[in] | verbose | : When true enable verbose mode. |
Definition at line 59 of file vpPololu.cpp.
References connect().
|
virtual |
Destructor.
Definition at line 91 of file vpPololu.cpp.
void vpPololu::calibrate | ( | unsigned short & | pwm_min, |
unsigned short & | pwm_max | ||
) |
Move servo motor to minimal pwm position and then to maximal pwm position to retrieve min and max pwm values.
[out] | pwm_min | : Min position (pwm). |
[out] | pwm_max | : Max position (pwm). |
Definition at line 103 of file vpPololu.cpp.
References vpException::fatalError, and getPwmPosition().
void vpPololu::connect | ( | const std::string & | device, |
int | baudrate, | ||
int | channel | ||
) |
Open a connection with the Pololu board.
[in] | device | : Serial device name to dial with Pololu board. |
[in] | baudrate | : Baudrate used to dial with Pololu board. Note that this parameter is only used on Windows. |
[in] | channel | : Channel to which the servo is connected to the Pololu board. |
Definition at line 66 of file vpPololu.cpp.
References vpRobotException::constructionError.
Referenced by vpPololu(), and vpRobotPololuPtu::vpRobotPololuPtu().
bool vpPololu::connected | ( | ) | const |
Check if the serial connection is still up.
Definition at line 129 of file vpPololu.cpp.
float vpPololu::getAngularPosition | ( | ) | const |
Return angular position in rad.
Definition at line 166 of file vpPololu.cpp.
References getPwmPosition(), and pwmToRad().
Referenced by vpRobotPololuPtu::getPosition().
unsigned short vpPololu::getPwmPosition | ( | ) | const |
Return PWM position.
Definition at line 145 of file vpPololu.cpp.
References vpException::fatalError.
Referenced by calibrate(), getAngularPosition(), setPwmVelocity(), and stopVelocityCmd().
void vpPololu::getRangeAngles | ( | float & | minAngle, |
float & | maxAngle | ||
) | const |
Get min, max and range for angle cmd.
[out] | minAngle | : Min range value for angle control. |
[out] | maxAngle | : Max range value for angle control. |
Definition at line 174 of file vpPololu.cpp.
void vpPololu::getRangePwm | ( | unsigned short & | min, |
unsigned short & | max | ||
) |
Get min, max range for PWM cmd.
[out] | min | : Min value for PWM control. |
[out] | max | Max value for PWM control. |
Definition at line 180 of file vpPololu.cpp.
float vpPololu::pwmToRad | ( | unsigned short | pwm | ) | const |
Convert a PWM value to an angle in radians.
[in] | pwm | : PWM value. |
Definition at line 186 of file vpPololu.cpp.
Referenced by getAngularPosition().
short vpPololu::radSToSpeed | ( | float | speed_rad_s | ) | const |
Convert deg/s speed into Pololu's speed.
speed_rad_s | : Speed converted to rad/s. |
Definition at line 140 of file vpPololu.cpp.
Referenced by setAngularPosition(), and setAngularVelocity().
unsigned short vpPololu::radToPwm | ( | float | angle | ) | const |
Convert angles in radians to PWM for servo commands.
angle | : Angle in radian to convert. |
Definition at line 121 of file vpPololu.cpp.
Referenced by setAngularPosition().
void vpPololu::setAngularPosition | ( | float | pos_rad, |
float | vel_rad_s = 0.f |
||
) |
Set the position to reach in angle.
[in] | pos_rad | : Position to reach in radians. |
[in] | vel_rad_s | : Velocity to use for the positioning in rad/s. Default is '0' and will use maximum speed. |
Definition at line 194 of file vpPololu.cpp.
References vpRobotException::positionOutOfRangeError, radSToSpeed(), radToPwm(), and setPwmPosition().
Referenced by vpRobotPololuPtu::setPosition().
|
inline |
Set min and max axis angles range in rad.
[in] | min_angle | : Min value for angle (rad). |
[in] | max_angle | : Max value for angle (rad). |
Definition at line 184 of file vpPololu.h.
Referenced by vpRobotPololuPtu::vpRobotPololuPtu().
void vpPololu::setAngularVelocity | ( | float | vel_rad_s | ) |
Set the angular velocity of the motor movements in rad/s.
[in] | vel_rad_s | : Velocity to apply for movement in rad/s. |
Definition at line 239 of file vpPololu.cpp.
References radSToSpeed(), and setPwmVelocity().
Referenced by vpRobotPololuPtu::setVelocity().
void vpPololu::setPwmPosition | ( | unsigned short | pos_pwm, |
unsigned short | speed_pwm = 0 |
||
) |
Set the position to reach in PWM.
[in] | pos_pwm | : Position in PWM to reach. |
[in] | speed_pwm | : Speed to use for movement in units of (0.25 us)/(10 ms). Default is 0, maximum speed. |
When | PWM out of range. |
Definition at line 211 of file vpPololu.cpp.
References vpException::fatalError, and vpRobotException::positionOutOfRangeError.
Referenced by setAngularPosition(), and stopVelocityCmd().
|
inline |
Set min, max PWM cmd.
[in] | min_pwm | : Min value for PWM control. |
[in] | max_pwm | : Max value for PWM control. |
Definition at line 218 of file vpPololu.h.
Referenced by vpRobotPololuPtu::vpRobotPololuPtu().
void vpPololu::setPwmVelocity | ( | short | pwm_vel | ) |
Set the pwm velocity of the motor movements. The motor will move to the edge of the range at the given speed.
[in] | pwm_vel | : PWM velocity to use for movement in units of (0.25 us)/(10 ms). When set to 0, will use the maximum speed. |
Definition at line 255 of file vpPololu.cpp.
References getPwmPosition(), and vpRobotException::positionOutOfRangeError.
Referenced by setAngularVelocity().
|
inline |
Enable/disable verbose mode.
[in] | verbose | : Set to true to enable verbose mode, false otherwise. |
Definition at line 239 of file vpPololu.h.
Referenced by vpRobotPololuPtu::vpRobotPololuPtu().
float vpPololu::speedToRadS | ( | short | speed | ) | const |
Convert Pololu's pwm velocity to rad/s velocity.
[in] | speed | : Signed speed in units of (0.25 us)/(10 ms). |
Definition at line 283 of file vpPololu.cpp.
Referenced by vpRobotPololuPtu::getAngularVelocityResolution().
void vpPololu::stopVelocityCmd | ( | ) |
Stop the velocity command thread.
Definition at line 288 of file vpPololu.cpp.
References getPwmPosition(), and setPwmPosition().
Referenced by vpRobotPololuPtu::stopVelocity(), and vpRobotPololuPtu::~vpRobotPololuPtu().