YARP
Yet Another Robot Platform
RPCMessagesParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 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_RPCMESSAGESPARSER_H
10 #define YARP_DEV_CONTROLBOARDWRAPPER_RPCMESSAGESPARSER_H
11 
12 
13 // This file contains helper functions for the ControlBoardWrapper
14 
15 #include <yarp/os/PortablePair.h>
16 #include <yarp/os/BufferedPort.h>
17 #include <yarp/os/Time.h>
18 #include <yarp/os/Network.h>
19 #include <yarp/os/Stamp.h>
20 #include <yarp/os/Vocab.h>
21 
23 #include <yarp/dev/PolyDriver.h>
26 #include <yarp/sig/Vector.h>
27 #include <yarp/dev/Wrapper.h>
28 
29 #include <mutex>
30 #include <string>
31 #include <vector>
32 
33 
34 #ifdef MSVC
35  #pragma warning(disable:4355)
36 #endif
37 
38 /*
39  * To optimize memory allocation, for group of joints we can have one mem reserver for rpc port
40  * and on e for streaming. The size could be numOfSubDevices*maxNumOfjointForSubdevice.
41  * (we could also use the actual joint number for each subdevice using a for loop). TODO
42  */
43 
44 /* Using yarp::dev::impl namespace for all helper class inside yarp::dev to reduce
45  * name conflicts
46  */
47 
48 namespace yarp {
49  namespace dev {
50  class ControlBoardWrapper;
51  namespace impl {
52  class RPCMessagesParser;
53  class SubDevice;
54  class WrappedDevice;
55  }
56  }
57 }
58 
59 
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 
62 
63 
64 /* the control command message type
65 * head is a Bottle which contains the specification of the message type
66 * body is a Vector which move the robot accordingly
67 */
69 
70 
74 class yarp::dev::impl::RPCMessagesParser : public yarp::dev::DeviceResponder
75 {
76 protected:
77  yarp::dev::ControlBoardWrapper *ControlBoardWrapper_p;
78  yarp::dev::IPidControl *rpc_IPid;
79  yarp::dev::IPositionControl *rpc_IPosCtrl;
80  yarp::dev::IPositionDirect *rpc_IPosDirect;
81  yarp::dev::IVelocityControl *rpc_IVelCtrl;
82  yarp::dev::IEncodersTimed *rpc_IEncTimed;
83  yarp::dev::IMotorEncoders *rpc_IMotEnc;
85  yarp::dev::IControlLimits *rcp_Ilim;
86  yarp::dev::ITorqueControl *rpc_ITorque;
87  yarp::dev::IControlMode *rpc_iCtrlMode;
88  yarp::dev::IAxisInfo *rpc_AxisInfo;
89  yarp::dev::IRemoteCalibrator *rpc_IRemoteCalibrator;
91  yarp::dev::IImpedanceControl *rpc_IImpedance;
92  yarp::dev::IInteractionMode *rpc_IInteract;
93  yarp::dev::IMotor *rpc_IMotor;
95  yarp::dev::ICurrentControl *rpc_ICurrent;
96  yarp::dev::IPWMControl *rpc_IPWM;
97  yarp::sig::Vector tmpVect;
98  yarp::os::Stamp lastRpcStamp;
99  std::mutex mutex;
100  int controlledJoints;
101 
102 public:
106  RPCMessagesParser();
107 
114  void init(yarp::dev::ControlBoardWrapper *x);
115 
116  bool respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& response) override;
117 
118  void handleTorqueMsg(const yarp::os::Bottle& cmd,
119  yarp::os::Bottle& response, bool *rec, bool *ok);
120 
121  void handleControlModeMsg(const yarp::os::Bottle& cmd,
122  yarp::os::Bottle& response, bool *rec, bool *ok);
123 
124  void handleImpedanceMsg(const yarp::os::Bottle& cmd,
125  yarp::os::Bottle& response, bool *rec, bool *ok);
126 
127  void handleInteractionModeMsg(const yarp::os::Bottle& cmd,
128  yarp::os::Bottle& response, bool *rec, bool *ok);
129 
130  void handleProtocolVersionRequest(const yarp::os::Bottle& cmd,
131  yarp::os::Bottle& response, bool *rec, bool *ok);
132 
133  void handleRemoteCalibratorMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool *rec, bool *ok);
134 
135  void handleRemoteVariablesMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool *rec, bool *ok);
136 
137  void handleCurrentMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool *rec, bool *ok);
138 
139  void handlePWMMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool *rec, bool *ok);
140 
141  void handlePidMsg(const yarp::os::Bottle& cmd, yarp::os::Bottle& response, bool *rec, bool *ok);
142 
147  virtual bool initialize();
148 };
149 
150 
151 
152 
153 #endif // DOXYGEN_SHOULD_SKIP_THIS
154 
155 #endif // YARP_DEV_CONTROLBOARDWRAPPER_RPCMESSAGESPARSER_H
Interface for control boards implementing current control.
Interface for control devices, calibration commands.
define the interface for an attachable object
Control board, encoder interface.
Interface for controlling an axis, by sending directly a PWM reference signal to a motor...
Definition: IPWMControl.h:27
Interface for control boards implementing torque control.
Interface for a generic control board device implementing position control.
Provides:
Definition: Vector.h:32
The main, catch-all namespace for YARP.
Definition: numeric.h:47
Interface for setting control mode in control board.
Definition: IControlMode.h:27
Interface for a generic control board device implementing a PID controller, with scaled arguments...
Definition: IPidControl.h:210
Control board, extend encoder interface with timestamps.
Interface for a generic control board device implementing position control.
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:42
virtual bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply)
Respond to a message.
Interface for control boards implementing impedance control.
IRemoteCalibrator interface is meant to remotize the access of the calibration device in order to all...
Group a pair of objects to be sent and received together.
Definition: PortablePair.h:50
A cheap and cheerful framework for human readable/writable forms of messages to devices.
Definition: DeviceDriver.h:132
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:72
Control board, encoder interface.
Definition: IMotor.h:98
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
define control board standard interfaces
contains the definition of a Vector type
Interface for control devices, amplifier commands.
Interface for control boards implementing velocity control.
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:24
Interface for control devices, commands to get/set position and veloity limits.
IRemoteVariables interface.