robot_program_executor.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * FSRobo-R Package BSDL
3 * ---------
4 * Copyright (C) 2019 FUJISOFT. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *********************************************************************/
28 
33 #include "ros/ros.h"
35 #include <string>
36 
37 
39 
46 using std::string;
47 using std::vector;
48 
49 namespace fsrobo_r_driver
50 {
51 namespace robot_program_executor
52 {
53 
55 {
56  connection_ = connection;
57  return true;
58 }
59 
60 bool RobotProgramExecutor::execute(string name, string param, bool &result)
61 {
62  ExecuteProgramReply reply;
63 
64  if (!sendAndReceive(name, param, reply))
65  {
66  ROS_ERROR("Failed to send EXECUTE_PROGRAM command");
67  return false;
68  }
69 
70  //return (reply.getResultCode() == ExecuteProgramReplyResults::SUCCESS);
71  result = (reply.getResultCode() == ExecuteProgramReplyResults::SUCCESS);
72  return true;
73 }
74 
75 bool RobotProgramExecutor::sendAndReceive(string name, string param,ExecuteProgramReply &reply)
76 {
77  SimpleMessage req, res;
78  SimpleString ss_name;
79  SimpleString ss_param;
80  ExecuteProgram execute_program;
81  ExecuteProgramMessage execute_program_msg;
82  ExecuteProgramReplyMessage execute_program_reply_msg;
83 
84  ss_name.init(name);
85  ss_param.init(param);
86  ROS_ERROR("%s", name.c_str());
87  ROS_ERROR("%s", param.c_str());
88  execute_program.init(ss_name, ss_param);
89  execute_program_msg.init(execute_program);
90  execute_program_msg.toRequest(req);
91 
92  if (!this->connection_->sendAndReceiveMsg(req, res))
93  {
94  ROS_ERROR("Failed to send RobotProgram message");
95  return false;
96  }
97 
98  execute_program_reply_msg.init(res);
99  reply.copyFrom(execute_program_reply_msg.reply_);
100 
101  return true;
102 }
103 
104 }
105 
106 }
void init()
Initializes a empty execute program command.
industrial::shared_types::shared_int getResultCode() const
Returns the result code.
void copyFrom(ExecuteProgramReply &src)
Copies the passed in value.
virtual bool toRequest(industrial::simple_message::SimpleMessage &msg)
bool sendAndReceiveMsg(industrial::simple_message::SimpleMessage &send, industrial::simple_message::SimpleMessage &recv, bool verbose=false)
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
Class encapsulated set io reply data. These messages are sent by the FSRobo-R controller in response ...
fsrobo_r_driver::simple_message::execute_program_reply::ExecuteProgramReply reply_
Class encapsulated FSRobo-R set io reply message generation methods (either to or from a industrial::...
bool init(industrial::simple_message::SimpleMessage &msg)
Initializes message from a simple message.
bool execute(std::string name, std::string param, bool &result)
Execute robot program on the controller.
void init()
Initializes a empty motion control reply.
bool sendAndReceive(std::string name, std::string param, ExecuteProgramReply &reply)
Class encapsulated set io reply data. These messages are sent by the FSRobo-R controller in response ...
Definition: simple_string.h:61
Class encapsulated write single io data. FSRobo-R specific interface to set IO element on the control...
#define ROS_ERROR(...)
Class encapsulated FSRobo-R set io message generation methods (either to or from a industrial::simple...


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29