SimpleMessage.c
Go to the documentation of this file.
00001 // SimpleMessage.c
00002 //
00003 // History:
00004 // 06/12/2013: Fix reply to ROS_MSG_JOINT_TRAJ_PT_FULL message
00005 // 06/12/2013: Release v.1.0.1
00006 // June 2014:   Release v1.2.0
00007 //                              Add support for multiple control groups.
00008 //                              Add support for DX200 controller.
00009 /*
00010 * Software License Agreement (BSD License) 
00011 *
00012 * Copyright (c) 2013, Yaskawa America, Inc.
00013 * All rights reserved.
00014 *
00015 * Redistribution and use in binary form, with or without modification,
00016 * is permitted provided that the following conditions are met:
00017 *
00018 *       * Redistributions in binary form must reproduce the above copyright
00019 *       notice, this list of conditions and the following disclaimer in the
00020 *       documentation and/or other materials provided with the distribution.
00021 *       * Neither the name of the Yaskawa America, Inc., nor the names 
00022 *       of its contributors may be used to endorse or promote products derived
00023 *       from this software without specific prior written permission.
00024 *
00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00029 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00030 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00031 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00032 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00033 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00034 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035 * POSSIBILITY OF SUCH DAMAGE.
00036 */ 
00037 
00038 #include "MotoROS.h"
00039 
00040 //-----------------------
00041 // Function Declarations
00042 //-----------------------
00043 
00044 //-----------------------
00045 // Function implementation
00046 //-----------------------
00047 
00048 // Creates a simple message of type: ROS_MSG_JOINT_FEEDBACK = 15
00049 // Simple message containing a the current joint position
00050 // of the specified control group
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         //initialize memory
00058         memset(sendMsg, 0x00, sizeof(SimpleMsg));
00059         
00060         // set prefix: length of message excluding the prefix
00061         sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedback);
00062         
00063         // set header information
00064         sendMsg->header.msgType = ROS_MSG_JOINT_FEEDBACK;
00065         sendMsg->header.commType = ROS_COMM_TOPIC;
00066         sendMsg->header.replyType = ROS_REPLY_INVALID;
00067         
00068         // set body
00069         sendMsg->body.jointFeedback.groupNo = ctrlGroup->groupNo;
00070         sendMsg->body.jointFeedback.validFields = Valid_Position;
00071         
00072         //feedback position
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         //servo speed
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 // Initialize header for a simple message of type: ROS_MSG_MOTO_JOINT_FEEDBACK_EX = 17
00090 void Ros_SimpleMsg_JointFeedbackEx_Init(int numberOfGroups, SimpleMsg* sendMsg)
00091 {       
00092         //initialize memory
00093         memset(sendMsg, 0x00, sizeof(SimpleMsg));
00094         
00095         // set prefix: length of message excluding the prefix
00096         sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedbackEx);
00097         
00098         // set header information
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         // set body
00104         sendMsg->body.jointFeedbackEx.numberOfValidGroups = numberOfGroups;
00105 }
00106 
00107 // Copy data from a standard feedback message to the extended feedback message.  This
00108 // function should be called multiple times to build a message for all control groups.
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 // Creates a simple message of type MOTO_MOTION_REPLY to reply to a received message 
00120 // result code and subcode indication result of the processing of the received message
00121 // 06/12/2013: Modified to fix reply to ROS_MSG_JOINT_TRAJ_PT_FULL message
00122 int Ros_SimpleMsg_MotionReply(SimpleMsg* receiveMsg, int result, int subcode, SimpleMsg* replyMsg, int ctrlGrp)
00123 {
00124         //initialize memory
00125         memset(replyMsg, 0x00, sizeof(SimpleMsg));
00126         
00127         // set prefix: length of message excluding the prefix
00128         replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
00129 
00130         // set header information of the reply
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         // set reply body
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 // Creates a simple message of type ROS_MSG_MOTO_IOCTRL_REPLY to reply to a received message 
00168 // result error code and subcode.  (Not used for successful commands.)
00169 int Ros_SimpleMsg_IoReply(int result, int subcode, SimpleMsg* replyMsg)
00170 {
00171         //initialize memory
00172         memset(replyMsg, 0x00, sizeof(SimpleMsg));
00173 
00174         // set prefix: length of message excluding the prefix
00175         replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
00176 
00177         // set header information of the reply
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         // set reply body
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 // function to dump data structure for debugging
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


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute)
autogenerated on Sat Jun 8 2019 19:06:58