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