YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeMotionControlMicro.h
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
6#ifndef YARP_DEVICE_FAKE_MOTIONCONTROLMICRO
7#define YARP_DEVICE_FAKE_MOTIONCONTROLMICRO
8
9#include <yarp/os/Time.h>
10#include <yarp/os/Bottle.h>
11#include <yarp/sig/Vector.h>
17
18#include <mutex>
20
42{
43private:
44 enum VerboseLevel
45 {
46 MUTE = 0, // only errors that prevent device from working
47 QUIET = 1, // adds errors that can cause malfunctioning
48 DEFAULT = 2, // adds warnings // DEFAULT // show noisy messages about back-compatible changes
49 CHATTY = 3, // adds info messages
50 VERBOSE = 4, // adds debug messages
51 VERY_VERBOSE = 5, // adds trace of events (shows thread running and catch if they get stuck)
52 VERY_VERY_VERBOSE = 6 // adds messages printed every cycle, so too much verbose for usage, only for deep debugging
53 };
54
55 std::recursive_mutex _mutex;
56 int _njoints;
57 int *_axisMap;
58 double *_angleToEncoder;
59 double *_encodersStamp;
61 std::string *_axisName;
62 yarp::dev::JointTypeEnum *_jointType;
64 bool verbosewhenok;
65 bool useRawEncoderData;
66
67
68 // internal stuff
69 int *_controlModes = nullptr;
70 int *_hwfault_code = nullptr;
71 std::string *_hwfault_message = nullptr;
72 yarp::sig::Vector pos, dpos, vel, speed, acc, loc, amp;
73 double prev_time;
74 bool opened;
75
76 // debugging
77 VerboseLevel verbose;
78public:
79
82
83 // Device Driver
84 bool open(yarp::os::Searchable &par) override;
85 bool close() override;
86 bool fromConfig(yarp::os::Searchable &config);
87
88 virtual bool initialised();
89
93 bool alloc(int njoints);
94
98 void resizeBuffers();
99
100 bool threadInit() override;
101 void threadRelease() override;
102
103 // IJointFault
104 yarp::dev::ReturnValue getLastJointFaultRaw(int j, int& fault, std::string& message) override;
105
110 yarp::dev::ReturnValue setMotorEncoderRaw(int j, double val) override;
111 yarp::dev::ReturnValue setMotorEncodersRaw(const double* vals) override;
112 yarp::dev::ReturnValue getMotorEncoderRaw(int j, double* v) override;
113 yarp::dev::ReturnValue getMotorEncodersRaw(double* encs) override;
114 yarp::dev::ReturnValue getMotorEncoderSpeedRaw(int j, double* sp) override;
116 yarp::dev::ReturnValue getMotorEncoderAccelerationRaw(int j, double* spds) override;
118 yarp::dev::ReturnValue getMotorEncodersTimedRaw(double* encs, double* stamps) override;
119 yarp::dev::ReturnValue getMotorEncoderTimedRaw(int m, double* encs, double* stamp) override;
121 yarp::dev::ReturnValue setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr) override;
123
125 yarp::dev::ReturnValue getAxes(size_t& ax) override;
128 yarp::dev::ReturnValue setEncoderRaw(int j, double val) override;
129 yarp::dev::ReturnValue setEncodersRaw(const double *vals) override;
130 yarp::dev::ReturnValue getEncoderRaw(int j, double *v) override;
131 yarp::dev::ReturnValue getEncodersRaw(double *encs) override;
132 yarp::dev::ReturnValue getEncoderSpeedRaw(int j, double *sp) override;
133 yarp::dev::ReturnValue getEncoderSpeedsRaw(double *spds) override;
134 yarp::dev::ReturnValue getEncoderAccelerationRaw(int j, double *spds) override;
137
139 yarp::dev::ReturnValue getEncodersTimedRaw(double *encs, double *stamps) override;
140 yarp::dev::ReturnValue getEncoderTimedRaw(int j, double *encs, double *stamp) override;
142
144 yarp::dev::ReturnValue getAxisNameRaw(int axis, std::string& name) override;
147
148 void run() override;
149private:
150 void cleanup();
151 bool dealloc();
152
153 bool extractGroup(yarp::os::Bottle &input, yarp::os::Bottle &out, const std::string &key1, const std::string &txt, int size);
154};
155
156#endif // YARP_DEVICE_FAKE_MOTIONCONTROLMICRO
define control board standard interfaces
contains the definition of a Vector type
This class is the parameters parser for class FakeMotionControlMicro.
fakeMotionControlMicro: This device implements a minimal subset of mandatory interfaces to run with c...
void threadRelease() override
Release method.
yarp::dev::ReturnValue getMotorEncoderSpeedsRaw(double *spds) override
Read the instantaneous speed of all motor encoders.
yarp::dev::ReturnValue setMotorEncoderRaw(int j, double val) override
Set the value of the motor encoder for a given motor.
yarp::dev::ReturnValue resetEncoderRaw(int j) override
Reset encoder, single joint.
yarp::dev::ReturnValue getMotorEncoderAccelerationsRaw(double *accs) override
Read the instantaneous acceleration of all motor encoders.
bool alloc(int njoints)
Allocated buffers.
yarp::dev::ReturnValue getMotorEncodersTimedRaw(double *encs, double *stamps) override
Read the instantaneous position of all motor encoders.
bool fromConfig(yarp::os::Searchable &config)
yarp::dev::ReturnValue getAxes(size_t &ax) override
Get the number of controlled axes.
yarp::dev::ReturnValue getMotorEncoderSpeedRaw(int j, double *sp) override
Read the instantaneous speed of a motor encoder.
yarp::dev::ReturnValue getEncoderSpeedsRaw(double *spds) override
Read the instantaneous acceleration of an axis.
yarp::dev::ReturnValue getEncoderAccelerationsRaw(double *accs) override
Read the instantaneous acceleration of all axes.
yarp::dev::ReturnValue getMotorEncodersRaw(double *encs) override
Read the position of all motor encoders.
yarp::dev::ReturnValue getNumberOfMotorEncodersRaw(int *num) override
Get the number of available motor encoders.
yarp::dev::ReturnValue getJointTypeRaw(int axis, yarp::dev::JointTypeEnum &type) override
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue resetMotorEncoderRaw(int j) override
Reset motor encoder, single motor.
yarp::dev::ReturnValue setMotorEncodersRaw(const double *vals) override
Set the value of all motor encoders.
yarp::dev::ReturnValue getAxisNameRaw(int axis, std::string &name) override
void run() override
Loop function.
yarp::dev::ReturnValue getMotorEncoderRaw(int j, double *v) override
Read the value of a motor encoder.
yarp::dev::ReturnValue setEncodersRaw(const double *vals) override
Set the value of all encoders.
yarp::dev::ReturnValue resetMotorEncodersRaw() override
Reset motor encoders.
void resizeBuffers()
Resize previously allocated buffers.
bool open(yarp::os::Searchable &par) override
Open the DeviceDriver.
yarp::dev::ReturnValue getMotorEncoderTimedRaw(int m, double *encs, double *stamp) override
Read the instantaneous position of a motor encoder.
bool threadInit() override
Initialization method.
yarp::dev::ReturnValue getMotorEncoderCountsPerRevolutionRaw(int m, double *v) override
Gets number of counts per revolution for motor encoder m.
yarp::dev::ReturnValue getEncodersRaw(double *encs) override
Read the position of all axes.
yarp::dev::ReturnValue getMotorEncoderAccelerationRaw(int j, double *spds) override
Read the instantaneous acceleration of a motor encoder.
yarp::dev::ReturnValue getEncodersTimedRaw(double *encs, double *stamps) override
Read the instantaneous acceleration of all axes.
yarp::dev::ReturnValue getEncoderTimedRaw(int j, double *encs, double *stamp) override
Read the instantaneous acceleration of all axes.
yarp::dev::ReturnValue getEncoderAccelerationRaw(int j, double *spds) override
Read the instantaneous acceleration of an axis.
yarp::dev::ReturnValue getEncoderRaw(int j, double *v) override
Read the value of an encoder.
yarp::dev::ReturnValue getEncoderSpeedRaw(int j, double *sp) override
Read the instantaneous speed of an axis.
yarp::dev::ReturnValue setEncoderRaw(int j, double val) override
Set the value of the encoder for a given joint.
yarp::dev::ReturnValue getLastJointFaultRaw(int j, int &fault, std::string &message) override
yarp::dev::ReturnValue resetEncodersRaw() override
Reset encoders.
yarp::dev::ReturnValue setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
Interface implemented by all device drivers.
Interface for getting information about specific axes, if available.
Definition IAxisInfo.h:73
Control board, extend encoder raw interface adding timestamps.
Interface for getting info about the fault which may occur on a robot.
Definition IJointFault.h:36
Control board, encoder interface.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31