YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementTorqueControl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
9
10#include <cstdio>
11using namespace yarp::dev;
12using namespace yarp::os;
13
14#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
15
17 iTorqueRaw(tq),
18 helper(nullptr),
19 intBuffManager(nullptr),
20 doubleBuffManager(nullptr)
21{;}
22
27
28bool ImplementTorqueControl::initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw, const double* amps, const double* dutys, const double* bemfs, const double* ktaus)
29{
30 if (helper != nullptr) {
31 return false;
32 }
33
34 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos, nw, amps, nullptr, dutys,bemfs,ktaus));
35 yAssert (helper != nullptr);
36
38 yAssert (intBuffManager != nullptr);
39
41 yAssert (doubleBuffManager != nullptr);
42
43 return true;
44}
45
47{
48 if (helper!=nullptr)
49 {
50 delete castToMapper(helper);
51 helper=nullptr;
52 }
53
55 {
56 delete intBuffManager;
57 intBuffManager=nullptr;
58 }
59
61 {
62 delete doubleBuffManager;
63 doubleBuffManager=nullptr;
64 }
65
66 return true;
67}
68
70{
71 return iTorqueRaw->getAxes(axes);
72}
73
75{
77 int k;
78 bool ret;
79 double torque;
81 ret = iTorqueRaw->getRefTorqueRaw(k, &torque);
82 *r=castToMapper(helper)->trqS2N(torque, k);
83 return ret;
84}
85
105
107{
109 int k=castToMapper(helper)->toHw(j);
110
113 int tmp_j;
114
115 if (b)
116 {
117 *params = params_raw;
118 castToMapper(helper)->bemf_raw2user(params_raw.bemf, k, (*params).bemf, tmp_j);
119 castToMapper(helper)->ktau_raw2user(params_raw.ktau, k, (*params).ktau, tmp_j);
120 (*params).bemf_scale = params_raw.bemf_scale;
121 (*params).ktau_scale = params_raw.ktau_scale;
122 castToMapper(helper)->viscousPos_raw2user(params_raw.viscousPos, k, (*params).viscousPos, tmp_j);
123 castToMapper(helper)->viscousNeg_raw2user(params_raw.viscousNeg, k, (*params).viscousNeg, tmp_j);
124 castToMapper(helper)->coulombPos_raw2user(params_raw.coulombPos, k, (*params).coulombPos, tmp_j);
125 castToMapper(helper)->coulombNeg_raw2user(params_raw.coulombNeg, k, (*params).coulombNeg, tmp_j);
126 castToMapper(helper)->velocityThres_raw2user(params_raw.velocityThres, k, (*params).velocityThres, tmp_j);
127 }
128 return b;
129}
130
139
148
150{
152 int k;
153 double sens;
156}
157
166
187
189{
191 int k;
193 return iTorqueRaw->getTorqueRaw(k, t);
194}
195
208
209bool ImplementTorqueControl::getTorqueRange(int j, double *min, double *max)
210{
212 int k;
214 return iTorqueRaw->getTorqueRangeRaw(k, min, max);
215}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
float t
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition Log.h:388
void viscousNeg_raw2user(double viscousNeg_raw, int k_raw, double &viscousNeg_user, int &j_user)
double viscousNeg_user2raw(double viscousNeg_user, int j)
void ktau_raw2user(double ktau_raw, int k_raw, double &ktau_user, int &j_user)
void trqN2S(double newtons, int j, double &sens, int &k)
void bemf_raw2user(double bemf_raw, int k_raw, double &bemf_user, int &j_user)
void coulombPos_raw2user(double coulombPos_raw, int k_raw, double &coulombPos_user, int &j_user)
double ktau_user2raw(double ktau_user, int j)
double coulombPos_user2raw(double coulombPos_user, int j)
double coulombNeg_user2raw(double coulombNeg_user, int j)
double velocityThres_user2raw(double velocityThres_user, int j)
void velocityThres_raw2user(double threshold_raw, int k_raw, double &velocityThres_user, int &j_user)
double viscousPos_user2raw(double viscousPos_user, int j)
void coulombNeg_raw2user(double coulombNeg_raw, int k_raw, double &coulombNeg_user, int &j_user)
void trqS2N(const double *sens, double *newtons)
double bemf_user2raw(double bemf_user, int j)
void viscousPos_raw2user(double viscousPos_raw, int k_raw, double &viscousPos_user, int &j_user)
Interface for control boards implementing torque control.
virtual bool getTorqueRangeRaw(int j, double *min, double *max)=0
Get the full scale of the torque sensor of a given joint.
virtual bool setRefTorquesRaw(const double *t)=0
Set the reference value of the torque for all joints.
virtual bool setMotorTorqueParamsRaw(int j, const yarp::dev::MotorTorqueParameters params)
Set the motor parameters.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getRefTorquesRaw(double *t)=0
Get the reference value of the torque for all joints.
virtual bool getTorqueRaw(int j, double *t)=0
Get the value of the torque on a given joint (this is the feedback if you have a torque sensor).
virtual bool getRefTorqueRaw(int j, double *t)=0
Set the reference value of the torque for a given joint.
virtual bool setRefTorqueRaw(int j, double t)=0
Set the reference value of the torque for a given joint.
virtual bool getMotorTorqueParamsRaw(int j, yarp::dev::MotorTorqueParameters *params)
Get the motor parameters.
virtual bool getTorqueRangesRaw(double *min, double *max)=0
Get the full scale of the torque sensors of all joints.
virtual bool getTorquesRaw(double *t)=0
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
bool getRefTorques(double *t) override
Get the reference value of the torque for all joints.
bool setMotorTorqueParams(int j, const yarp::dev::MotorTorqueParameters params) override
Set a subset of motor parameters (bemf, ktau etc) useful for torque control.
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
bool getTorque(int j, double *t) override
Get the value of the torque on a given joint (this is the feedback if you have a torque sensor).
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
bool getTorqueRanges(double *min, double *max) override
Get the full scale of the torque sensors of all joints.
bool setRefTorques(const double *t) override
Set the reference value of the torque for all joints.
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *nw, const double *amps, const double *dutys, const double *bemfs, const double *ktaus)
Initialize the internal data and alloc memory.
yarp::dev::ITorqueControlRaw * iTorqueRaw
ImplementTorqueControl(yarp::dev::ITorqueControlRaw *y)
bool uninitialize()
Clean up internal data and memory.
bool getTorqueRange(int j, double *min, double *max) override
Get the full scale of the torque sensor of a given joint.
bool getTorques(double *t) override
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
bool getRefTorque(int j, double *) override
Get the reference value of the torque for a given joint.
bool getAxes(int *ax) override
Get the number of controlled axes.
bool setRefTorque(int j, double t) override
Set the reference value of the torque for a given joint.
bool getMotorTorqueParams(int j, yarp::dev::MotorTorqueParameters *params) override
Get a subset of motor parameters (bemf, ktau etc) useful for torque control.
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
A manager of fixed size buffers in multi-thread environment.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
A mini-server for performing network communication in the background.
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.