robot_status.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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 #ifndef FLATHEADERS
35 #else
36 #include "robot_status.h"
37 #include "shared_types.h"
38 #include "log_wrapper.h"
39 #endif
40 
41 // remove ROS after Melodic (bw compat for #262)
42 #if defined(SIMPLE_MESSAGE_USE_ROS) || defined(ROS)
43 // Files below used to translate between ROS messages enums and
44 // enums defined in this file
45 #include "industrial_msgs/RobotMode.h"
46 #include "industrial_msgs/TriState.h"
47 #endif
48 
49 using namespace industrial::shared_types;
50 
51 namespace industrial
52 {
53 namespace robot_status
54 {
55 
56 namespace RobotModes
57 {
58 
59 // remove ROS after Melodic (bw compat for #262)
60 #if defined(SIMPLE_MESSAGE_USE_ROS) || defined(ROS)
61 
62 int toROSMsgEnum(RobotModes::RobotMode mode)
63 {
64 
65  switch (mode)
66  {
67  case RobotModes::AUTO:
69  break;
70  case RobotModes::MANUAL:
72  break;
75  }
77 
78 }
79 ;
80 
81 #endif
82 
83 }
84 
85 namespace TriStates
86 {
87 
88 // remove ROS after Melodic (bw compat for #262)
89 #if defined(SIMPLE_MESSAGE_USE_ROS) || defined(ROS)
90 
91 int toROSMsgEnum(TriStates::TriState state)
92 {
93 
94  switch (state)
95  {
98  break;
99  case TriStates::TS_TRUE:
100  return industrial_msgs::TriState::TRUE;
101  break;
102  case TriStates::TS_FALSE:
103  return industrial_msgs::TriState::FALSE;
104  break;
105  }
107 
108 }
109 ;
110 
111 #endif
112 
113 }
114 
115 RobotStatus::RobotStatus(void)
116 {
117  this->init();
118 }
119 RobotStatus::~RobotStatus(void)
120 {
121 
122 }
123 
124 void RobotStatus::init()
125 {
128 }
129 
130 void RobotStatus::init(TriState drivesPowered, TriState eStopped, industrial::shared_types::shared_int errorCode,
131  TriState inError, TriState inMotion, RobotMode mode, TriState motionPossible)
132 {
133  this->setDrivesPowered(drivesPowered);
134  this->setEStopped(eStopped);
135  this->setErrorCode(errorCode);
136  this->setInError(inError);
137  this->setInMotion(inMotion);
138  this->setMode(mode);
139  this->setMotionPossible(motionPossible);
140 }
141 
142 void RobotStatus::copyFrom(RobotStatus &src)
143 {
144  this->setDrivesPowered(src.getDrivesPowered());
145  this->setEStopped(src.getEStopped());
146  this->setErrorCode(src.getErrorCode());
147  this->setInError(src.getInError());
148  this->setInMotion(src.getInMotion());
149  this->setMode(src.getMode());
150  this->setMotionPossible(src.getMotionPossible());
151 }
152 
153 bool RobotStatus::operator==(RobotStatus &rhs)
154 {
155  return this->drives_powered_ == rhs.drives_powered_ && this->e_stopped_ == rhs.e_stopped_
156  && this->error_code_ == rhs.error_code_ && this->in_error_ == rhs.in_error_ && this->in_motion_ == rhs.in_motion_
157  && this->mode_ == rhs.mode_ && this->motion_possible_ == rhs.motion_possible_;
158 }
159 
160 bool RobotStatus::load(industrial::byte_array::ByteArray *buffer)
161 {
162  bool rtn = false;
163 
164  LOG_COMM("Executing robot status load");
165 
166  if (buffer->load(this->drives_powered_) && buffer->load(this->e_stopped_) && buffer->load(this->error_code_)
167  && buffer->load(this->in_error_) && buffer->load(this->in_motion_) && buffer->load(this->mode_)
168  && buffer->load(this->motion_possible_))
169  {
170 
171  LOG_COMM("Robot status successfully loaded");
172  rtn = true;
173  }
174  else
175  {
176  LOG_COMM("Robot status not loaded");
177  rtn = false;
178  }
179 
180  return rtn;
181 }
182 
183 bool RobotStatus::unload(industrial::byte_array::ByteArray *buffer)
184 {
185  bool rtn = false;
186 
187  LOG_COMM("Executing robot status unload");
188  if (buffer->unload(this->motion_possible_) && buffer->unload(this->mode_) && buffer->unload(this->in_motion_)
189  && buffer->unload(this->in_error_) && buffer->unload(this->error_code_) && buffer->unload(this->e_stopped_)
190  && buffer->unload(this->drives_powered_))
191  {
192 
193  rtn = true;
194  LOG_COMM("Robot status successfully unloaded");
195  }
196 
197  else
198  {
199  LOG_ERROR("Failed to unload robot status");
200  rtn = false;
201  }
202 
203  return rtn;
204 }
205 
206 }
207 }
208 
industrial::shared_types::shared_int in_motion_
in motion state (see TriStates::TriState)
Definition: robot_status.h:264
industrial::shared_types::shared_int motion_possible_
motion possible state (see TriStates::TriState)
Definition: robot_status.h:259
industrial::shared_types::shared_int in_error_
in error state (see TriStates::TriState)
Definition: robot_status.h:269
void init(const M_string &remappings)
Contains platform specific type definitions that guarantee the size of primitive data types...
Definition: shared_types.h:52
industrial::shared_types::shared_int mode_
Operating mode (see RobotModes::RobotMode)
Definition: robot_status.h:244
#define LOG_COMM(format,...)
Definition: log_wrapper.h:130
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: robot_status.h:118
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
Definition: byte_array.cpp:142
#define LOG_ERROR(format,...)
Definition: log_wrapper.h:134
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
industrial::shared_types::shared_int e_stopped_
E-stop state (see TriStates::TriState)
Definition: robot_status.h:249
industrial::shared_types::shared_int getErrorCode() const
Definition: robot_status.h:157
bool unload(industrial::shared_types::shared_bool &value)
unloads a boolean value from the byte array
Definition: byte_array.cpp:233
industrial::shared_types::shared_int error_code_
error code (non-zero is error)
Definition: robot_status.h:274
industrial::shared_types::shared_int drives_powered_
Drive power state (see TriStates::TriState)
Definition: robot_status.h:254


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Feb 28 2022 22:34:36