forked from UniversalRobots/Universal_Robots_Client_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtde_writer.h
More file actions
185 lines (170 loc) · 6.2 KB
/
Copy pathrtde_writer.h
File metadata and controls
185 lines (170 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2019 FZI Forschungszentrum Informatik
// Created on behalf of Universal Robots A/S
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------
//----------------------------------------------------------------------
/*!\file
*
* \author Tristan Schnell schnell@fzi.de
* \date 2019-07-25
*
*/
//----------------------------------------------------------------------
#ifndef UR_CLIENT_LIBRARY_RTDE_WRITER_H_INCLUDED
#define UR_CLIENT_LIBRARY_RTDE_WRITER_H_INCLUDED
#include "ur_client_library/rtde/package_header.h"
#include "ur_client_library/rtde/rtde_package.h"
#include "ur_client_library/rtde/data_package.h"
#include "ur_client_library/comm/stream.h"
#include "ur_client_library/queue/readerwriterqueue.h"
#include "ur_client_library/ur/datatypes.h"
#include <thread>
#include <mutex>
namespace urcl
{
namespace rtde_interface
{
/*!
* \brief The RTDEWriter class offers an abstraction layer to send data to the robot via the RTDE
* interface. Several simple to use functions to create data packages to send exist, which are
* then sent to the robot in an additional thread.
*/
class RTDEWriter
{
public:
RTDEWriter() = delete;
/*!
* \brief Creates a new RTDEWriter object using a given URStream and recipe.
*
* \param stream The URStream to use for communication with the robot
* \param recipe The recipe to use for communication
*/
RTDEWriter(comm::URStream<RTDEPackage>* stream, const std::vector<std::string>& recipe);
~RTDEWriter()
{
running_ = false;
if (writer_thread_.joinable())
{
writer_thread_.join();
}
}
/*!
* \brief Sets a new input recipe. This can be used to change the input recipe on the fly, if
* needed.
*
* \param recipe The new recipe to use
*/
void setInputRecipe(const std::vector<std::string>& recipe);
/*!
* \brief Starts the writer thread, which periodically clears the queue to write packages to the
* robot.
*
* \param recipe_id The recipe id to use, so the robot correctly identifies the used recipe
*/
void init(uint8_t recipe_id);
/*!
* \brief The writer thread loop, continually serializing and sending packages to the robot.
*/
void run();
/*!
* \brief Creates a package to request setting a new value for the speed slider.
*
* \param speed_slider_fraction The new speed slider fraction as a value between 0.0 and 1.0
*
* \returns Success of the package creation
*/
bool sendSpeedSlider(double speed_slider_fraction);
/*!
* \brief Creates a package to request setting a new value for one of the standard digital output pins.
*
* \param output_pin The pin to change
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendStandardDigitalOutput(uint8_t output_pin, bool value);
/*!
* \brief Creates a package to request setting a new value for one of the configurable digital output pins.
*
* \param output_pin The pin to change
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendConfigurableDigitalOutput(uint8_t output_pin, bool value);
/*!
* \brief Creates a package to request setting a new value for one of the tool output pins.
*
* \param output_pin The pin to change
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendToolDigitalOutput(uint8_t output_pin, bool value);
/*!
* \brief Creates a package to request setting a new value for one of the standard analog output pins.
*
* \param output_pin The pin to change
* \param value The new value, it should be between 0 and 1, where 0 is 4mA and 1 is 20mA.
* \param type The domain for the output can be eitherAnalogOutputType::CURRENT or AnalogOutputType::VOLTAGE or
* AnalogOutputType::SET_ON_TEACH_PENDANT. In the latter case the domain is left untouched and the domain configured
* on the teach pendant will be used.
*
* \returns Success of the package creation
*/
bool sendStandardAnalogOutput(uint8_t output_pin, double value,
const AnalogOutputType type = AnalogOutputType::SET_ON_TEACH_PENDANT);
/*!
* \brief Creates a package to request setting a new value for an input_bit_register
*
* \param register_id The id of the register that should be changed [64..127]
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendInputBitRegister(uint32_t register_id, bool value);
/*!
* \brief Creates a package to request setting a new value for an input_int_register
*
* \param register_id The id of the register that should be changed [24..47]
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendInputIntRegister(uint32_t register_id, int32_t value);
/*!
* \brief Creates a package to request setting a new value for an input_double_register
*
* \param register_id The id of the register that should be changed [24..47]
* \param value The new value
*
* \returns Success of the package creation
*/
bool sendInputDoubleRegister(uint32_t register_id, double value);
private:
uint8_t pinToMask(uint8_t pin);
comm::URStream<RTDEPackage>* stream_;
std::vector<std::string> recipe_;
uint8_t recipe_id_ = 0;
moodycamel::BlockingReaderWriterQueue<std::unique_ptr<DataPackage>> queue_;
std::thread writer_thread_;
bool running_;
DataPackage package_;
std::mutex package_mutex_;
};
} // namespace rtde_interface
} // namespace urcl
#endif // UR_CLIENT_LIBRARY_RTDE_WRITER_H_INCLUDED