Public Member Functions | Private Member Functions | Private Attributes | List of all members
hitec_5980SG Class Reference

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]. More...
 
short int GetVersionAndID (void)
 Gets servos version and id's. More...
 
 hitec_5980SG (const char *pdevice)
 Constructor. More...
 
bool IsActive (void)
 Checks por activation. More...
 
short unsigned int ReleaseServos (void)
 Releases all the servos in the bus. More...
 
short unsigned int SetGoStop (short unsigned int value)
 Sends command go/stop to all servos in the bus. More...
 
short unsigned int SetPosition (int id, int position)
 Sets the target position of a servo. More...
 
short unsigned int SetPositionAllServos (short unsigned int position)
 Sets the target position of all servos in the bus. More...
 
short unsigned int SetServoID (int id)
 Sets servo ID. More...
 
short unsigned int SetSpeedPosition (int id, int speed)
 Set velocity and read position of the servo. More...
 
 ~hitec_5980SG ()
 De-constructor. More...
 

Private Member Functions

void CleanBuffer (void)
 Cleans the buffer. More...
 
short unsigned int ReadResponse (char *response_1=NULL, char *response_2=NULL)
 Reads the response to a command. More...
 

Private Attributes

bool active
 This variable indicates that the communication is active. More...
 
short unsigned int center
 Center position of the servo. More...
 
char * device
 Communication device to use. More...
 
double HSR_5498SG_MAX_ANGULAR_SPEED
 Maximum angular speed of the servo HSR-5498SG. More...
 
double HSR_5980SG_MAX_ANGULAR_SPEED
 Maximum angular speed of the servo HSR-5980SG. More...
 
short unsigned int maximum
 Maximum position of the servo. More...
 
short unsigned int minimum
 Minimum position of the servo. More...
 
int port
 Communication port to use. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Parameters
pdevicePath/name of the device to use in communications
Returns
void

Definition at line 34 of file hitec5980sg.cpp.

hitec_5980SG::~hitec_5980SG ( )

De-constructor.

This function closes the communication with the servos.

Returns
void

Definition at line 106 of file hitec5980sg.cpp.

Member Function Documentation

void hitec_5980SG::CleanBuffer ( void  )
private

Cleans the buffer.

This function clean the communication input buffer.

Returns
void

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].

Parameters
[in]angular_speedangular speed as a double.
[in]Servo_typeone of teo possible types of hitec servomotors.
Returns
void

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.

Returns
returns the response from the servo or 0xFFFF in case of error
Todo:
You should not do this!, there is a function called ReadResponse to do this part!!

Definition at line 242 of file hitec5980sg.cpp.

bool hitec_5980SG::IsActive ( void  )

Checks por activation.

This function checks the COMM port for activity.

Returns
void

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.

Returns
returns the response from the servo or 0xFFFF in case of error

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.

Returns
returns the response from the servo or 0xFFFF in case of error
Todo:
You should not do this!, there is a function called ReadResponse to do this part!! | Pedro_Cruz_Response: Indeed! But it doesn't work in this case! Function must be altered to suit all possible responces, because some functions place different information in those two last bytes...

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.

Parameters
valuevalue for go/stop command [0,1].
Returns
returns the response from the servo or 0xFFFF in case of error
Todo:
You should not do this!, there is a function called ReadResponse to do this part!! | Pedro_Cruz_Response: Indeed! But it doesn't work in this case! Function must be altered to suit all possible responces, because some functions place different information in those two last bytes...

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.

Parameters
ididentification of the servo
positiondesired position of the servo
Returns
returns the response from the servo or 0xFFFF in case of error

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.

Parameters
positiondesired position of the servos [600...2400]
Returns
returns the response from the servo or 0xFFFF in case of error

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.

Parameters
idValue for new ID atempt.
Returns
returns the response from the servo or 0xFFFF in case of error
Todo:
You should not do this!, there is a function called ReadResponse to do this part!! | Pedro_Cruz_Response: Indeed! But it doesn't work in this case! Function must be altered to suit all possible responces, because some functions place different information in those two last bytes...

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.

Parameters
ididentification of the servo
speeddesired speed of the servo
Returns
returns the response from the servo or 0xFFFF in case of error (Current Position!)

Definition at line 170 of file hitec5980sg.cpp.

Member Data Documentation

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.


The documentation for this class was generated from the following files:


hitec5980sg
Author(s): Pedro Cruz, Jorge Almeida
autogenerated on Mon Mar 2 2015 01:31:40