io_ctrl.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2016, Delft Robotics 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 Delft Robotics 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  * \author G.A. vd. Hoorn (TU Delft Robotics Institute)
32  */
33 
34 #include "motoman_driver/io_ctrl.h"
39 #include "ros/ros.h"
41 #include <string>
42 
43 
46 
55 
56 
57 namespace motoman
58 {
59 namespace io_ctrl
60 {
61 
63 {
64  connection_ = connection;
65  return true;
66 }
67 
68 bool MotomanIoCtrl::readSingleIO(shared_int address, shared_int &value, std::string &err_msg)
69 {
70  ReadSingleIOReply reply;
71 
72  if (!sendAndReceive(address, reply))
73  {
74  ROS_ERROR("Failed to send READ_SINGLE_IO command");
75  return false;
76  }
77 
78  value = reply.getValue();
79 
80  bool read_success = reply.getResultCode() == ReadSingleIOReplyResultCodes::SUCCESS;
81  if (!read_success)
82  {
83  err_msg = reply.getResultString();
84  }
85 
86  return read_success;
87 }
88 
89 bool MotomanIoCtrl::writeSingleIO(shared_int address, shared_int value, std::string &err_msg)
90 {
91  WriteSingleIOReply reply;
92 
93  if (!sendAndReceive(address, value, reply))
94  {
95  ROS_ERROR("Failed to send WRITE_SINGLE_IO command");
96  return false;
97  }
98 
99  bool write_success = reply.getResultCode() == WriteSingleIOReplyResultCodes::SUCCESS;
100  if (!write_success)
101  {
102  err_msg = reply.getResultString();
103  }
104 
105  return write_success;
106 }
107 
109 {
110  SimpleMessage req, res;
112  ReadSingleIOMessage read_io_msg;
113  ReadSingleIOReplyMessage read_io_reply;
114 
115  data.init(address);
116  read_io_msg.init(data);
117  read_io_msg.toRequest(req);
118 
119  if (!this->connection_->sendAndReceiveMsg(req, res))
120  {
121  ROS_ERROR("Failed to send ReadSingleIO message");
122  return false;
123  }
124 
125  read_io_reply.init(res);
126  reply.copyFrom(read_io_reply.reply_);
127 
128  return true;
129 }
130 
132 {
133  SimpleMessage req, res;
135  WriteSingleIOMessage write_io_msg;
136  WriteSingleIOReplyMessage write_io_reply;
137 
138  data.init(address, value);
139  write_io_msg.init(data);
140  write_io_msg.toRequest(req);
141 
142  if (!this->connection_->sendAndReceiveMsg(req, res))
143  {
144  ROS_ERROR("Failed to send WriteSingleIO message");
145  return false;
146  }
147 
148  write_io_reply.init(res);
149  reply.copyFrom(write_io_reply.reply_);
150 
151  return true;
152 }
153 
154 } // namespace io_ctrl
155 
156 } // namespace motoman
Class encapsulated write single io reply data. These messages are sent by the FS100 controller in res...
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
industrial::shared_types::shared_int getResultCode() const
Returns the result code.
bool sendAndReceive(industrial::shared_types::shared_int address, ReadSingleIOReply &reply)
Definition: io_ctrl.cpp:108
void init()
Initializes a empty write single io command.
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Class encapsulated motoman write single io message generation methods (either to or from a industrial...
SmplMsgConnection * connection_
Definition: io_ctrl.h:92
industrial::shared_types::shared_int getValue() const
Returns the value.
UINT32 value
bool readSingleIO(industrial::shared_types::shared_int address, industrial::shared_types::shared_int &value, std::string &err_msg)
Reads a single IO point on the controller.
Definition: io_ctrl.cpp:68
Class encapsulated write single io data. Motoman specific interface to write a single IO element on t...
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
Class encapsulated read single io reply data. These messages are sent by the FS100 controller in resp...
bool init(SmplMsgConnection *connection)
Definition: io_ctrl.cpp:62
void init()
Initializes a empty motion control command.
bool sendAndReceiveMsg(industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, bool verbose=false)
Class encapsulated motoman write single io reply message generation methods (either to or from a indu...
Class encapsulated motoman read single io message generation methods (either to or from a industrial:...
Class encapsulated read single io data. Motoman specific interface to read a single IO element on the...
static std::string getResultString(industrial::shared_types::shared_int code)
industrial::shared_types::shared_int getResultCode() const
Returns the result code.
void copyFrom(ReadSingleIOReply &src)
Copies the passed in value.
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
float data[ROS_MAX_JOINT]
static std::string getResultString(industrial::shared_types::shared_int code)
Class encapsulated motoman read single io reply message generation methods (either to or from a indus...
bool writeSingleIO(industrial::shared_types::shared_int address, industrial::shared_types::shared_int value, std::string &err_msg)
Writes to a single IO point on the controller.
Definition: io_ctrl.cpp:89
void copyFrom(WriteSingleIOReply &src)
Copies the passed in value.
#define ROS_ERROR(...)


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:43