YARP
Yet Another Robot Platform
ControlBoardWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPER_H
10 #define YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPER_H
11 
12 
13 // ControlBoardWrapper
14 // A modified version of the remote control board class
15 // which remaps joints, it can also merge networks into a single part.
16 
17 
18 #include <yarp/dev/DeviceDriver.h>
20 
21 #include <yarp/os/BufferedPort.h>
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/Stamp.h>
24 #include <yarp/sig/Vector.h>
26 
27 #include <yarp/dev/impl/jointData.h> // struct for YARP extended port
28 
29 #include <mutex>
30 #include <string>
31 #include <vector>
32 
33 // ROS state publisher
34 #include <yarp/os/Node.h>
35 #include <yarp/os/Publisher.h>
38 
39 
60 
61 #include "SubDevice.h"
63 #include "RPCMessagesParser.h"
64 
65 
66 #ifdef MSVC
67  #pragma warning(disable:4355)
68 #endif
69 
70 /*
71  * To optimize memory allocation, for group of joints we can have one mem reserver for rpc port
72  * and on e for streaming. The size could be numOfSubDevices*maxNumOfjointForSubdevice.
73  * (we could also use the actual joint number for each subdevice using a for loop). TODO
74  */
75 
76 class CommandsHelper;
77 class SubDevice;
78 
79 
183  virtual public ControlBoardWrapperCommon,
204 {
205 private:
206  std::string rootName;
207 
208  bool checkPortName(yarp::os::Searchable &params);
209 
211 
212  yarp::os::BufferedPort<yarp::sig::Vector> outputPositionStatePort; // Port /state:o streaming out the encoder positions
213  yarp::os::BufferedPort<CommandMessage> inputStreamingPort; // Input streaming port for high frequency commands
214  yarp::os::Port inputRPCPort; // Input RPC port for set/get remote calls
215  yarp::sig::Vector times; // time for each joint
216 
217  // Buffer associated to the extendedOutputStatePort port; in this case we will use the type generated
218  // from the YARP .thrift file
220  yarp::os::Port extendedOutputStatePort; // Port /stateExt:o streaming out the struct with the robot data
221 
222  // ROS state publisher
223  ROSTopicUsageType useROS {ROS_disabled}; // decide if open ROS topic or not
224  std::vector<std::string> jointNames; // name of the joints
225  std::string rosNodeName; // name of the rosNode
226  std::string rosTopicName; // name of the rosTopic
227  yarp::os::Node *rosNode {nullptr}; // add a ROS node
228  yarp::os::NetUint32 rosMsgCounter {0}; // incremental counter in the ROS message
229  yarp::os::PortWriterBuffer<yarp::rosmsg::sensor_msgs::JointState> rosOutputState_buffer; // Buffer associated to the ROS topic
230  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::JointState> rosPublisherPort; // Dedicated ROS topic publisher
231 
232  yarp::os::PortReaderBuffer<yarp::os::Bottle> inputRPC_buffer; // Buffer associated to the inputRPCPort port
233  RPCMessagesParser RPC_parser; // Message parser associated to the inputRPCPort port
234  StreamingMessagesParser streaming_parser; // Message parser associated to the inputStreamingPort port
235 
236  static constexpr double default_period = 0.02; // s
237  double period {default_period};
238 
239  yarp::os::Bottle getOptions();
240  bool updateAxisName();
241  bool checkROSParams(yarp::os::Searchable &config);
242  bool initialize_ROS();
243  bool initialize_YARP(yarp::os::Searchable &prop);
244  void cleanup_yarpPorts();
245 
246  // Default usage
247  // Open the wrapper only, the attach method needs to be called before using it
248  bool openDeferredAttach(yarp::os::Property& prop);
249 
250  // For the simulator, if a subdevice parameter is given to the wrapper, it will
251  // open it and attach to it immediately.
252  yarp::dev::PolyDriver *subDeviceOwned {nullptr};
253  bool openAndAttachSubDevice(yarp::os::Property& prop);
254 
255  bool ownDevices;
256 
257  void calculateMaxNumOfJointsInDevices();
258 
259 public:
266 
267 
268  /* Return id of this device */
269  std::string getId()
270  {
271  return partName;
272  }
273 
278  bool close() override;
279 
280 
290  bool open(yarp::os::Searchable& prop) override;
291 
292  bool detachAll() override;
293 
294  bool attachAll(const yarp::dev::PolyDriverList &l) override;
295 
299  void run() override;
300 };
301 
302 
303 #endif // YARP_DEV_CONTROLBOARDWRAPPER_CONTROLBOARDWRAPPER_H
SubDevice.h
ControlBoardWrapperVelocityControl.h
ControlBoardWrapper::operator=
ControlBoardWrapper & operator=(ControlBoardWrapper &&)=delete
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
ControlBoardWrapperPidControl
Definition: ControlBoardWrapperPidControl.h:19
ControlBoardWrapperControlCalibration
Definition: ControlBoardWrapperControlCalibration.h:19
JointState.h
ControlBoardWrapper::operator=
ControlBoardWrapper & operator=(const ControlBoardWrapper &)=delete
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
ControlBoardWrapperInteractionMode
Definition: ControlBoardWrapperInteractionMode.h:20
ControlBoardWrapperTorqueControl
Definition: ControlBoardWrapperTorqueControl.h:19
Vector.h
contains the definition of a Vector type
ControlBoardWrapperImpedanceControl
Definition: ControlBoardWrapperImpedanceControl.h:19
ControlBoardWrapperAxisInfo
Definition: ControlBoardWrapperAxisInfo.h:19
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
ControlBoardWrapperCurrentControl
Definition: ControlBoardWrapperCurrentControl.h:19
ControlBoardWrapperAmplifierControl.h
ControlBoardWrapperMotorEncoders.h
ControlBoardHelpers.h
yarp::os::PortReaderBuffer< yarp::os::Bottle >
yarp::os::PortWriterBuffer< yarp::dev::impl::jointData >
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::JointState >
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
ControlBoardWrapper::close
bool close() override
Close the device driver by deallocating all resources and closing ports.
Definition: ControlBoardWrapper.cpp:62
ControlBoardWrapperMotorEncoders
Definition: ControlBoardWrapperMotorEncoders.h:19
ControlBoardWrapperRemoteCalibrator.h
ControlBoardWrapper::run
void run() override
The thread main loop deals with writing on ports here.
Definition: ControlBoardWrapper.cpp:777
ControlBoardWrapperMotor.h
yarpRosHelper.h
ControlBoardWrapperControlLimits
Definition: ControlBoardWrapperControlLimits.h:19
ControlBoardWrapperMotor
Definition: ControlBoardWrapperMotor.h:19
ControlBoardWrapperRemoteCalibrator
Definition: ControlBoardWrapperRemoteCalibrator.h:20
ControlBoardWrapper::getId
std::string getId()
Definition: ControlBoardWrapper.h:269
yarp::sig::VectorOf< double >
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort< yarp::sig::Vector >
ControlBoardWrapper
controlboardwrapper2: An updated version of the controlBoard network wrapper.
Definition: ControlBoardWrapper.h:204
ControlBoardWrapperPositionControl.h
ControlBoardWrapper::ControlBoardWrapper
ControlBoardWrapper(const ControlBoardWrapper &)=delete
ControlBoardWrapperCurrentControl.h
ROSTopicUsageType
ROSTopicUsageType
Definition: yarpRosHelper.h:19
ControlBoardWrapperCommon::partName
std::string partName
Definition: ControlBoardWrapperCommon.h:24
yarp::os::NetUint32
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
ControlBoardWrapperAxisInfo.h
ControlBoardWrapperRemoteVariables
Definition: ControlBoardWrapperRemoteVariables.h:20
Stamp.h
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
ROS_disabled
@ ROS_disabled
Definition: yarpRosHelper.h:21
ControlBoardWrapperPWMControl.h
Node.h
StreamingMessagesParser
Callback implementation after buffered input.
Definition: StreamingMessagesParser.h:55
ControlBoardWrapperAmplifierControl
Definition: ControlBoardWrapperAmplifierControl.h:19
ControlBoardWrapper::~ControlBoardWrapper
~ControlBoardWrapper() override
ControlBoardWrapperControlMode.h
yarp::os::Node
The Node class.
Definition: Node.h:27
ControlBoardWrapperEncodersTimed
Definition: ControlBoardWrapperEncodersTimed.h:19
ControlBoardWrapperControlCalibration.h
ControlBoardWrapperPreciselyTimed.h
ControlBoardWrapperCommon
Definition: ControlBoardWrapperCommon.h:19
ControlBoardWrapperTorqueControl.h
BufferedPort.h
IMultipleWrapper.h
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
ControlBoardWrapper::ControlBoardWrapper
ControlBoardWrapper()
Definition: ControlBoardWrapper.cpp:33
ControlBoardWrapperPreciselyTimed
Definition: ControlBoardWrapperPreciselyTimed.h:20
ControlBoardWrapperControlLimits.h
ControlBoardWrapper::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: ControlBoardWrapper.cpp:753
ControlBoardWrapper::attachAll
bool attachAll(const yarp::dev::PolyDriverList &l) override
Attach to a list of objects.
Definition: ControlBoardWrapper.cpp:694
ControlBoardWrapperEncodersTimed.h
PeriodicThread.h
ControlBoardWrapperPositionControl
Definition: ControlBoardWrapperPositionControl.h:20
RPCMessagesParser
Helper object for parsing RPC port messages.
Definition: RPCMessagesParser.h:58
jointData.h
ControlBoardWrapper::ControlBoardWrapper
ControlBoardWrapper(ControlBoardWrapper &&)=delete
ControlBoardWrapperInteractionMode.h
Publisher.h
yarp::dev::IMultipleWrapper
Interface for an object that can wrap/attach to to another.
Definition: IMultipleWrapper.h:30
ControlBoardWrapperPidControl.h
yarp::rosmsg::sensor_msgs::JointState
Definition: JointState.h:56
ControlBoardWrapperPWMControl
Definition: ControlBoardWrapperPWMControl.h:20
ControlBoardWrapperRemoteVariables.h
ControlBoardWrapperPositionDirect
Definition: ControlBoardWrapperPositionDirect.h:20
ControlBoardWrapperControlMode
Definition: ControlBoardWrapperControlMode.h:19
RPCMessagesParser.h
SubDevice
Definition: SubDevice.h:55
ControlBoardWrapperImpedanceControl.h
ControlBoardWrapper::open
bool open(yarp::os::Searchable &prop) override
Open the device driver.
Definition: ControlBoardWrapper.cpp:338
ControlBoardWrapperPositionDirect.h
ControlBoardWrapperVelocityControl
Definition: ControlBoardWrapperVelocityControl.h:20
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
StreamingMessagesParser.h
DeviceDriver.h