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 <yarp/os/Network.h>
7#include <yarp/os/Time.h>
8#include <yarp/os/Log.h>
9#include <yarp/os/LogStream.h>
11#include <yarp/sig/Vector.h>
12
14#include <yarp/dev/PolyDriver.h>
16#include <yarp/os/Thread.h>
17
18using namespace std;
19using namespace yarp::os;
20using namespace yarp::sig;
21using namespace yarp::dev;
22
23#include "robotDriver.h"
24
25// ******************** ROBOT DRIVER CLASS
27{
28 drvOptions_ll.clear();
29}
30
32{
33 bool ret=true;
34 Property &options=const_cast<Property &> (copt);
35
36 drvOptions_ll.put("device","remotecontrolboardremapper");
37
38 yDebug() << "remoteControlBoards will use the following configuration:";
39 yDebug() << "set of joints:" << options.find("axesNames").toString();
40 yDebug() << "set of controlboards:" << options.find("remoteControlBoards").toString();
41 drvOptions_ll.put("axesNames", options.find("axesNames"));
42 drvOptions_ll.put("remoteControlBoards",options.find("remoteControlBoards"));
43 drvOptions_ll.put("localPortPrefix", options.find("localPortPrefix"));
44
45 yarp::os::Property& pcb =drvOptions_ll.addGroup("REMOTE_CONTROLBOARD_OPTIONS");
46 pcb.put("carrier", "fast_tcp");
47
48 if (verbose)
49 {
50 yDebug() << "driver options:\n" << drvOptions_ll.toString().c_str();
51 }
52
53 return ret;
54}
55
57{
58 drv_ll.open(drvOptions_ll);
59 bool ok = true;
60
61 if (drv_ll.isValid())
62 {
63 ok = drv_ll.view(ipos_ll) && drv_ll.view(iposdir_ll) && drv_ll.view(ienc_ll) &&
64 drv_ll.view(ipid_ll) && drv_ll.view(imotenc_ll) && drv_ll.view(icmd_ll);
65 }
66 else
67 {
68 ok = false;
69 }
70
71 if (!ok)
72 {
73 return false;
74 }
75
76 //get the number of the joints
77 ok &= ienc_ll->getAxes(&n_joints);
78
79 //set the initial reference speeds
80 std::vector<double> speeds;
81 for (int i = 0; i < n_joints; i++)
82 {
83 speeds.push_back(20.0);
84 }
85 ok &= ipos_ll->setRefSpeeds(speeds.data());
86
87 return ok;
88}
89
93
94bool robotDriver::setControlMode(const int j, const int mode)
95{
96 if (!icmd_ll) return false;
97 return icmd_ll->setControlMode(j, mode);
98}
99
100bool robotDriver::setPosition(int j, double ref)
101{
102 if (!iposdir_ll) return false;
103 return iposdir_ll->setPosition(j, ref);
104}
105
106bool robotDriver::getEncoder(int j, double *v)
107{
108 if (!ienc_ll) return false;
109 return ienc_ll->getEncoder(j, v);
110}
111
112bool robotDriver::positionMove(int j, double v)
113{
114 if (!ipos_ll) return false;
115 return ipos_ll->positionMove(j, v);
116}
117
119{
120 return n_joints;
121}
define control board standard interfaces
bool ret
#define yDebug(...)
Definition Log.h:275
contains the definition of a Vector type
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 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:356
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.