SimpleMessage.c
Go to the documentation of this file.
1 // SimpleMessage.c
2 //
3 // History:
4 // 06/12/2013: Fix reply to ROS_MSG_JOINT_TRAJ_PT_FULL message
5 // 06/12/2013: Release v.1.0.1
6 // June 2014: Release v1.2.0
7 // Add support for multiple control groups.
8 // Add support for DX200 controller.
9 /*
10 * Software License Agreement (BSD License)
11 *
12 * Copyright (c) 2013, Yaskawa America, Inc.
13 * All rights reserved.
14 *
15 * Redistribution and use in binary form, with or without modification,
16 * is permitted provided that the following conditions are met:
17 *
18 * * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * * Neither the name of the Yaskawa America, Inc., nor the names
22 * of its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37 
38 #include "MotoROS.h"
39 
40 //-----------------------
41 // Function Declarations
42 //-----------------------
43 
44 //-----------------------
45 // Function implementation
46 //-----------------------
47 
48 // Creates a simple message of type: ROS_MSG_JOINT_FEEDBACK = 15
49 // Simple message containing a the current joint position
50 // of the specified control group
52 {
53  int bRet;
54  long pulsePos[MAX_PULSE_AXES];
55  long pulseSpeed[MAX_PULSE_AXES];
56 
57  //initialize memory
58  memset(sendMsg, 0x00, sizeof(SimpleMsg));
59 
60  // set prefix: length of message excluding the prefix
61  sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedback);
62 
63  // set header information
65  sendMsg->header.commType = ROS_COMM_TOPIC;
67 
68  // set body
69  sendMsg->body.jointFeedback.groupNo = ctrlGroup->groupNo;
71 
72  //feedback position
73  bRet = Ros_CtrlGroup_GetFBPulsePos(ctrlGroup, pulsePos);
74  if(bRet!=TRUE)
75  return 0;
76  Ros_CtrlGroup_ConvertToRosPos(ctrlGroup, pulsePos, sendMsg->body.jointFeedback.pos);
77 
78  //servo speed
79  bRet = Ros_CtrlGroup_GetFBServoSpeed(ctrlGroup, pulseSpeed);
80  if (bRet == TRUE)
81  {
82  Ros_CtrlGroup_ConvertToRosPos(ctrlGroup, pulseSpeed, sendMsg->body.jointFeedback.vel);
84  }
85 
86  return(sendMsg->prefix.length + sizeof(SmPrefix));
87 }
88 
89 // Initialize header for a simple message of type: ROS_MSG_MOTO_JOINT_FEEDBACK_EX = 17
90 void Ros_SimpleMsg_JointFeedbackEx_Init(int numberOfGroups, SimpleMsg* sendMsg)
91 {
92  //initialize memory
93  memset(sendMsg, 0x00, sizeof(SimpleMsg));
94 
95  // set prefix: length of message excluding the prefix
96  sendMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyJointFeedbackEx);
97 
98  // set header information
100  sendMsg->header.commType = ROS_COMM_TOPIC;
102 
103  // set body
104  sendMsg->body.jointFeedbackEx.numberOfValidGroups = numberOfGroups;
105 }
106 
107 // Copy data from a standard feedback message to the extended feedback message. This
108 // function should be called multiple times to build a message for all control groups.
109 int Ros_SimpleMsg_JointFeedbackEx_Build(int groupIndex, SimpleMsg* src_msgFeedback, SimpleMsg* dst_msgExtendedFeedback)
110 {
111  memcpy(&dst_msgExtendedFeedback->body.jointFeedbackEx.jointTrajPtData[groupIndex],
112  &src_msgFeedback->body.jointFeedback,
113  sizeof(SmBodyJointFeedback));
114 
115  return(dst_msgExtendedFeedback->prefix.length + sizeof(SmPrefix));
116 }
117 
118 
119 // Creates a simple message of type MOTO_MOTION_REPLY to reply to a received message
120 // result code and subcode indication result of the processing of the received message
121 // 06/12/2013: Modified to fix reply to ROS_MSG_JOINT_TRAJ_PT_FULL message
122 int Ros_SimpleMsg_MotionReply(SimpleMsg* receiveMsg, int result, int subcode, SimpleMsg* replyMsg, int ctrlGrp)
123 {
124  //initialize memory
125  memset(replyMsg, 0x00, sizeof(SimpleMsg));
126 
127  // set prefix: length of message excluding the prefix
128  replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
129 
130  // set header information of the reply
133  replyMsg->header.replyType = ROS_REPLY_SUCCESS;
134 
135  replyMsg->body.motionReply.groupNo = ctrlGrp;
136 
137  // set reply body
138  if(receiveMsg->header.msgType == ROS_MSG_MOTO_MOTION_CTRL)
139  {
140  replyMsg->body.motionReply.sequence = receiveMsg->body.motionCtrl.sequence;
141  replyMsg->body.motionReply.command = receiveMsg->body.motionCtrl.command;
142  }
143  else if(receiveMsg->header.msgType == ROS_MSG_JOINT_TRAJ_PT_FULL)
144  {
145  replyMsg->body.motionReply.sequence = receiveMsg->body.jointTrajData.sequence;
147  }
148  else if (receiveMsg->header.msgType == ROS_MSG_MOTO_JOINT_TRAJ_PT_FULL_EX)
149  {
150  replyMsg->body.motionReply.sequence = receiveMsg->body.jointTrajDataEx.sequence;
152  }
153  if (receiveMsg->header.msgType == ROS_MSG_MOTO_SELECT_TOOL)
154  {
155  replyMsg->body.motionReply.sequence = receiveMsg->body.selectTool.sequence;
156  replyMsg->body.motionReply.command = receiveMsg->header.msgType;
157  }
158  else
159  {
160  replyMsg->body.motionReply.groupNo = -1;
161  replyMsg->body.motionReply.sequence = -1;
162  replyMsg->body.motionReply.command = receiveMsg->header.msgType;
163  }
164 
165  replyMsg->body.motionReply.result = result;
166  replyMsg->body.motionReply.subcode = subcode;
167 
168  return(replyMsg->prefix.length + sizeof(SmPrefix));
169 }
170 
171 // Creates a simple message of type ROS_MSG_MOTO_IOCTRL_REPLY to reply to a received message
172 // result error code and subcode. (Not used for successful commands.)
174 {
175  //initialize memory
176  memset(replyMsg, 0x00, sizeof(SimpleMsg));
177 
178  // set prefix: length of message excluding the prefix
179  replyMsg->prefix.length = sizeof(SmHeader) + sizeof(SmBodyMotoMotionReply);
180 
181  // set header information of the reply
184  replyMsg->header.replyType = ROS_REPLY_SUCCESS;
185 
186  // set reply body
187  replyMsg->body.ioCtrlReply.result = result;
188  replyMsg->body.ioCtrlReply.subcode = subcode;
189 
190  return(replyMsg->prefix.length + sizeof(SmPrefix));
191 }
192 
193 #ifdef DEBUG
194 // function to dump data structure for debugging
195 void Ros_SimpleMsg_DumpTrajPtFull(SmBodyJointTrajPtFull* data)
196 {
197  printf("Dumping SmBodyJointTrajPtFull:\r\n");
198  printf(" groupNo=%d\r\n", data->groupNo);
199  printf(" sequence=%d\r\n", data->sequence);
200  printf(" validFields=%d\r\n", data->validFields);
201  printf(" time=%.5f\r\n", data->time);
202  printf(" pos: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
203  data->pos[0], data->pos[1], data->pos[2], data->pos[3],
204  data->pos[4], data->pos[5], data->pos[6]);
205  printf(" vel: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
206  data->vel[0], data->vel[1], data->vel[2], data->vel[3],
207  data->vel[4], data->vel[5], data->vel[6]);
208  printf(" acc: %.5f, %.5f, %.5f, %.5f, %.5f, %.5f, %.5f\r\n",
209  data->acc[0], data->acc[1], data->acc[2], data->acc[3],
210  data->acc[4], data->acc[5], data->acc[6]);
211 }
212 #endif
SmMsgType msgType
SmBodyJointFeedback jointTrajPtData[MOT_MAX_GR]
SmBodyJointTrajPtFull jointTrajData
SmCommandType command
SmBodyJointFeedbackEx jointFeedbackEx
struct _SmHeader SmHeader
SmPrefix prefix
SmBodyMotoMotionCtrl motionCtrl
BOOL Ros_CtrlGroup_GetFBPulsePos(CtrlGroup *ctrlGroup, long pulsePos[MAX_PULSE_AXES])
Definition: CtrlGroup.c:271
float pos[ROS_MAX_JOINT]
int subcode
float vel[ROS_MAX_JOINT]
SmBodyJointTrajPtFullEx jointTrajDataEx
int Ros_SimpleMsg_JointFeedbackEx_Build(int groupIndex, SimpleMsg *src_msgFeedback, SimpleMsg *dst_msgExtendedFeedback)
int Ros_SimpleMsg_MotionReply(SimpleMsg *receiveMsg, int result, int subcode, SimpleMsg *replyMsg, int ctrlGrp)
SmBodyMotoMotionReply motionReply
SmBodySelectTool selectTool
float data[ROS_MAX_JOINT]
SmBodyJointFeedback jointFeedback
SmHeader header
float vel[ROS_MAX_JOINT]
SmResultType result
SmReplyType replyType
void Ros_SimpleMsg_JointFeedbackEx_Init(int numberOfGroups, SimpleMsg *sendMsg)
Definition: SimpleMessage.c:90
int Ros_SimpleMsg_IoReply(int result, int subcode, SimpleMsg *replyMsg)
SmCommType commType
int groupNo
Definition: CtrlGroup.h:82
BOOL Ros_CtrlGroup_GetFBServoSpeed(CtrlGroup *ctrlGroup, long pulseSpeed[MAX_PULSE_AXES])
Definition: CtrlGroup.c:345
FlagsValidFields validFields
int Ros_SimpleMsg_JointFeedback(CtrlGroup *ctrlGroup, SimpleMsg *sendMsg)
Definition: SimpleMessage.c:51
SmBodyMotoIoCtrlReply ioCtrlReply
float pos[ROS_MAX_JOINT]
FlagsValidFields validFields
float acc[ROS_MAX_JOINT]
void Ros_CtrlGroup_ConvertToRosPos(CtrlGroup *ctrlGroup, long motopulsePos[MAX_PULSE_AXES], float rosPos[MAX_PULSE_AXES])
Definition: CtrlGroup.c:479


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute), Ted Miller (MotoROS) (Yaskawa Motoman), Eric Marcil (MotoROS) (Yaskawa Motoman)
autogenerated on Sat May 8 2021 02:27:44