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 #ifdef ROS
42 // Files below used to translate between ROS messages enums and
43 // enums defined in this file
44 #include "industrial_msgs/RobotMode.h"
45 #include "industrial_msgs/TriState.h"
46 #endif
47 
48 using namespace industrial::shared_types;
49 
50 namespace industrial
51 {
52 namespace robot_status
53 {
54 
55 namespace RobotModes
56 {
57 
58 #ifdef ROS
59 
60 int toROSMsgEnum(RobotModes::RobotMode mode)
61 {
62 
63  switch (mode)
64  {
65  case RobotModes::AUTO:
67  break;
68  case RobotModes::MANUAL:
70  break;
73  }
75 
76 }
77 ;
78 
79 #endif
80 
81 }
82 
83 namespace TriStates
84 {
85 
86 #ifdef ROS
87 
88 int toROSMsgEnum(TriStates::TriState state)
89 {
90 
91  switch (state)
92  {
95  break;
96  case TriStates::TS_TRUE:
97  return industrial_msgs::TriState::TRUE;
98  break;
100  return industrial_msgs::TriState::FALSE;
101  break;
102  }
104 
105 }
106 ;
107 
108 #endif
109 
110 }
111 
112 RobotStatus::RobotStatus(void)
113 {
114  this->init();
115 }
116 RobotStatus::~RobotStatus(void)
117 {
118 
119 }
120 
121 void RobotStatus::init()
122 {
125 }
126 
127 void RobotStatus::init(TriState drivesPowered, TriState eStopped, industrial::shared_types::shared_int errorCode,
128  TriState inError, TriState inMotion, RobotMode mode, TriState motionPossible)
129 {
130  this->setDrivesPowered(drivesPowered);
131  this->setEStopped(eStopped);
132  this->setErrorCode(errorCode);
133  this->setInError(inError);
134  this->setInMotion(inMotion);
135  this->setMode(mode);
136  this->setMotionPossible(motionPossible);
137 }
138 
139 void RobotStatus::copyFrom(RobotStatus &src)
140 {
141  this->setDrivesPowered(src.getDrivesPowered());
142  this->setEStopped(src.getEStopped());
143  this->setErrorCode(src.getErrorCode());
144  this->setInError(src.getInError());
145  this->setInMotion(src.getInMotion());
146  this->setMode(src.getMode());
147  this->setMotionPossible(src.getMotionPossible());
148 }
149 
150 bool RobotStatus::operator==(RobotStatus &rhs)
151 {
152  return this->drives_powered_ == rhs.drives_powered_ && this->e_stopped_ == rhs.e_stopped_
153  && this->error_code_ == rhs.error_code_ && this->in_error_ == rhs.in_error_ && this->in_motion_ == rhs.in_motion_
154  && this->mode_ == rhs.mode_ && this->motion_possible_ == rhs.motion_possible_;
155 }
156 
157 bool RobotStatus::load(industrial::byte_array::ByteArray *buffer)
158 {
159  bool rtn = false;
160 
161  LOG_COMM("Executing robot status load");
162 
163  if (buffer->load(this->drives_powered_) && buffer->load(this->e_stopped_) && buffer->load(this->error_code_)
164  && buffer->load(this->in_error_) && buffer->load(this->in_motion_) && buffer->load(this->mode_)
165  && buffer->load(this->motion_possible_))
166  {
167 
168  LOG_COMM("Robot status successfully loaded");
169  rtn = true;
170  }
171  else
172  {
173  LOG_COMM("Robot status not loaded");
174  rtn = false;
175  }
176 
177  return rtn;
178 }
179 
180 bool RobotStatus::unload(industrial::byte_array::ByteArray *buffer)
181 {
182  bool rtn = false;
183 
184  LOG_COMM("Executing robot status unload");
185  if (buffer->unload(this->motion_possible_) && buffer->unload(this->mode_) && buffer->unload(this->in_motion_)
186  && buffer->unload(this->in_error_) && buffer->unload(this->error_code_) && buffer->unload(this->e_stopped_)
187  && buffer->unload(this->drives_powered_))
188  {
189 
190  rtn = true;
191  LOG_COMM("Robot status successfully unloaded");
192  }
193 
194  else
195  {
196  LOG_ERROR("Failed to unload robot status");
197  rtn = false;
198  }
199 
200  return rtn;
201 }
202 
203 }
204 }
205 
industrial::shared_types::shared_int in_motion_
in motion state (see TriStates::TriState)
Definition: robot_status.h:262
industrial::shared_types::shared_int motion_possible_
motion possible state (see TriStates::TriState)
Definition: robot_status.h:257
industrial::shared_types::shared_int in_error_
in error state (see TriStates::TriState)
Definition: robot_status.h:267
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:242
#define LOG_COMM(format,...)
Definition: log_wrapper.h:104
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: robot_status.h:116
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:108
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:247
industrial::shared_types::shared_int getErrorCode() const
Definition: robot_status.h:155
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:272
industrial::shared_types::shared_int drives_powered_
Drive power state (see TriStates::TriState)
Definition: robot_status.h:252


simple_message
Author(s): Shaun Edwards
autogenerated on Sat Sep 21 2019 03:30:09