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
00032
00033
00034
00035
00036
00037
00038 #include "MotoROS.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 int Ros_SimpleMsg_JointFeedback(CtrlGroup* ctrlGroup, SimpleMsg* sendMsg)
00052 {
00053 int bRet;
00054 long pulsePos[MAX_PULSE_AXES];
00055 long pulseSpeed[MAX_PULSE_AXES];
00056
00057
00058 memset(sendMsg, 0x00, sizeof(SimpleMsg));
00059
00060
00061 sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedback);
00062
00063
00064 sendMsg->header.msgType = ROS_MSG_JOINT_FEEDBACK;
00065 sendMsg->header.commType = ROS_COMM_TOPIC;
00066 sendMsg->header.replyType = ROS_REPLY_INVALID;
00067
00068
00069 sendMsg->body.jointFeedback.groupNo = ctrlGroup->groupNo;
00070 sendMsg->body.jointFeedback.validFields = Valid_Position;
00071
00072
00073 bRet = Ros_CtrlGroup_GetFBPulsePos(ctrlGroup, pulsePos);
00074 if(bRet!=TRUE)
00075 return 0;
00076 Ros_CtrlGroup_ConvertToRosPos(ctrlGroup, pulsePos, sendMsg->body.jointFeedback.pos);
00077
00078
00079 bRet = Ros_CtrlGroup_GetFBServoSpeed(ctrlGroup, pulseSpeed);
00080 if (bRet == TRUE)
00081 {
00082 Ros_CtrlGroup_ConvertToRosPos(ctrlGroup, pulseSpeed, sendMsg->body.jointFeedback.vel);
00083 sendMsg->body.jointFeedback.validFields |= Valid_Velocity;
00084 }
00085
00086 return(sendMsg->prefix.length + sizeof(SmPrefix));
00087 }
00088
00089
00090 void Ros_SimpleMsg_JointFeedbackEx_Init(int numberOfGroups, SimpleMsg* sendMsg)
00091 {
00092
00093 memset(sendMsg, 0x00, sizeof(SimpleMsg));
00094
00095
00096 sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedbackEx);
00097
00098
00099 sendMsg->header.msgType = ROS_MSG_MOTO_JOINT_FEEDBACK_EX;
00100 sendMsg->header.commType = ROS_COMM_TOPIC;
00101 sendMsg->header.replyType = ROS_REPLY_INVALID;
00102
00103
00104 sendMsg->body.jointFeedbackEx.numberOfValidGroups = numberOfGroups;
00105 }
00106
00107
00108
00109 int Ros_SimpleMsg_JointFeedbackEx_Build(int groupIndex, SimpleMsg* src_msgFeedback, SimpleMsg* dst_msgExtendedFeedback)
00110 {
00111 memcpy(&dst_msgExtendedFeedback->body.jointFeedbackEx.jointTrajPtData[groupIndex],
00112 &src_msgFeedback->body.jointFeedback,
00113 sizeof(SmBodyJointFeedback));
00114
00115 return(dst_msgExtendedFeedback->prefix.length + sizeof(SmPrefix));
00116 }
00117
00118
00119
00120
00121
00122 int Ros_SimpleMsg_MotionReply(SimpleMsg* receiveMsg, int result, int subcode, SimpleMsg* replyMsg, int ctrlGrp)
00123 {
00124
00125 memset(replyMsg, 0x00, sizeof(SimpleMsg));
00126
00127
00128 replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
00129
00130
00131 replyMsg->header.msgType = ROS_MSG_MOTO_MOTION_REPLY;
00132 replyMsg->header.commType = ROS_COMM_SERVICE_REPLY;
00133 replyMsg->header.replyType = ROS_REPLY_SUCCESS;
00134
00135
00136 if(receiveMsg->header.msgType == ROS_MSG_MOTO_MOTION_CTRL)
00137 {
00138 replyMsg->body.motionReply.groupNo = ctrlGrp;
00139 replyMsg->body.motionReply.sequence = receiveMsg->body.motionCtrl.sequence;
00140 replyMsg->body.motionReply.command = receiveMsg->body.motionCtrl.command;
00141 }
00142 else if(receiveMsg->header.msgType == ROS_MSG_JOINT_TRAJ_PT_FULL)
00143 {
00144 replyMsg->body.motionReply.groupNo = ctrlGrp;
00145 replyMsg->body.motionReply.sequence = receiveMsg->body.jointTrajData.sequence;
00146 replyMsg->body.motionReply.command = ROS_MSG_JOINT_TRAJ_PT_FULL;
00147 }
00148 else if (receiveMsg->header.msgType == ROS_MSG_MOTO_JOINT_TRAJ_PT_FULL_EX)
00149 {
00150 replyMsg->body.motionReply.groupNo = ctrlGrp;
00151 replyMsg->body.motionReply.sequence = receiveMsg->body.jointTrajDataEx.sequence;
00152 replyMsg->body.motionReply.command = ROS_MSG_MOTO_JOINT_TRAJ_PT_FULL_EX;
00153 }
00154 else
00155 {
00156 replyMsg->body.motionReply.groupNo = -1;
00157 replyMsg->body.motionReply.sequence = -1;
00158 replyMsg->body.motionReply.command = receiveMsg->header.msgType;
00159 }
00160
00161 replyMsg->body.motionReply.result = result;
00162 replyMsg->body.motionReply.subcode = subcode;
00163
00164 return(replyMsg->prefix.length + sizeof(SmPrefix));
00165 }
00166
00167
00168
00169 int Ros_SimpleMsg_IoReply(int result, int subcode, SimpleMsg* replyMsg)
00170 {
00171
00172 memset(replyMsg, 0x00, sizeof(SimpleMsg));
00173
00174
00175 replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
00176
00177
00178 replyMsg->header.msgType = ROS_MSG_MOTO_MOTION_REPLY;
00179 replyMsg->header.commType = ROS_COMM_SERVICE_REPLY;
00180 replyMsg->header.replyType = ROS_REPLY_SUCCESS;
00181
00182
00183 replyMsg->body.ioCtrlReply.result = result;
00184 replyMsg->body.ioCtrlReply.subcode = subcode;
00185
00186 return(replyMsg->prefix.length + sizeof(SmPrefix));
00187 }
00188
00189 #ifdef DEBUG
00190
00191 void Ros_SimpleMsg_DumpTrajPtFull(SmBodyJointTrajPtFull* data)
00192 {
00193 printf("Dumping SmBodyJointTrajPtFull:\r\n");
00194 printf(" groupNo=%d\r\n", data->groupNo);
00195 printf(" sequence=%d\r\n", data->sequence);
00196 printf(" validFields=%d\r\n", data->validFields);
00197 printf(" time=%.5f\r\n", data->time);
00198 printf(" pos: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
00199 data->pos[0], data->pos[1], data->pos[2], data->pos[3],
00200 data->pos[4], data->pos[5], data->pos[6]);
00201 printf(" vel: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
00202 data->vel[0], data->vel[1], data->vel[2], data->vel[3],
00203 data->vel[4], data->vel[5], data->vel[6]);
00204 printf(" acc: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
00205 data->acc[0], data->acc[1], data->acc[2], data->acc[3],
00206 data->acc[4], data->acc[5], data->acc[6]);
00207 }
00208 #endif