Class to implement the HMI Hitec protocol. More...
#include <hitec5980sg.h>
Public Member Functions | |
short unsigned int | ConvertAngularSpeedToServoSpeed (double angular_speed, unsigned int Servo_type) |
Converts angular speed to servo speed range [1...255]. | |
short int | GetVersionAndID (void) |
Gets servos version and id's. | |
hitec_5980SG (const char *pdevice) | |
Constructor. | |
bool | IsActive (void) |
Checks por activation. | |
short unsigned int | ReleaseServos (void) |
Releases all the servos in the bus. | |
short unsigned int | SetGoStop (short unsigned int value) |
Sends command go/stop to all servos in the bus. | |
short unsigned int | SetPosition (int id, int position) |
Sets the target position of a servo. | |
short unsigned int | SetPositionAllServos (short unsigned int position) |
Sets the target position of all servos in the bus. | |
short unsigned int | SetServoID (int id) |
Sets servo ID. | |
short unsigned int | SetSpeedPosition (int id, int speed) |
Set velocity and read position of the servo. | |
~hitec_5980SG () | |
De-constructor. | |
Private Member Functions | |
void | CleanBuffer (void) |
Cleans the buffer. | |
short unsigned int | ReadResponse (char *response_1=NULL, char *response_2=NULL) |
Reads the response to a command. | |
Private Attributes | |
bool | active |
This variable indicates that the communication is active. | |
short unsigned int | center |
Center position of the servo. | |
char * | device |
Communication device to use. | |
double | HSR_5498SG_MAX_ANGULAR_SPEED |
Maximum angular speed of the servo HSR-5498SG. | |
double | HSR_5980SG_MAX_ANGULAR_SPEED |
Maximum angular speed of the servo HSR-5980SG. | |
short unsigned int | maximum |
Maximum position of the servo. | |
short unsigned int | minimum |
Minimum position of the servo. | |
int | port |
Communication port to use. |
Class to implement the HMI Hitec protocol.
This class is used to communicate and control the hitec5980sg servos that comply with the Hitec HMI servo control protocol.
This protocol is only used in robotic servos and works over a serial line. This line only has one conductor (only one cable for TX and RX), this limitation severely limits the amount of communication with the servos but allows for a large number of servos in only one communication line.
Definition at line 62 of file hitec5980sg.h.
hitec_5980SG::hitec_5980SG | ( | const char * | pdevice | ) |
Constructor.
This functions sets the default values for internal variables and opens communication with the servos. The function sends a dummy instruction to initialize servo communications.
pdevice | Path/name of the device to use in communications |
Definition at line 34 of file hitec5980sg.cpp.
hitec_5980SG::~hitec_5980SG | ( | ) |
De-constructor.
This function closes the communication with the servos.
Definition at line 106 of file hitec5980sg.cpp.
void hitec_5980SG::CleanBuffer | ( | void | ) | [private] |
Cleans the buffer.
This function clean the communication input buffer.
Definition at line 476 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::ConvertAngularSpeedToServoSpeed | ( | double | angular_speed, | |
unsigned int | Servo_type | |||
) |
Converts angular speed to servo speed range [1...255].
This function converts a given angular speed in deg/s to the servo digital speed range [1...255].
[in] | angular_speed | angular speed as a double. |
[in] | Servo_type | one of teo possible types of hitec servomotors. |
Definition at line 492 of file hitec5980sg.cpp.
short int hitec_5980SG::GetVersionAndID | ( | void | ) |
Gets servos version and id's.
This function commands all servos to give away firmware versions and ID's.
Definition at line 242 of file hitec5980sg.cpp.
bool hitec_5980SG::IsActive | ( | void | ) |
Checks por activation.
This function checks the COMM port for activity.
Definition at line 436 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::ReadResponse | ( | char * | response_1 = NULL , |
|
char * | response_2 = NULL | |||
) | [private] |
Reads the response to a command.
This function reads the response from the servo. It must be used after every command is sent to the servo.
Definition at line 441 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::ReleaseServos | ( | void | ) |
Releases all the servos in the bus.
This function commands all servos in the bus to release. Any posterior command makes all the servos return to previous position.
Definition at line 284 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::SetGoStop | ( | short unsigned int | value | ) |
Sends command go/stop to all servos in the bus.
This function commands all servos in the bus to go/stop. Servos will not change position until order is given.
value | value for go/stop command [0,1]. |
Definition at line 379 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::SetPosition | ( | int | id, | |
int | position | |||
) |
Sets the target position of a servo.
This function commands a servo to move to a desired position. This function tests if the position is within the defined servo limits.
id | identification of the servo | |
position | desired position of the servo |
Definition at line 130 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::SetPositionAllServos | ( | short unsigned int | position | ) |
Sets the target position of all servos in the bus.
This function commands all servos in the bus to move to a desired position. This function tests if the position is within the defined servo limits.
position | desired position of the servos [600...2400] |
Definition at line 204 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::SetServoID | ( | int | id | ) |
Sets servo ID.
This function sets ID to a servo, writing in the EEPROM's ID address.
id | Value for new ID atempt. |
Definition at line 334 of file hitec5980sg.cpp.
short unsigned int hitec_5980SG::SetSpeedPosition | ( | int | id, | |
int | speed | |||
) |
Set velocity and read position of the servo.
This function sets the movement speed of a servo.
id | identification of the servo | |
speed | desired speed of the servo |
Definition at line 170 of file hitec5980sg.cpp.
bool hitec_5980SG::active [private] |
This variable indicates that the communication is active.
Definition at line 189 of file hitec5980sg.h.
short unsigned int hitec_5980SG::center [private] |
Center position of the servo.
Definition at line 198 of file hitec5980sg.h.
char* hitec_5980SG::device [private] |
Communication device to use.
Definition at line 195 of file hitec5980sg.h.
double hitec_5980SG::HSR_5498SG_MAX_ANGULAR_SPEED [private] |
Maximum angular speed of the servo HSR-5498SG.
Definition at line 210 of file hitec5980sg.h.
double hitec_5980SG::HSR_5980SG_MAX_ANGULAR_SPEED [private] |
Maximum angular speed of the servo HSR-5980SG.
Definition at line 207 of file hitec5980sg.h.
short unsigned int hitec_5980SG::maximum [private] |
Maximum position of the servo.
Definition at line 204 of file hitec5980sg.h.
short unsigned int hitec_5980SG::minimum [private] |
Minimum position of the servo.
Definition at line 201 of file hitec5980sg.h.
int hitec_5980SG::port [private] |
Communication port to use.
Definition at line 192 of file hitec5980sg.h.