YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
robotDriver.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <cmath>
7
8#include <yarp/os/Network.h>
9#include <yarp/os/Time.h>
10#include <yarp/os/Log.h>
11#include <yarp/os/LogStream.h>
13#include <yarp/sig/Vector.h>
14
16#include <yarp/dev/PolyDriver.h>
18#include <yarp/os/Thread.h>
19
20using namespace std;
21using namespace yarp::os;
22using namespace yarp::sig;
23using namespace yarp::dev;
24
25#include "robotDriver.h"
26
27// ******************** ROBOT DRIVER CLASS
29{
30 drvOptions_ll.clear();
31}
32
34{
35 bool ret=true;
36 Property &options=const_cast<Property &> (copt);
37
38 drvOptions_ll.put("device","remotecontrolboardremapper");
39
40 yDebug() << "remoteControlBoards will use the following configuration:";
41 yDebug() << "set of joints:" << options.find("axesNames").toString();
42 yDebug() << "set of controlboards:" << options.find("remoteControlBoards").toString();
43 drvOptions_ll.put("axesNames", options.find("axesNames"));
44 drvOptions_ll.put("remoteControlBoards",options.find("remoteControlBoards"));
45 drvOptions_ll.put("localPortPrefix", options.find("localPortPrefix"));
46
47 yarp::os::Property& pcb =drvOptions_ll.addGroup("REMOTE_CONTROLBOARD_OPTIONS");
48 pcb.put("carrier", "fast_tcp");
49
50 if (m_verbose)
51 {
52 yDebug() << "driver options:\n" << drvOptions_ll.toString().c_str();
53 }
54
55 return ret;
56}
57
59{
60 for (size_t i=0; i<n_joints; i++)
61 m_trajectoryTime[i] = t;
62 return true;
63}
64
65bool robotDriver::setTrajectoryTime(int j, double t)
66{
67 m_trajectoryTime[j] = t;
68 return true;
69}
70
72{
73 drv_ll.open(drvOptions_ll);
74 bool ok = true;
75
76 if (drv_ll.isValid())
77 {
78 ok = drv_ll.view(ipos_ll) && drv_ll.view(iposdir_ll) && drv_ll.view(ienc_ll) &&
79 drv_ll.view(ipid_ll) && drv_ll.view(imotenc_ll) && drv_ll.view(icmd_ll);
80 }
81 else
82 {
83 ok = false;
84 }
85
86 if (!ok)
87 {
88 return false;
89 }
90
91 //get the number of the joints
92 ok &= ienc_ll->getAxes(&n_joints);
93
94 //set the initial reference speeds
95 m_trajectoryTime.resize(n_joints,4.0);
96 std::vector<double> speeds;
97 for (int i = 0; i < n_joints; i++)
98 {
99 speeds.push_back(20.0);
100 }
101 ok &= ipos_ll->setRefSpeeds(speeds.data());
102
103 return ok;
104}
105
109
110bool robotDriver::setControlMode(const int j, const int mode)
111{
112 if (!icmd_ll) return false;
113 return icmd_ll->setControlMode(j, mode);
114}
115
116bool robotDriver::setPosition(int j, double ref)
117{
118 if (!iposdir_ll) return false;
119 return iposdir_ll->setPosition(j, ref);
120}
121
122bool robotDriver::getEncoder(int j, double *v)
123{
124 if (!ienc_ll) return false;
125 return ienc_ll->getEncoder(j, v);
126}
127
128bool robotDriver::positionMove(int j, double v)
129{
130 if (!ipos_ll) return false;
131 bool ret = true;
132
133 // set ref speed to each joint so that the motion is completed in
134 // the requested amount of time
135 if (1)
136 {
137 double enc = 0;
138 ret &= ienc_ll->getEncoder(j, &enc);
139 double diff = fabs(v - enc);
140 double speed = diff/m_trajectoryTime[j];
141 ipos_ll->setRefSpeed(j, speed);
142 }
143
144 ret &= ipos_ll->positionMove(j, v);
145
146 return ret;
147}
148
150{
151 return n_joints;
152}
define control board standard interfaces
FeatureMode mode
bool ret
#define yDebug(...)
Definition Log.h:275
contains the definition of a Vector type
bool setTrajectoryTime(double t)
bool setPosition(int j, double ref)
size_t getNJoints()
bool configure(const yarp::os::Property &copt)
bool setControlMode(const int j, const int mode)
bool getEncoder(int j, double *v)
bool positionMove(int j, double ref)
bool view(T *&x)
Get an interface to the device driver.
virtual bool setControlMode(const int j, const int mode)=0
Set the current control mode.
virtual bool getEncoder(int j, double *v)=0
Read the value of an encoder.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool setRefSpeed(int j, double sp)=0
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
virtual bool setRefSpeeds(const double *spds)=0
Set reference speed on all joints.
virtual bool positionMove(int j, double ref)=0
Set new reference point for a single axis.
virtual bool setPosition(int j, double ref)=0
Set new position for a single axis.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
void clear()
Remove all associations.
Property & addGroup(const std::string &key)
Add a nested group.
std::string toString() const override
Return a standard text representation of the content of the object.
Definition Value.cpp:368
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
int diff(std::string contextName, folderType fType, bool verbose)