reverse_interface.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2019 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
29 #ifndef UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED
30 #define UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED
31 
35 #include "ur_client_library/log.h"
36 #include <cstring>
37 #include <endian.h>
38 #include <condition_variable>
39 
40 namespace urcl
41 {
42 namespace control
43 {
47 enum class TrajectoryControlMessage : int32_t
48 {
49  TRAJECTORY_CANCEL = -1,
50  TRAJECTORY_NOOP = 0,
51  TRAJECTORY_START = 1,
52 };
53 
57 enum class FreedriveControlMessage : int32_t
58 {
59  FREEDRIVE_STOP = -1,
60  FREEDRIVE_NOOP = 0,
61  FREEDRIVE_START = 1,
62 };
63 
69 {
70 public:
71  static const int32_t MULT_JOINTSTATE = 1000000;
72 
73  ReverseInterface() = delete;
80  ReverseInterface(uint32_t port, std::function<void(bool)> handle_program_state);
81 
85  virtual ~ReverseInterface() = default;
86 
96  virtual bool write(const vector6d_t* positions, const comm::ControlMode control_mode = comm::ControlMode::MODE_IDLE);
97 
106  bool writeTrajectoryControlMessage(const TrajectoryControlMessage trajectory_action, const int point_number = 0);
107 
115  bool writeFreedriveControlMessage(const FreedriveControlMessage freedrive_action);
116 
122  virtual void setKeepaliveCount(const uint32_t& count)
123  {
124  keepalive_count_ = count;
125  }
126 
127 protected:
128  virtual void connectionCallback(const int filedescriptor);
129 
130  virtual void disconnectionCallback(const int filedescriptor);
131 
132  virtual void messageCallback(const int filedescriptor, char* buffer, int nbytesrecv);
133 
136 
137  template <typename T>
138  size_t append(uint8_t* buffer, T& val)
139  {
140  size_t s = sizeof(T);
141  std::memcpy(buffer, &val, s);
142  return s;
143  }
144 
145  static const int MAX_MESSAGE_LENGTH = 8;
146 
147  std::function<void(bool)> handle_program_state_;
149 };
150 
151 } // namespace control
152 } // namespace urcl
153 
154 #endif // UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED
Represents command to start a new trajectory.
Represents command to cancel currently active trajectory.
FreedriveControlMessage
Control messages for starting and stopping freedrive mode.
size_t append(uint8_t *buffer, T &val)
Wrapper class for a TCP socket server.
Definition: tcp_server.h:59
Set when no controller is currently active controlling the robot.
virtual void setKeepaliveCount(const uint32_t &count)
Set the Keepalive count. This will set the number of allowed timeout reads on the robot...
ControlMode
Control modes as interpreted from the script runnning on the robot.
Definition: control_mode.h:39
Represents command to start freedrive mode.
TrajectoryControlMessage
Control messages for forwarding and aborting trajectories.
std::function< void(bool)> handle_program_state_
std::array< double, 6 > vector6d_t
Definition: types.h:30
Represents keep running in freedrive mode.
The ReverseInterface class handles communication to the robot. It starts a server and waits for the r...
Represents command to stop freedrive mode.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47