utest_message.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
43 
44 #include <gtest/gtest.h>
45 
46 using namespace industrial::simple_message;
47 using namespace industrial::tcp_socket;
48 using namespace industrial::tcp_client;
49 using namespace industrial::tcp_server;
50 using namespace industrial::joint_data;
51 using namespace industrial::joint_message;
52 using namespace industrial::joint_traj_pt;
53 using namespace industrial::joint_traj_pt_message;
54 using namespace industrial::typed_message;
55 using namespace industrial::joint_traj;
56 using namespace industrial::robot_status;
57 using namespace industrial::robot_status_message;
58 
59 // Message passing routine, used to send and receive a typed message
60 // Useful for checking the packing and unpacking of message data.
62 {
63  const int tcpPort = TEST_PORT_BASE+401;
64  char ipAddr[] = "127.0.0.1";
65 
66  TcpClient tcpClient;
67  TcpServer tcpServer;
68  SimpleMessage msgSend, msgRecv;
69 
70  ASSERT_TRUE(send.toTopic(msgSend));
71 
72  // Construct server
73 
74  ASSERT_TRUE(tcpServer.init(tcpPort));
75 
76  // Construct a client
77  ASSERT_TRUE(tcpClient.init(&ipAddr[0], tcpPort));
78  ASSERT_TRUE(tcpClient.makeConnect());
79 
80  ASSERT_TRUE(tcpServer.makeConnect());
81 
82  ASSERT_TRUE(tcpClient.sendMsg(msgSend));
83  ASSERT_TRUE(tcpServer.receiveMsg(msgRecv));
84  ASSERT_TRUE(recv.init(msgRecv));
85 }
86 
88 {
89  JointData joint;
90 
91  joint.init();
92  EXPECT_TRUE(joint.setJoint(0, 1.0));
93  EXPECT_TRUE(joint.setJoint(1, 2.0));
94  EXPECT_TRUE(joint.setJoint(2, 3.0));
95  EXPECT_TRUE(joint.setJoint(3, 4.0));
96  EXPECT_TRUE(joint.setJoint(4, 5.0));
97  EXPECT_TRUE(joint.setJoint(5, 6.0));
98  EXPECT_TRUE(joint.setJoint(6, 7.0));
99  EXPECT_TRUE(joint.setJoint(7, 8.0));
100  EXPECT_TRUE(joint.setJoint(8, 9.0));
101  EXPECT_TRUE(joint.setJoint(9, 10.0));
102 
103  EXPECT_FALSE(joint.setJoint(10, 11.0));
104 
105 }
106 
108 {
109  JointData jointlhs, jointrhs;
110 
111  jointrhs.init();
112  jointlhs.init();
113  jointlhs.setJoint(0, -1.0);
114  jointlhs.setJoint(9, 1.0);
115 
116  EXPECT_FALSE(jointlhs==jointrhs);
117 
118  jointrhs.setJoint(0, -1.0);
119  jointrhs.setJoint(9, 1.0);
120 
121  EXPECT_TRUE(jointlhs==jointrhs);
122 
123 }
124 
125 TEST(JointMessage, toMessage)
126 {
127  JointData toMessage, fromMessage;
128  JointMessage msg;
129 
130  toMessage.init();
131  toMessage.setJoint(4, 44.44);
132 
133  msg.init(1, toMessage);
134 
135  fromMessage.copyFrom(msg.getJoints());
136 
137  EXPECT_TRUE(toMessage==fromMessage);
138 
139 }
140 
142 {
143 
144  JointMessage jointSend, jointRecv;
145  JointData posSend, posRecv;
146 
147  posSend.init();
148  posSend.setJoint(0, 1.0);
149  posSend.setJoint(1, 2.0);
150  posSend.setJoint(2, 3.0);
151  posSend.setJoint(3, 4.0);
152  posSend.setJoint(4, 5.0);
153  posSend.setJoint(5, 6.0);
154  posSend.setJoint(6, 7.0);
155  posSend.setJoint(7, 8.0);
156  posSend.setJoint(8, 9.0);
157  posSend.setJoint(9, 10.0);
158 
159  jointSend.init(1, posSend);
160 
161  messagePassing(jointSend, jointRecv);
162 
163  posRecv.copyFrom(jointRecv.getJoints());
164  ASSERT_TRUE(posRecv==posSend);
165 }
166 
168 {
169  JointTrajPt lhs, rhs;
170  JointData joint;
171 
172  joint.init();
173  ASSERT_TRUE(joint.setJoint(0, 1.0));
174  ASSERT_TRUE(joint.setJoint(1, 2.0));
175  ASSERT_TRUE(joint.setJoint(2, 3.0));
176  ASSERT_TRUE(joint.setJoint(3, 4.0));
177  ASSERT_TRUE(joint.setJoint(4, 5.0));
178  ASSERT_TRUE(joint.setJoint(5, 6.0));
179  ASSERT_TRUE(joint.setJoint(6, 7.0));
180  ASSERT_TRUE(joint.setJoint(7, 8.0));
181  ASSERT_TRUE(joint.setJoint(8, 9.0));
182  ASSERT_TRUE(joint.setJoint(9, 10.0));
183 
184  rhs.init(1.0, joint, 50.0, 100);
185  EXPECT_FALSE(lhs==rhs);
186 
187  lhs.init(0, joint, 0, 0);
188  EXPECT_FALSE(lhs==rhs);
189 
190  lhs.copyFrom(rhs);
191  EXPECT_TRUE(lhs==rhs);
192 
193 }
194 
195 TEST(JointTrajPt, toMessage)
196 {
197  JointTrajPt toMessage, fromMessage;
198  JointTrajPtMessage msg;
199 
200  toMessage.init();
201  toMessage.setSequence(99);
202  msg.init(toMessage);
203 
204  fromMessage.copyFrom(msg.point_);
205 
206  EXPECT_TRUE(toMessage==fromMessage);
207 
208 }
209 
211 {
212 
213  JointTrajPtMessage jointSend, jointRecv;
214  JointData data;
215  JointTrajPt posSend, posRecv;
216 
217  data.init();
218  data.setJoint(0, 1.0);
219  data.setJoint(1, 2.0);
220  data.setJoint(2, 3.0);
221  data.setJoint(3, 4.0);
222  data.setJoint(4, 5.0);
223  data.setJoint(5, 6.0);
224  data.setJoint(6, 7.0);
225  data.setJoint(7, 8.0);
226  data.setJoint(8, 9.0);
227  data.setJoint(9, 10.0);
228  posSend.init(1, data, 99, 100);
229 
230  jointSend.init(posSend);
231 
232  messagePassing(jointSend, jointRecv);
233 
234  posRecv.copyFrom(jointRecv.point_);
235  ASSERT_TRUE(posRecv==posSend);
236 }
237 
239 {
240  JointTraj lhs, rhs;
241  JointData joint;
242  JointTrajPt point;
243 
244  joint.init();
245  ASSERT_TRUE(joint.setJoint(0, 1.0));
246  ASSERT_TRUE(joint.setJoint(1, 2.0));
247  ASSERT_TRUE(joint.setJoint(2, 3.0));
248  ASSERT_TRUE(joint.setJoint(3, 4.0));
249  ASSERT_TRUE(joint.setJoint(4, 5.0));
250  ASSERT_TRUE(joint.setJoint(5, 6.0));
251  ASSERT_TRUE(joint.setJoint(6, 7.0));
252  ASSERT_TRUE(joint.setJoint(7, 8.0));
253  ASSERT_TRUE(joint.setJoint(8, 9.0));
254  ASSERT_TRUE(joint.setJoint(9, 10.0));
255 
256  point.init(1.0, joint, 50.0, 100);
257  rhs.addPoint(point);
258  EXPECT_FALSE(lhs==rhs);
259 
260  lhs.addPoint(point);
261  EXPECT_TRUE(lhs==rhs);
262 
263  lhs.addPoint(point);
264  EXPECT_FALSE(lhs==rhs);
265 
266  lhs.copyFrom(rhs);
267  EXPECT_TRUE(lhs==rhs);
268 
269 }
270 
271 TEST(RobotStatus, enumerations)
272 {
273  // Verifying the disabled state and aliases match
277 
278  // Verifying the enabled state and aliases values match
282 
283  // Verifying the unknown values match (this isn't reqd, but makes sense)
285 }
286 
288 {
289  RobotStatus status;
290  RobotStatus empty;
291  status.init();
292  // An empty (non-initted) status should be initialized in the constructor.
293  EXPECT_TRUE(status==empty);
294  EXPECT_EQ(status.getDrivesPowered(), TriStates::TS_UNKNOWN);
295  EXPECT_EQ(status.getEStopped(), TriStates::TS_UNKNOWN);
296  EXPECT_EQ(status.getErrorCode(), 0);
297  EXPECT_EQ(status.getInError(), TriStates::TS_UNKNOWN);
298  EXPECT_EQ(status.getInMotion(), TriStates::TS_UNKNOWN);
299  EXPECT_EQ(status.getMode(), RobotModes::UNKNOWN);
300  EXPECT_EQ(status.getMotionPossible(), TriStates::TS_UNKNOWN);
301 }
302 
304 {
305  RobotStatus lhs, rhs;
306 
307  EXPECT_TRUE(lhs==rhs);
309  EXPECT_FALSE(lhs==rhs);
311  EXPECT_TRUE(lhs==rhs);
312 
314  EXPECT_FALSE(lhs==rhs);
316  EXPECT_TRUE(lhs==rhs);
317 
318  lhs.setErrorCode(99);
319  EXPECT_FALSE(lhs==rhs);
320  rhs.setErrorCode(99);
321  EXPECT_TRUE(lhs==rhs);
322 
324  EXPECT_FALSE(lhs==rhs);
326  EXPECT_TRUE(lhs==rhs);
327 
329  EXPECT_FALSE(lhs==rhs);
331  EXPECT_TRUE(lhs==rhs);
332 
334  EXPECT_FALSE(lhs==rhs);
336  EXPECT_TRUE(lhs==rhs);
337 
339  EXPECT_FALSE(lhs==rhs);
341  EXPECT_TRUE(lhs==rhs);
342 
343 }
344 
345 TEST(RobotStatus, toMessage)
346 {
347  RobotStatus toMessage, fromMessage;
348  RobotStatusMessage msg;
349 
352  msg.init(toMessage);
353 
354  fromMessage.copyFrom(msg.status_);
355 
356  EXPECT_TRUE(toMessage==fromMessage);
357 
358 }
359 
361 {
362  RobotStatusMessage statusMsgSend, statusMsgRecv;
363  RobotStatus statusSend, statusRecv;
364 
367 
368  statusMsgSend.init(statusSend);
369 
370  messagePassing(statusMsgSend, statusMsgRecv);
371 
372  statusRecv.copyFrom(statusMsgRecv.status_);
373  ASSERT_TRUE(statusRecv==statusSend);
374 }
375 
joint_message.h
industrial::robot_status::TriStates::TS_FALSE
@ TS_FALSE
Definition: robot_status.h:86
TEST
TEST(JointMessage, init)
Definition: utest_message.cpp:87
robot_status_message.h
industrial::robot_status
Definition: robot_status.h:47
industrial::joint_data::JointData
Class encapsulated joint data (positions, accelerations, velocity, torque, and/or effort).
Definition: joint_data.h:68
industrial::robot_status::RobotStatus::getEStopped
TriState getEStopped()
Definition: robot_status.h:152
industrial::joint_traj_pt::JointTrajPt
Class encapsulated joint trajectory point data. The point data serves as a waypoint along a trajector...
Definition: joint_traj_pt.h:92
industrial::joint_traj_pt_message::JointTrajPtMessage::init
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Definition: joint_traj_pt_message.cpp:64
industrial::joint_traj::JointTraj::copyFrom
void copyFrom(JointTraj &src)
Copies the passed in value.
Definition: joint_traj.cpp:105
industrial::joint_traj_pt_message::JointTrajPtMessage::point_
industrial::joint_traj_pt::JointTrajPt point_
Definition: joint_traj_pt_message.h:120
industrial::robot_status_message::RobotStatusMessage::status_
industrial::robot_status::RobotStatus status_
Definition: robot_status_message.h:115
industrial::robot_status::TriStates::TS_TRUE
@ TS_TRUE
Definition: robot_status.h:84
industrial::robot_status::RobotModes::UNKNOWN
@ UNKNOWN
Definition: robot_status.h:58
industrial::robot_status::RobotStatus::copyFrom
void copyFrom(RobotStatus &src)
Copies the passed in value.
Definition: robot_status.cpp:142
industrial::robot_status::RobotStatus::getMode
RobotMode getMode()
Definition: robot_status.h:172
industrial::robot_status::TriStates::TS_LOW
@ TS_LOW
Definition: robot_status.h:86
industrial::robot_status::RobotStatus::getInError
TriState getInError()
Definition: robot_status.h:162
industrial::robot_status::RobotStatus::getErrorCode
industrial::shared_types::shared_int getErrorCode() const
Definition: robot_status.h:157
simple_message.h
industrial::joint_traj::JointTraj
Class encapsulated joint trajectory. A joint trajectory includes an array of JointTrajPt data types....
Definition: joint_traj.h:70
industrial::typed_message::TypedMessage::toTopic
virtual bool toTopic(industrial::simple_message::SimpleMessage &msg)
creates a simple_message topic
Definition: typed_message.h:124
industrial::joint_traj_pt::JointTrajPt::setSequence
void setSequence(industrial::shared_types::shared_int sequence)
Sets joint trajectory point sequence number.
Definition: joint_traj_pt.h:146
industrial::typed_message::TypedMessage::init
virtual bool init(industrial::simple_message::SimpleMessage &msg)=0
Initializes message from a simple message.
industrial::robot_status::RobotStatus::setDrivesPowered
void setDrivesPowered(TriState drivesPowered)
Definition: robot_status.h:182
industrial::robot_status::RobotStatus::setEStopped
void setEStopped(TriState eStopped)
Definition: robot_status.h:187
industrial::robot_status::RobotStatus::setMotionPossible
void setMotionPossible(TriState motionPossible)
Definition: robot_status.h:212
industrial::robot_status::TriStates::TS_UNKNOWN
@ TS_UNKNOWN
Definition: robot_status.h:82
industrial::tcp_socket
Definition: tcp_socket.h:63
industrial::joint_data
Definition: joint_data.h:47
industrial::typed_message
Definition: typed_message.h:46
industrial::robot_status::TriStates::TS_HIGH
@ TS_HIGH
Definition: robot_status.h:84
industrial::tcp_client
Definition: tcp_client.h:45
industrial::tcp_server::TcpServer::init
bool init(int port_num)
initializes TCP server socket. The connect method must be called following initialization in order to...
Definition: tcp_server.cpp:57
joint_traj_pt.h
industrial::robot_status::RobotStatus::setMode
void setMode(RobotMode mode)
Definition: robot_status.h:207
industrial::joint_traj_pt
Definition: joint_traj_pt.h:49
joint_traj.h
industrial::simple_message::SimpleMessage
This class defines a simple messaging protocol for communicating with an industrial robot controller.
Definition: simple_message.h:164
industrial::robot_status::RobotModes::MANUAL
@ MANUAL
Definition: robot_status.h:60
industrial::robot_status::RobotStatus::setInError
void setInError(TriState inError)
Definition: robot_status.h:197
industrial::simple_message
Definition: simple_message.h:49
industrial::robot_status::RobotModes::AUTO
@ AUTO
Definition: robot_status.h:60
industrial::robot_status::RobotStatus
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: robot_status.h:118
tcp_client.h
industrial::tcp_server::TcpServer
Defines TCP server functions.
Definition: tcp_server.h:49
industrial::tcp_client::TcpClient::init
bool init(char *buff, int port_num)
initializes TCP client socket. Object can either be a client OR a server, NOT BOTH.
Definition: tcp_client.cpp:55
industrial::joint_data::JointData::init
void init()
Initializes a empty joint data.
Definition: joint_data.cpp:57
industrial::joint_traj::JointTraj::addPoint
bool addPoint(industrial::joint_traj_pt::JointTrajPt &point)
Adds a point value to the end of the buffer.
Definition: joint_traj.cpp:69
industrial::tcp_client::TcpClient::makeConnect
bool makeConnect()
connects to the remote host
Definition: tcp_client.cpp:91
industrial::joint_message::JointMessage
Class encapsulated joint message generation methods (either to or from a SimpleMessage type....
Definition: joint_message.h:85
industrial::robot_status::RobotStatus::getMotionPossible
TriState getMotionPossible()
Definition: robot_status.h:177
industrial::joint_traj_pt::JointTrajPt::init
void init()
Initializes a empty joint trajectory point.
Definition: joint_traj_pt.cpp:58
industrial::robot_status::TriStates::TS_ENABLED
@ TS_ENABLED
Definition: robot_status.h:84
industrial::joint_message::JointMessage::init
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Definition: joint_message.cpp:65
industrial::robot_status_message::RobotStatusMessage
Class encapsulated robot status message generation methods (either to or from a industrial::simple_me...
Definition: robot_status_message.h:66
industrial::robot_status::RobotStatus::setErrorCode
void setErrorCode(industrial::shared_types::shared_int errorCode)
Definition: robot_status.h:192
industrial::joint_traj_pt_message::JointTrajPtMessage
Class encapsulated joint trajectory point message generation methods (either to or from a industrial:...
Definition: joint_traj_pt_message.h:65
messagePassing
void messagePassing(TypedMessage &send, TypedMessage &recv)
Definition: utest_message.cpp:61
industrial::joint_traj
Definition: joint_traj.h:51
industrial::joint_traj_pt_message
Definition: joint_traj_pt_message.h:49
industrial::robot_status_message
Definition: robot_status_message.h:49
industrial::robot_status::RobotStatus::setInMotion
void setInMotion(TriState inMotion)
Definition: robot_status.h:202
joint_data.h
industrial::joint_message
Definition: joint_message.h:49
industrial::joint_data::JointData::copyFrom
void copyFrom(JointData &src)
Copies the passed in value.
Definition: joint_data.cpp:107
industrial::joint_message::JointMessage::getJoints
industrial::joint_data::JointData & getJoints()
returns reference to underlying joint class
Definition: joint_message.h:146
industrial::tcp_server::TcpServer::makeConnect
bool makeConnect()
connects to the remote host
Definition: tcp_server.cpp:118
industrial::typed_message::TypedMessage
Message interface for typed messages built from SimpleMessage.
Definition: typed_message.h:74
typed_message.h
industrial::robot_status::TriStates::TS_DISABLED
@ TS_DISABLED
Definition: robot_status.h:86
industrial::robot_status::TriStates::TS_OFF
@ TS_OFF
Definition: robot_status.h:86
industrial::robot_status::RobotStatus::getDrivesPowered
TriState getDrivesPowered()
Definition: robot_status.h:147
industrial::robot_status::RobotStatus::getInMotion
TriState getInMotion()
Definition: robot_status.h:167
tcp_server.h
industrial::tcp_server
Definition: tcp_server.h:43
industrial::robot_status::RobotStatus::init
void init()
Initializes an empty robot status.
Definition: robot_status.cpp:124
industrial::smpl_msg_connection::SmplMsgConnection::receiveMsg
virtual bool receiveMsg(industrial::simple_message::SimpleMessage &message)
Receives a message using the data connection.
Definition: smpl_msg_connection.cpp:80
joint_traj_pt_message.h
industrial::robot_status::TriStates::TS_ON
@ TS_ON
Definition: robot_status.h:84
industrial::tcp_client::TcpClient
Defines TCP client functions.
Definition: tcp_client.h:52
industrial::joint_data::JointData::setJoint
bool setJoint(industrial::shared_types::shared_int index, industrial::shared_types::shared_real value)
Sets a joint value within the buffer.
Definition: joint_data.cpp:65
industrial::joint_traj_pt::JointTrajPt::copyFrom
void copyFrom(JointTrajPt &src)
Copies the passed in value.
Definition: joint_traj_pt.cpp:74
industrial::smpl_msg_connection::SmplMsgConnection::sendMsg
virtual bool sendMsg(industrial::simple_message::SimpleMessage &message)
Sends a message using the data connection.
Definition: smpl_msg_connection.cpp:57
industrial::robot_status_message::RobotStatusMessage::init
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Definition: robot_status_message.cpp:64
robot_status.h


simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53