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
9#include <yarp/os/LogStream.h>
11#include <iostream>
12
13using namespace yarp::dev;
14using namespace yarp::os;
15
16namespace {
17YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementPWMControl")
18}
19
22 m_helper(nullptr),
23 m_iraw(r)
24{;}
25
26bool ImplementPWMControl::initialize(int size, const int *amap, const double* dutyToPWM)
27{
28 if (m_helper != nullptr) {
29 return false;
30 }
31
32 m_helper = (void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, nullptr, nullptr, dutyToPWM));
33 yAssert(m_helper != nullptr);
34
35 m_buffer_ints.resize (size);
36 m_buffer_doubles.resize(size);
37
38 return true;
39}
40
45
47{
48 if (m_helper != nullptr)
49 {
50 delete castToMapper(m_helper);
51 m_helper = nullptr;
52 }
53
54 return true;
55}
56
58{
59 std::lock_guard lock(m_imp_mutex);
61
62 return m_iraw->getNumberOfMotorsRaw(axes);
63}
64
66{
67 std::lock_guard lock(m_imp_mutex);
69
70 int k;
71 double pwm;
72 castToMapper(m_helper)->dutycycle2PWM(duty, j, pwm, k);
73 return m_iraw->setRefDutyCycleRaw(k, pwm);
74}
75
77{
78 std::lock_guard lock(m_imp_mutex);
80
81 castToMapper(m_helper)->dutycycle2PWM(duty, m_buffer_doubles.data());
82 ReturnValue ret = m_iraw->setRefDutyCyclesRaw( m_buffer_doubles.data());
83
84 return ret;
85}
86
88{
89 std::lock_guard lock(m_imp_mutex);
92
93 double pwm;
94 int k = castToMapper(m_helper)->toHw(j);
95 ReturnValue ret = m_iraw->getRefDutyCycleRaw(k, &pwm);
96 *v = castToMapper(m_helper)->PWM2dutycycle(pwm, k);
97 return ret;
98}
99
101{
102 std::lock_guard lock(m_imp_mutex);
104
105 ReturnValue ret = m_iraw->getRefDutyCyclesRaw(m_buffer_doubles.data());
106 castToMapper(m_helper)->PWM2dutycycle(m_buffer_doubles.data(), duty);
107
108 return ret;
109}
110
112{
113 std::lock_guard lock(m_imp_mutex);
116
117 double pwm;
118 int k = castToMapper(m_helper)->toHw(j);
119 ReturnValue ret = m_iraw->getDutyCycleRaw(k, &pwm);
120 *duty = castToMapper(m_helper)->PWM2dutycycle(pwm, k);
121 return ret;
122}
123
125{
126 std::lock_guard lock(m_imp_mutex);
128
129 ReturnValue ret = m_iraw->getDutyCyclesRaw(m_buffer_doubles.data());
130 castToMapper(m_helper)->PWM2dutycycle(m_buffer_doubles.data(), duty);
131
132 return ret;
133}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#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:85
virtual yarp::dev::ReturnValue setRefDutyCycleRaw(int m, double ref)=0
Sets the reference dutycycle of a single motor.
virtual yarp::dev::ReturnValue getDutyCycleRaw(int m, double *val)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual yarp::dev::ReturnValue getRefDutyCyclesRaw(double *refs)=0
Gets the last reference sent using the setRefDutyCyclesRaw function.
virtual yarp::dev::ReturnValue getNumberOfMotorsRaw(int *number)=0
Retrieves the number of controlled motors from the current physical interface.
virtual yarp::dev::ReturnValue getRefDutyCycleRaw(int m, double *ref)=0
Gets the last reference sent using the setRefDutyCycleRaw function.
virtual yarp::dev::ReturnValue getDutyCyclesRaw(double *vals)=0
Gets the current dutycycle of the output of the amplifier (i.e.
virtual yarp::dev::ReturnValue setRefDutyCyclesRaw(const double *refs)=0
Sets the reference dutycycle for all motors.
bool initialize(int k, const int *amap, const double *dutyToPWM)
yarp::dev::ReturnValue getDutyCycle(int j, double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
yarp::dev::ReturnValue getRefDutyCycle(int j, double *v) override
Gets the last reference sent using the setRefDutyCycle function.
yarp::dev::ReturnValue setRefDutyCycles(const double *v) override
Sets the reference dutycycle for all the motors.
yarp::dev::ReturnValue getNumberOfMotors(int *ax) override
Retrieves the number of controlled motors from the current physical interface.
yarp::dev::ReturnValue getRefDutyCycles(double *v) override
Gets the last reference sent using the setRefDutyCycles function.
yarp::dev::ReturnValue setRefDutyCycle(int j, double v) override
Sets the reference dutycycle to a single motor.
yarp::dev::ReturnValue getDutyCycles(double *v) override
Gets the current dutycycle of the output of the amplifier (i.e.
A mini-server for performing network communication in the background.
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.