YARP
Yet Another Robot Platform
SubDevice.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_SUBDEVICE_H
10 #define YARP_DEV_CONTROLBOARDWRAPPER_SUBDEVICE_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 #include <yarp/os/BufferedPort.h>
18 #include <yarp/os/Network.h>
19 #include <yarp/os/PortablePair.h>
20 #include <yarp/os/Semaphore.h>
21 #include <yarp/os/Stamp.h>
22 #include <yarp/os/Time.h>
23 #include <yarp/os/Vocab.h>
24 
25 #include <yarp/sig/Vector.h>
26 
30 #include <yarp/dev/PolyDriver.h>
31 
32 #include "RPCMessagesParser.h"
34 #include <string>
35 #include <vector>
36 
37 #ifdef MSVC
38 # pragma warning(disable : 4355)
39 #endif
40 
41 /*
42  * To optimize memory allocation, for group of joints we can have one mem reserver for rpc port
43  * and on e for streaming. The size could be numOfSubDevices*maxNumOfjointForSubdevice.
44  * (we could also use the actual joint number for each subdevice using a for loop). TODO
45  */
46 
48 
49 /*
50 * An Helper class for the controlBoardWrapper
51 * It maps only a subpart of the underlying device.
52 */
53 
54 class SubDevice
55 {
56 public:
57  std::string id;
58  size_t base {static_cast<size_t>(-1)};
59  size_t top {static_cast<size_t>(-1)};
60  size_t wbase; //wrapper base
61  size_t wtop; //wrapper top
62  size_t axes {0}; //number of used axis of this subdevice
63  size_t totalAxis; //Numeber of total axis that the subdevice can control
64 
65  bool configuredF {false};
66 
68 
89 
94 
95  SubDevice() = default;
96  ;
97 
98  bool attach(yarp::dev::PolyDriver* d, const std::string& id);
99  void detach();
100 
101  bool configure(size_t wbase, size_t wtop, size_t base, size_t top, size_t axes, const std::string& id, ControlBoardWrapper* _parent);
102 
103  bool isAttached()
104  {
105  return attachedF;
106  }
107 
108 private:
109  bool attachedF {false};
110 };
111 
112 typedef std::vector<SubDevice> SubDeviceVector;
113 
115 {
116  size_t offset; //an offset, the device is mapped starting from this joint
117  size_t deviceEntry; //index to the joint corresponding subdevice in the list
118  size_t jointIndexInDev; //the index of joint in the numeration inside the device
119 };
120 
121 
123 {
124 public:
126  std::vector<DevicesLutEntry> lut;
128 
129  inline SubDevice* getSubdevice(size_t i)
130  {
131  if (i >= subdevices.size()) {
132  return nullptr;
133  }
134 
135  return &subdevices[i];
136  }
137 };
138 
139 #endif // YARP_DEV_CONTROLBOARDWRAPPER_SUBDEVICE_H
SubDevice::iMotEnc
yarp::dev::IMotorEncoders * iMotEnc
Definition: SubDevice.h:74
SubDevice::vel
yarp::dev::IVelocityControl * vel
Definition: SubDevice.h:72
SubDevice::iVar
yarp::dev::IRemoteVariables * iVar
Definition: SubDevice.h:86
yarp::dev::IRemoteVariables
IRemoteVariables interface.
Definition: IRemoteVariables.h:51
Network.h
WrappedDevice
Definition: SubDevice.h:123
Vector.h
contains the definition of a Vector type
yarp::dev::IImpedanceControl
Interface for control boards implementing impedance control.
Definition: IImpedanceControl.h:75
DevicesLutEntry::deviceEntry
size_t deviceEntry
Definition: SubDevice.h:117
IPreciselyTimed.h
SubDevice::info
yarp::dev::IAxisInfo * info
Definition: SubDevice.h:82
SubDevice::iMode
yarp::dev::IControlMode * iMode
Definition: SubDevice.h:81
SubDevice::pos
yarp::dev::IPositionControl * pos
Definition: SubDevice.h:71
ControlBoardInterfaces.h
define control board standard interfaces
SubDevice::iPWM
yarp::dev::IPWMControl * iPWM
Definition: SubDevice.h:87
SubDevice::subDev_motor_encoders
yarp::sig::Vector subDev_motor_encoders
Definition: SubDevice.h:92
SubDevice::top
size_t top
Definition: SubDevice.h:59
PortablePair.h
SubDeviceVector
std::vector< SubDevice > SubDeviceVector
Definition: SubDevice.h:112
SubDevice::iCurr
yarp::dev::ICurrentControl * iCurr
Definition: SubDevice.h:88
SubDevice::SubDevice
SubDevice()=default
yarp::sig::VectorOf< double >
yarp::dev::IInteractionMode
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
Definition: IInteractionMode.h:43
ControlBoardWrapper
controlboardwrapper2: An updated version of the controlBoard network wrapper.
Definition: ControlBoardWrapper.h:204
yarp::dev::IControlMode
Interface for setting control mode in control board.
Definition: IControlMode.h:28
SubDevice::calib
yarp::dev::IControlCalibration * calib
Definition: SubDevice.h:77
DevicesLutEntry
Definition: SubDevice.h:115
yarp::dev::IControlCalibration
Interface for control devices, calibration commands.
Definition: IControlCalibration.h:85
yarp::dev::IAxisInfo
Interface for getting information about specific axes, if available.
Definition: IAxisInfo.h:43
PolyDriver.h
Stamp.h
SubDevice::id
std::string id
Definition: SubDevice.h:57
yarp::dev::IControlLimits
Interface for control devices, commands to get/set position and veloity limits.
Definition: IControlLimits.h:33
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
SubDevice::subdevice
yarp::dev::PolyDriver * subdevice
Definition: SubDevice.h:69
DevicesLutEntry::offset
size_t offset
Definition: SubDevice.h:116
WrappedDevice::getSubdevice
SubDevice * getSubdevice(size_t i)
Definition: SubDevice.h:129
SubDevice::subDev_joint_encoders
yarp::sig::Vector subDev_joint_encoders
Definition: SubDevice.h:90
WrappedDevice::subdevices
SubDeviceVector subdevices
Definition: SubDevice.h:125
SubDevice::posDir
yarp::dev::IPositionDirect * posDir
Definition: SubDevice.h:83
SubDevice::attach
bool attach(yarp::dev::PolyDriver *d, const std::string &id)
Definition: SubDevice.cpp:87
SubDevice::lim
yarp::dev::IControlLimits * lim
Definition: SubDevice.h:76
SubDevice::isAttached
bool isAttached()
Definition: SubDevice.h:103
DevicesLutEntry::jointIndexInDev
size_t jointIndexInDev
Definition: SubDevice.h:118
SubDevice::iTimed
yarp::dev::IPreciselyTimed * iTimed
Definition: SubDevice.h:78
yarp::dev::IPWMControl
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition: IPWMControl.h:28
SubDevice::wtop
size_t wtop
Definition: SubDevice.h:61
Semaphore.h
BufferedPort.h
SubDevice::motorEncodersTimes
yarp::sig::Vector motorEncodersTimes
Definition: SubDevice.h:93
yarp::dev::IMotorEncoders
Control board, encoder interface.
Definition: IMotorEncoders.h:155
yarp::dev::IAmplifierControl
Interface for control devices, amplifier commands.
Definition: IAmplifierControl.h:33
SubDevice::iTorque
yarp::dev::ITorqueControl * iTorque
Definition: SubDevice.h:79
yarp::dev::IMotor
Control board, encoder interface.
Definition: IMotor.h:99
yarp::dev::IVelocityControl
Interface for control boards implementing velocity control.
Definition: IVelocityControl.h:160
yarp::dev::ICurrentControl
Interface for control boards implementing current control.
Definition: ICurrentControl.h:28
SubDevice::parent
ControlBoardWrapper * parent
Definition: SubDevice.h:67
yarp::dev::IPidControl
Interface for a generic control board device implementing a PID controller, with scaled arguments.
Definition: IPidControl.h:211
SubDevice::jointEncodersTimes
yarp::sig::Vector jointEncodersTimes
Definition: SubDevice.h:91
yarp::dev::IPositionDirect
Interface for a generic control board device implementing position control.
Definition: IPositionDirect.h:32
yarp::dev::IEncodersTimed
Control board, extend encoder interface with timestamps.
Definition: IEncodersTimed.h:59
SubDevice::base
size_t base
Definition: SubDevice.h:58
WrappedDevice::lut
std::vector< DevicesLutEntry > lut
Definition: SubDevice.h:126
SubDevice::detach
void detach()
Definition: SubDevice.cpp:63
SubDevice::totalAxis
size_t totalAxis
Definition: SubDevice.h:63
Vocab.h
ControlBoardInterfacesImpl.h
SubDevice::iInteract
yarp::dev::IInteractionMode * iInteract
Definition: SubDevice.h:84
SubDevice::iImpedance
yarp::dev::IImpedanceControl * iImpedance
Definition: SubDevice.h:80
Time.h
yarp::dev::ITorqueControl
Interface for control boards implementing torque control.
Definition: ITorqueControl.h:39
RPCMessagesParser.h
SubDevice::wbase
size_t wbase
Definition: SubDevice.h:60
SubDevice
Definition: SubDevice.h:55
WrappedDevice::maxNumOfJointsInDevices
size_t maxNumOfJointsInDevices
Definition: SubDevice.h:127
SubDevice::pid
yarp::dev::IPidControl * pid
Definition: SubDevice.h:70
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
yarp::dev::IPositionControl
Interface for a generic control board device implementing position control.
Definition: IPositionControl.h:257
SubDevice::iJntEnc
yarp::dev::IEncodersTimed * iJntEnc
Definition: SubDevice.h:73
SubDevice::axes
size_t axes
Definition: SubDevice.h:62
SubDevice::amp
yarp::dev::IAmplifierControl * amp
Definition: SubDevice.h:75
SubDevice::configure
bool configure(size_t wbase, size_t wtop, size_t base, size_t top, size_t axes, const std::string &id, ControlBoardWrapper *_parent)
Definition: SubDevice.cpp:27
StreamingMessagesParser.h
SubDevice::imotor
yarp::dev::IMotor * imotor
Definition: SubDevice.h:85
SubDevice::configuredF
bool configuredF
Definition: SubDevice.h:65