YARP
Yet Another Robot Platform
RPCMessagesParser.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_DEV_CONTROLBOARDWRAPPER_RPCMESSAGESPARSER_H
7 #define YARP_DEV_CONTROLBOARDWRAPPER_RPCMESSAGESPARSER_H
8 
9 
10 // This file contains helper functions for the ControlBoardWrapper
11 
12 #include <yarp/os/BufferedPort.h>
13 #include <yarp/os/Network.h>
14 #include <yarp/os/PortablePair.h>
15 #include <yarp/os/Stamp.h>
16 #include <yarp/os/Time.h>
17 #include <yarp/os/Vocab.h>
18 
19 #include <yarp/sig/Vector.h>
20 
24 #include <yarp/dev/PolyDriver.h>
25 
26 #include <mutex>
27 #include <string>
28 #include <vector>
29 
30 
31 #ifdef MSVC
32 # pragma warning(disable : 4355)
33 #endif
34 
35 /*
36  * To optimize memory allocation, for group of joints we can have one mem reserver for rpc port
37  * and on e for streaming. The size could be numOfSubDevices*maxNumOfjointForSubdevice.
38  * (we could also use the actual joint number for each subdevice using a for loop). TODO
39  */
40 
42 
43 /* the control command message type
44 * head is a Bottle which contains the specification of the message type
45 * body is a Vector which move the robot accordingly
46 */
48 
49 
55 {
56 protected:
78  std::mutex mutex;
79  size_t controlledJoints {0};
80 
81 public:
85  RPCMessagesParser() = default;
86 
94  void reset();
95 
96  bool respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& response) override;
97 
98  void handleTorqueMsg(const yarp::os::Bottle& cmd,
99  yarp::os::Bottle& response,
100  bool* rec,
101  bool* ok);
102 
103  void handleControlModeMsg(const yarp::os::Bottle& cmd,
104  yarp::os::Bottle& response,
105  bool* rec,
106  bool* ok);
107 
108  void handleImpedanceMsg(const yarp::os::Bottle& cmd,
109  yarp::os::Bottle& response,
110  bool* rec,
111  bool* ok);
112 
114  yarp::os::Bottle& response,
115  bool* rec,
116  bool* ok);
117 
119  yarp::os::Bottle& response,
120  bool* rec,
121  bool* ok);
122 
123  void handleRemoteCalibratorMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok);
124 
125  void handleRemoteVariablesMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok);
126 
127  void handleCurrentMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok);
128 
129  void handlePWMMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok);
130 
131  void handlePidMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool* rec, bool* ok);
132 
137  virtual bool initialize();
138 };
139 
140 #endif // YARP_DEV_CONTROLBOARDWRAPPER_RPCMESSAGESPARSER_H
define control board standard interfaces
yarp::os::PortablePair< yarp::os::Bottle, yarp::sig::Vector > CommandMessage
contains the definition of a Vector type
Helper object for parsing RPC port messages.
void handleRemoteCalibratorMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IControlCalibration * rpc_Icalib
yarp::dev::IEncodersTimed * rpc_IEncTimed
yarp::dev::IControlMode * rpc_iCtrlMode
yarp::dev::IRemoteCalibrator * rpc_IRemoteCalibrator
yarp::dev::IAxisInfo * rpc_AxisInfo
yarp::dev::ITorqueControl * rpc_ITorque
yarp::dev::IPidControl * rpc_IPid
void handleProtocolVersionRequest(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handlePWMMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IRemoteVariables * rpc_IVar
yarp::dev::IImpedanceControl * rpc_IImpedance
void handleCurrentMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleInteractionModeMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleControlModeMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void init(yarp::dev::DeviceDriver *x)
Initialization.
yarp::dev::IPositionDirect * rpc_IPosDirect
yarp::dev::ICurrentControl * rpc_ICurrent
void handleTorqueMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
yarp::dev::IMotorEncoders * rpc_IMotEnc
yarp::dev::IInteractionMode * rpc_IInteract
void handlePidMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
virtual bool initialize()
Initialize the internal data.
yarp::dev::IPositionControl * rpc_IPosCtrl
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
yarp::sig::Vector tmpVect
yarp::dev::IVelocityControl * rpc_IVelCtrl
yarp::dev::IPWMControl * rpc_IPWM
yarp::dev::IAmplifierControl * rcp_IAmp
yarp::dev::IMotor * rpc_IMotor
yarp::dev::IControlLimits * rcp_Ilim
yarp::os::Stamp lastRpcStamp
void handleImpedanceMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
void handleRemoteVariablesMsg(const yarp::os::Bottle &cmd, yarp::os::Bottle &response, bool *rec, bool *ok)
RPCMessagesParser()=default
Constructor.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
A cheap and cheerful framework for human readable/writable forms of messages to devices.
Definition: DeviceDriver.h:131
Interface for control devices, amplifier commands.
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:40
Interface for control devices, calibration commands.
Interface for control devices, commands to get/set position and veloity limits.
Interface for setting control mode in control board.
Definition: IControlMode.h:25
Interface for control boards implementing current control.
Control board, extend encoder interface with timestamps.
Interface for control boards implementing impedance control.
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
Control board, encoder interface.
Control board, encoder interface.
Definition: IMotor.h:96
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition: IPWMControl.h:25
Interface for a generic control board device implementing a PID controller, with scaled arguments.
Definition: IPidControl.h:208
Interface for a generic control board device implementing position control.
Interface for a generic control board device implementing position control.
IRemoteCalibrator interface is meant to remotize the access of the calibration device in order to all...
IRemoteVariables interface.
Interface for control boards implementing torque control.
Interface for control boards implementing velocity control.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:48
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22