YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementPWMControl.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
8#include <yarp/os/LogStream.h>
10#include <iostream>
11
12using namespace yarp::dev;
13using namespace yarp::os;
14
15#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
16
19 helper(nullptr),
20 raw(r),
21 doubleBuffManager(nullptr)
22{;}
23
24bool ImplementPWMControl::initialize(int size, const int *amap, const double* dutyToPWM)
25{
26 if (helper != nullptr) {
27 return false;
28 }
29
30 helper = (void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, nullptr, nullptr, dutyToPWM));
31 yAssert(helper != nullptr);
32
33 doubleBuffManager = new yarp::dev::impl::FixedSizeBuffersManager<double> (size);
34 yAssert (doubleBuffManager != nullptr);
35
36 return true;
37}
38
43
45{
46 if (helper != nullptr)
47 {
48 delete castToMapper(helper);
49 helper = nullptr;
50 }
51
52 if(doubleBuffManager)
53 {
54 delete doubleBuffManager;
55 doubleBuffManager=nullptr;
56 }
57
58 return true;
59}
60
62{
63 return raw->getNumberOfMotorsRaw(axes);
64}
65
67{
69 int k;
70 double pwm;
71 castToMapper(helper)->dutycycle2PWM(duty, j, pwm, k);
72 return raw->setRefDutyCycleRaw(k, pwm);
73}
74
76{
78 castToMapper(helper)->dutycycle2PWM(duty, buffValues.getData());
79 bool ret = raw->setRefDutyCyclesRaw( buffValues.getData());
80 doubleBuffManager->releaseBuffer(buffValues);
81 return ret;
82}
83
85{
87 double pwm;
88 int k = castToMapper(helper)->toHw(j);
89 bool ret = raw->getRefDutyCycleRaw(k, &pwm);
90 *v = castToMapper(helper)->PWM2dutycycle(pwm, k);
91 return ret;
92}
93
95{
97 bool ret = raw->getRefDutyCyclesRaw(buffValues.getData());
98 castToMapper(helper)->PWM2dutycycle(buffValues.getData(), duty);
99 doubleBuffManager->releaseBuffer(buffValues);
100 return ret;
101}
102
104{
106 double pwm;
107 int k = castToMapper(helper)->toHw(j);
108 bool ret = raw->getDutyCycleRaw(k, &pwm);
109 *duty = castToMapper(helper)->PWM2dutycycle(pwm, k);
110 return ret;
111}
112
114{
116 bool ret = raw->getDutyCyclesRaw(buffValues.getData());
117 castToMapper(helper)->PWM2dutycycle(buffValues.getData(), duty);
118 doubleBuffManager->releaseBuffer(buffValues);
119 return ret;
120}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition Log.h:388
void dutycycle2PWM(double dutycycle, int j, double &pwm, int &k)
void PWM2dutycycle(const double *pwm, double *dutycycle)
Interface for controlling an axis, by sending directly a PWM reference signal to a motor.
Definition IPWMControl.h:84
virtual bool getDutyCycleRaw(int m, double *val)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual bool setRefDutyCycleRaw(int m, double ref)=0
Sets the reference dutycycle of a single motor.
virtual bool getDutyCyclesRaw(double *vals)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual bool getNumberOfMotorsRaw(int *number)=0
Retrieves the number of controlled motors from the current physical interface.
virtual bool setRefDutyCyclesRaw(const double *refs)=0
Sets the reference dutycycle for all motors.
virtual bool getRefDutyCyclesRaw(double *refs)=0
Gets the last reference sent using the setRefDutyCyclesRaw function.
virtual bool getRefDutyCycleRaw(int m, double *ref)=0
Gets the last reference sent using the setRefDutyCycleRaw function.
bool initialize(int k, const int *amap, const double *dutyToPWM)
bool getDutyCycle(int j, double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool getDutyCycles(double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
bool getNumberOfMotors(int *ax) override
Retrieves the number of controlled motors from the current physical interface.
bool getRefDutyCycle(int j, double *v) override
Gets the last reference sent using the setRefDutyCycle function.
bool getRefDutyCycles(double *v) override
Gets the last reference sent using the setRefDutyCycles function.
bool setRefDutyCycles(const double *v) override
Sets the reference dutycycle for all the motors.
bool setRefDutyCycle(int j, double v) override
Sets the reference dutycycle to a single motor.
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.