robot_state.cpp
Go to the documentation of this file.
00001 #include "aubo_new_driver/robot_state.h"
00002 #include "aubo_new_driver/do_output.h"
00003 
00004 
00005 RobotState::RobotState(std::condition_variable& msg_cond) {
00006     joint_position_actual_.assign(6, 0.0);
00007     joint_velocity_actual_.assign(6, 0.0);
00008     tool_position_actual_.assign(3, 0.0);
00009     tool_orientation_actual_.assign(4, 0.0);
00010     joint_temperatures_actual_.assign(6, 0.0);
00011     joint_current_actual_.assign(6, 0.0);
00012     joint_voltage_actual_.assign(6, 0.0);
00013     tcp_force_actual_.assign(6, 0.0);
00014     end_speed_actual_= 0.0;
00015         data_published_ = false;
00016         controller_updated_ = false;
00017         pMsg_cond_ = &msg_cond;
00018 }
00019 
00020 RobotState::~RobotState() {
00021         /* Make sure nobody is waiting after this thread is destroyed */
00022         data_published_ = true;
00023         controller_updated_ = true;
00024         pMsg_cond_->notify_all();
00025 }
00026 
00027 void RobotState::setDataPublished() {
00028         data_published_ = false;
00029 }
00030 bool RobotState::getDataPublished() {
00031         return data_published_;
00032 }
00033 
00034 void RobotState::setControllerUpdated() {
00035         controller_updated_ = false;
00036 }
00037 bool RobotState::getControllerUpdated() {
00038         return controller_updated_;
00039 }
00040 
00041 std::vector<double> RobotState::getJonitPosition() {
00042         std::vector<double> ret;
00043         val_lock_.lock();
00044     ret = joint_position_actual_;
00045         val_lock_.unlock();
00046         return ret;
00047 }
00048 
00049 
00050 std::vector<double> RobotState::getJonitVelocity() {
00051     std::vector<double> ret;
00052     val_lock_.lock();
00053     ret = joint_velocity_actual_;
00054     val_lock_.unlock();
00055     return ret;
00056 }
00057 
00058 std::vector<double> RobotState::getToolPosition() {
00059         std::vector<double> ret;
00060         val_lock_.lock();
00061     ret = tool_position_actual_;
00062         val_lock_.unlock();
00063         return ret;
00064 }
00065 
00066 std::vector<double> RobotState::getToolOrientation() {
00067         std::vector<double> ret;
00068         val_lock_.lock();
00069     ret = tool_orientation_actual_;
00070         val_lock_.unlock();
00071         return ret;
00072 }
00073 std::vector<double> RobotState::getJointTemperatures() {
00074         std::vector<double> ret;
00075         val_lock_.lock();
00076     ret = joint_temperatures_actual_;
00077         val_lock_.unlock();
00078         return ret;
00079 }
00080 std::vector<double> RobotState::getJointCurrent() {
00081         std::vector<double> ret;
00082         val_lock_.lock();
00083     ret = joint_current_actual_;
00084         val_lock_.unlock();
00085         return ret;
00086 }
00087 std::vector<double> RobotState::getJointVoltage() {
00088         std::vector<double> ret;
00089         val_lock_.lock();
00090     ret = joint_voltage_actual_;
00091         val_lock_.unlock();
00092         return ret;
00093 }
00094 
00095 
00096 std::vector<double> RobotState::getTcpForce() {
00097     std::vector<double> ret;
00098     val_lock_.lock();
00099     ret = tcp_force_actual_;
00100     val_lock_.unlock();
00101     return ret;
00102 }
00103 
00104 double RobotState::getEndSpeed() {
00105         double ret;
00106         val_lock_.lock();
00107     ret = end_speed_actual_;
00108         val_lock_.unlock();
00109         return ret;
00110 }
00111 
00112 void RobotState::unpack(uint8_t * buf) {
00113 
00114         val_lock_.lock();
00115 
00116     char *rec = (char*)buf;
00117 
00118     std::string response =(std::string)rec;
00119 
00120     //print_info(response);
00121 
00122     int pos = response.find("getRobotPos",0);
00123 
00124     if((pos != -1)&&(pos < 4096))
00125     {
00126         joint_position_actual_.clear();
00127         pos = response.find("\"joint1\":",0);
00128         double data = atof(&rec[pos+9]);
00129         joint_position_actual_.push_back(data);
00130 
00131         pos = response.find("\"joint2\":",0);
00132         data = atof(&rec[pos+9]);
00133         joint_position_actual_.push_back(data);
00134 
00135         pos = response.find("\"joint3\":",0);
00136         data = atof(&rec[pos+9]);
00137         joint_position_actual_.push_back(data);
00138 
00139         pos = response.find("\"joint4\":",0);
00140         data = atof(&rec[pos+9]);
00141         joint_position_actual_.push_back(data);
00142 
00143         pos = response.find("\"joint5\":",0);
00144         data = atof(&rec[pos+9]);
00145         joint_position_actual_.push_back(data);
00146 
00147         pos = response.find("\"joint6\":",0);
00148         data = atof(&rec[pos+9]);
00149         joint_position_actual_.push_back(data);
00150 
00151 
00152         tool_position_actual_.clear();
00153         pos = response.find("\"X\":",0);
00154         data = atof(&rec[pos+4]);
00155         tool_position_actual_.push_back(data);
00156 
00157         pos = response.find("\"Y\":",0);
00158         data = atof(&rec[pos+4]);
00159         tool_position_actual_.push_back(data);
00160 
00161         pos = response.find("\"Z\":",0);
00162         data = atof(&rec[pos+4]);
00163         tool_position_actual_.push_back(data);
00164 
00165 
00166         tool_orientation_actual_.clear();
00167         pos = response.find("\"pose_w\":",0);
00168         data = atof(&rec[pos+9]);
00169         tool_orientation_actual_.push_back(data);
00170 
00171         pos = response.find("\"pose_x\":",0);
00172         data = atof(&rec[pos+9]);
00173         tool_orientation_actual_.push_back(data);
00174 
00175         pos = response.find("\"pose_y\":",0);
00176         data = atof(&rec[pos+9]);
00177         tool_orientation_actual_.push_back(data);
00178 
00179         pos = response.find("\"pose_z\":",0);
00180         data = atof(&rec[pos+9]);
00181         tool_orientation_actual_.push_back(data);
00182     }
00183 
00184 
00185         val_lock_.unlock();
00186         controller_updated_ = true;
00187         data_published_ = true;
00188         pMsg_cond_->notify_all();
00189 }
00190 


aubo_new_driver
Author(s): liuxin
autogenerated on Wed Sep 6 2017 03:06:44