diff --git a/include/dynamixel_pan_tilt.h b/include/dynamixel_pan_tilt.h index 0518ba987c7f6043201e9418f32b01931a88e3e5..3ae73db22a6c67c3aa8b6b769298c0e5bb942754 100644 --- a/include/dynamixel_pan_tilt.h +++ b/include/dynamixel_pan_tilt.h @@ -504,12 +504,24 @@ class CDynamixel_Pan_Tilt #endif + /** + * \brief Function to get the number of motors. + * + */ + unsigned int get_num_motors(void); /** * \brief Function to get the position of both servos in degrees. * * \return A struct with the angles of both servos in degrees. */ Dynamixel_pan_tilt_data get_position(void); + + /** + * \brief Function to get the position of both servos in degrees. + * + * \param position A std::vector with the angles of both servos in degrees. + */ + void get_position2(std::vector<double> &position); /** * \brief Function to get the position of the pan servo in degrees. @@ -533,6 +545,15 @@ class CDynamixel_Pan_Tilt * \param speed The specific speed in degrees/second for both servos in a struct. */ void move_absolute_angle(Dynamixel_pan_tilt_data &angle, Dynamixel_pan_tilt_data &speed); + + /** + * \brief Function to move the pan-tilt to a specific position by a specific speed. + * If some of the values passed are out of range, they'll be changed to the value of the limit. + * + * \param angle The specific position in degrees for both servos in a std::vector. + * \param speed The specific speed in degrees/second for both servos in a std::vector. + */ + void move_absolute_angle2(std::vector<double> &angle, std::vector<double> &speed); /** * \brief Function to move the pan-tilt a specific angle relative to the current position by a specific speed. @@ -543,6 +564,16 @@ class CDynamixel_Pan_Tilt * \param speed The specific speed in degrees/second for both servos in a struct. */ void move_relative_angle(Dynamixel_pan_tilt_data &angle, Dynamixel_pan_tilt_data &speed); + + /** + * \brief Function to move the pan-tilt a specific angle relative to the current position by a specific speed. + * If some of the values passed are out of range, they'll be changed to the value of the limit. + * + * \param angle The specific angle in degrees to move from the current position for both servos in a std::vector. + * It's value is changed to the goal position. + * \param speed The specific speed in degrees/second for both servos in a std::vector. + */ + void move_relative_angle2(std::vector<double> &angle, std::vector<double> &speed); /** * \brief Function to move the pan-tilt on endless mode for both servos. diff --git a/src/dynamixel_pan_tilt.cpp b/src/dynamixel_pan_tilt.cpp index 4143cbe1d6b132b17a8031f1f373f9c9fe8a14c9..33b527f4ce27941a32c033ab4ac1a291ecf4fa1c 100644 --- a/src/dynamixel_pan_tilt.cpp +++ b/src/dynamixel_pan_tilt.cpp @@ -490,6 +490,17 @@ void CDynamixel_Pan_Tilt::move_absolute_angle(Dynamixel_pan_tilt_data &angle, Dy move_absolute_angle_tilt(angle.tilt, speed.tilt); } +void CDynamixel_Pan_Tilt::move_absolute_angle2(std::vector<double> &angle, std::vector<double> &speed) +{ + if (angle.size() == 2 && speed.size() == 2) + { + move_absolute_angle_pan(angle[0], speed[0]); + move_absolute_angle_tilt(angle[1], speed[1]); + } + else + throw CDynamixel_Pan_TiltException(_HERE_,"There are necessaries two angles and speeds to move the servos"); +} + void CDynamixel_Pan_Tilt::move_absolute_angle_pan(double &angle, double &speed) { if (this->pan!=NULL) @@ -605,6 +616,17 @@ void CDynamixel_Pan_Tilt::move_relative_angle(Dynamixel_pan_tilt_data &angle, Dy move_relative_angle_tilt(angle.tilt, speed.tilt); } +void CDynamixel_Pan_Tilt::move_relative_angle2(std::vector<double> &angle, std::vector<double> &speed) +{ + if (angle.size() == 2 && speed.size() == 2) + { + move_relative_angle_pan(angle[0], speed[0]); + move_relative_angle_tilt(angle[1], speed[1]); + } + else + throw CDynamixel_Pan_TiltException(_HERE_,"There are necessaries two angles and speeds to move the servos"); +} + void CDynamixel_Pan_Tilt::move_relative_angle_pan(double &angle, double &speed) { if (this->pan!=NULL) @@ -1365,6 +1387,11 @@ void CDynamixel_Pan_Tilt::default_parameters(void) ///------------------------------------------------------Get & Set +unsigned int CDynamixel_Pan_Tilt::get_num_motors(void) +{ + return 2; +} + Dynamixel_pan_tilt_data CDynamixel_Pan_Tilt::get_position(void) { Dynamixel_pan_tilt_data data; @@ -1375,6 +1402,15 @@ Dynamixel_pan_tilt_data CDynamixel_Pan_Tilt::get_position(void) return data; } +void CDynamixel_Pan_Tilt::get_position2(std::vector<double> &position) +{ + position.clear(); + double angle = get_pan_position(); + position.push_back(angle); + angle = get_tilt_position(); + position.push_back(angle); +} + double CDynamixel_Pan_Tilt::get_pan_position(void) { if (this->pan!=NULL)