YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementMotorEncoders.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
10
11#include <cstdio>
12using namespace yarp::dev;
13using namespace yarp::os;
14
15namespace {
16YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementMotorEncoders")
17}
18
20// Encoder Interface Timed Implementation
22 m_iraw(y),
23 m_helper(nullptr)
24{;}
25
30
31bool ImplementMotorEncoders:: initialize (int size, const int *amap, const double *enc, const double *zos)
32{
33 if (m_helper != nullptr) {
34 return false;
35 }
36
37 m_helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
38 yAssert (m_helper != nullptr);
39
40 m_buffer_ints.resize (size);
41 m_buffer_doubles.resize(size);
42 m_buffer_doubles2.resize(size);
43
44 return true;
45}
46
52{
53 if (m_helper!=nullptr)
54 {
55 delete castToMapper(m_helper);
56 m_helper=nullptr;
57 }
58
59 return true;
60}
61
63{
64 std::lock_guard lock(m_imp_mutex);
65
66 (*num)=castToMapper(m_helper)->axes();
67 return ReturnValue_ok;
68}
69
80
87
89{
90 std::lock_guard lock(m_imp_mutex);
92
93 int k;
94 double enc;
95
96 castToMapper(m_helper)->posA2E(val, m, enc, k);
97
99}
100
114
126
128{
129 std::lock_guard lock(m_imp_mutex);
131
133
135
136 return ret;
137}
138
140{
141 std::lock_guard lock(m_imp_mutex);
144
145 int k;
146 double enc;
147 ReturnValue ret;
148
150
152
154
155 return ret;
156}
157
168
170{
171 std::lock_guard lock(m_imp_mutex);
174
175 int k;
176 double enc;
177 ReturnValue ret;
178
180
182
184
185 return ret;
186}
187
198
200{
201 std::lock_guard lock(m_imp_mutex);
204
205 int k;
206 double enc;
207 ReturnValue ret;
208
210
212
214
215 return ret;
216}
217
228
230{
231 std::lock_guard lock(m_imp_mutex);
235
236 int k;
237 double enc;
238 ReturnValue ret;
239
241
243
245
246 return ret;
247}
248
249
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#define yAssert(x)
Definition Log.h:388
#define ReturnValue_ok
Definition ReturnValue.h:82
void accE2A(double enc, int j, double &ang, int &k)
void velE2A(double enc, int j, double &ang, int &k)
void posE2A(double enc, int j, double &ang, int &k)
void posA2E(double ang, int j, double &enc, int &k)
Control board, encoder interface.
virtual yarp::dev::ReturnValue setMotorEncoderRaw(int m, const double val)=0
Set the value of the motor encoder for a given motor.
virtual yarp::dev::ReturnValue resetMotorEncoderRaw(int m)=0
Reset motor encoder, single motor.
virtual yarp::dev::ReturnValue getMotorEncoderTimedRaw(int m, double *encs, double *stamp)=0
Read the instantaneous position of a motor encoder.
virtual yarp::dev::ReturnValue getMotorEncodersRaw(double *encs)=0
Read the position of all motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderRaw(int m, double *v)=0
Read the value of a motor encoder.
virtual yarp::dev::ReturnValue setMotorEncodersRaw(const double *vals)=0
Set the value of all motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderSpeedRaw(int m, double *sp)=0
Read the instantaneous speed of a motor encoder.
virtual yarp::dev::ReturnValue setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr)=0
Sets number of counts per revolution for motor encoder m.
virtual yarp::dev::ReturnValue resetMotorEncodersRaw()=0
Reset motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderAccelerationsRaw(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderSpeedsRaw(double *spds)=0
Read the instantaneous speed of all motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderCountsPerRevolutionRaw(int m, double *cpr)=0
Gets number of counts per revolution for motor encoder m.
virtual yarp::dev::ReturnValue getMotorEncodersTimedRaw(double *encs, double *stamps)=0
Read the instantaneous position of all motor encoders.
virtual yarp::dev::ReturnValue getMotorEncoderAccelerationRaw(int m, double *spds)=0
Read the instantaneous acceleration of a motor encoder.
yarp::dev::ReturnValue getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets number of counts per revolution for motor encoder m.
yarp::dev::ReturnValue getMotorEncodersTimed(double *encs, double *time) override
Read the instantaneous position of all motor encoders.
yarp::dev::ReturnValue setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
ImplementMotorEncoders(yarp::dev::IMotorEncodersRaw *y)
yarp::dev::ReturnValue resetMotorEncoders() override
Reset motor encoders.
bool uninitialize()
Clean up internal data and memory.
yarp::dev::ReturnValue getMotorEncoderTimed(int m, double *v, double *t) override
Read the instantaneous position of a motor encoder.
yarp::dev::ReturnValue getMotorEncoderSpeed(int m, double *spds) override
Read the instantaneous speed of a motor encoder.
yarp::dev::ReturnValue getMotorEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all motor encoders.
yarp::dev::ReturnValue getMotorEncoderAcceleration(int m, double *spds) override
Read the instantaneous acceleration of a motor encoder.
yarp::dev::ReturnValue resetMotorEncoder(int m) override
Reset motor encoder, single motor.
yarp::dev::ReturnValue getMotorEncoder(int m, double *v) override
Read the value of a motor encoder.
yarp::dev::ReturnValue setMotorEncoder(int m, const double val) override
Set the value of the motor encoder for a given motor.
yarp::dev::ReturnValue getMotorEncoders(double *encs) override
Read the position of all motor encoders.
yarp::dev::ReturnValue getMotorEncoderSpeeds(double *spds) override
Read the instantaneous speed of all motor encoders.
yarp::dev::ReturnValue setMotorEncoders(const double *vals) override
Set the value of all motor encoders.
yarp::dev::ReturnValue getNumberOfMotorEncoders(int *num) override
Get the number of available motor encoders.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
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.
Definition OSTestMsg.cpp:13