00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifdef ROS
00032 #include "dx100/ros_conversion.h"
00033 #include "dx100/trajectory_job.h"
00034 #include "string.h"
00035 #include "simple_message/joint_traj_pt.h"
00036 #include "simple_message/shared_types.h"
00037 #include "simple_message/log_wrapper.h"
00038 #endif
00039
00040 #ifdef MOTOPLUS
00041 #include "ros_conversion.h"
00042 #include "trajectory_job.h"
00043 #include "string.h"
00044 #include "joint_traj_pt.h"
00045 #include "shared_types.h"
00046 #include "log_wrapper.h"
00047 #endif
00048
00049 using namespace industrial::shared_types;
00050 using namespace industrial::joint_traj;
00051 using namespace industrial::joint_traj_pt;
00052 using namespace industrial::joint_data;
00053 using namespace motoman::ros_conversion;
00054
00055 namespace motoman
00056 {
00057 namespace trajectory_job
00058 {
00059
00068
00069
00070 #define SAFE_STRCAT(dest, dest_max_size, src) \
00071 do \
00072 { \
00073 if (strlen(src) < dest_max_size - strlen(dest) - 1) \
00074 { \
00075 strcat(dest, src); \
00076 } \
00077 else \
00078 { \
00079 LOG_ERROR("STRCAT failed to append %s to %s", src, dest); \
00080 return false; \
00081 } \
00082 } while (0)
00083
00089 #define APPEND_LINEFEED(dest, dest_max_size) SAFE_STRCAT(dest, dest_max_size, "\r\n");
00090
00096 #define APPEND_LINE(dest, dest_max_size, src) \
00097 do \
00098 { \
00099 SAFE_STRCAT(dest, dest_max_size, src); \
00100 APPEND_LINEFEED(dest, dest_max_size); \
00101 } while (0)
00102
00103 TrajectoryJob::TrajectoryJob(void)
00104 {
00105 }
00106 TrajectoryJob::~TrajectoryJob(void)
00107 {
00108 }
00109
00110 bool TrajectoryJob::init(const char* name)
00111 {
00112
00113 bool rtn = false;
00114
00115 if( strlen(name) <= NAME_BUFFER_SIZE_ )
00116 {
00117 strcpy(this->name_, name);
00118 rtn = true;
00119 }
00120 else
00121 {
00122 LOG_ERROR("Failed to initialize trajectory job, name size %d too large",
00123 NAME_BUFFER_SIZE_);
00124 rtn = false;
00125 }
00126 return rtn;
00127
00128 }
00129
00130 bool TrajectoryJob::toJobString(JointTraj & trajectory, char* str_buffer, size_t buffer_size)
00131 {
00132 bool rtn = false;
00133 if (0 < buffer_size)
00134 {
00135
00136
00137
00138 strcpy(str_buffer, "");
00139 APPEND_LINE(str_buffer, buffer_size, "/JOB");
00140
00141 sprintf(this->line_buffer_, "//NAME %s", this->name_);
00142 APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
00143
00144 APPEND_LINE(str_buffer, buffer_size, "//POS");
00145
00146 sprintf(this->line_buffer_, "///NPOS %d,0,0,0,0,0", trajectory.size());
00147 APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
00148
00149 APPEND_LINE(str_buffer, buffer_size, "///TOOL 0");
00150 APPEND_LINE(str_buffer, buffer_size, "///POSTYPE PULSE");
00151 APPEND_LINE(str_buffer, buffer_size, "///PULSE");
00152
00153
00154
00155 JointTrajPt pt;
00156 JointData rosData;
00157 JointData mpData;
00158
00159 for(int i = 0; i < trajectory.size(); i++)
00160 {
00161 sprintf(this->line_buffer_, "C%05d=", i);
00162 SAFE_STRCAT(str_buffer, buffer_size, this->line_buffer_);
00163 trajectory.getPoint(i, pt);
00164 pt.getJointPosition(rosData);
00165
00166
00167 toMpJoint(rosData, mpData);
00168 for(int j = 0; j < mpData.getMaxNumJoints(); j++)
00169 {
00170
00171 if (j < (mpData.getMaxNumJoints() - 1))
00172 {
00173 sprintf(this->line_buffer_, "%d,", (int)mpData.getJoint(j));
00174 SAFE_STRCAT(str_buffer, buffer_size, this->line_buffer_);
00175 }
00176 else
00177 {
00178 sprintf(this->line_buffer_, "%d", (int)mpData.getJoint(j));
00179 APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
00180 }
00181 }
00182 }
00183
00184
00185
00186 APPEND_LINE(str_buffer, buffer_size, "//INST");
00187 APPEND_LINE(str_buffer, buffer_size, "///DATE 1979/10/01 00:00");
00188 APPEND_LINE(str_buffer, buffer_size, "///ATTR SC,RW");
00189 APPEND_LINE(str_buffer, buffer_size, "///GROUP1 RB1");
00190
00191
00192 APPEND_LINE(str_buffer, buffer_size, "NOP");
00193 for(int i = 0; i < trajectory.size(); i++)
00194 {
00195 trajectory.getPoint(i, pt);
00196 sprintf(this->line_buffer_, "MOVJ C%05d VJ=%.2f", i, pt.getVelocity());
00197 APPEND_LINE(str_buffer, buffer_size, this->line_buffer_);
00198 }
00199 APPEND_LINE(str_buffer, buffer_size, "END");
00200
00201 rtn = true;
00202 }
00203 else
00204 {
00205 rtn = false;
00206 LOG_ERROR("Failed to generate job string");
00207 }
00208 return rtn;
00209
00210 }
00211
00212
00213 }
00214 }
00215