YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeLaserWithMotor.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef FAKE_LASER_WITH_MOTOR_H
8#define FAKE_LASER_WITH_MOTOR_H
9
10
23#include <yarp/dev/MapGrid2D.h>
24#include <yarp/dev/PolyDriver.h>
25#include <yarp/sig/Vector.h>
26
27#include <mutex>
28#include <random>
29#include <string>
30
32
59 // public yarp::dev::StubImplTorqueControlRaw,
68{
69protected:
71
73
76
77 //motor stuff
78 size_t m_njoints=3;
79
80 //this is the position of the localized robot in the map
81 double m_robot_loc_x=0;
82 double m_robot_loc_y=0;
83 double m_robot_loc_t=0;
84
85 std::random_device* m_rd;
86 std::mt19937* m_gen;
87 std::uniform_real_distribution<>* m_dis;
88
90
91public:
92 FakeLaserWithMotor(double period = 0.02) : PeriodicThread(period),
100 {
101 //default parameters
102 m_min_distance = 0.1; //m
103 m_max_distance = 8.0; //m
104 m_min_angle = 0; //degrees
105 m_max_angle = 360; //degrees
106 m_resolution = 1.0; //degrees
107 m_scan_rate = period; //s
108
109 //noise generator
110 m_rd = new std::random_device;
111 m_gen = new std::mt19937((*m_rd)());
112 m_dis = new std::uniform_real_distribution<>(0, 0.01);
113 }
114
116 {
117 delete m_rd;
118 delete m_gen;
119 delete m_dis;
120 m_rd = 0;
121 m_gen = 0;
122 m_dis = 0;
123 }
124
125 bool open(yarp::os::Searchable& config) override;
126 bool close() override;
127 bool threadInit() override;
128 void threadRelease() override;
129 void run() override;
130
131private:
132 void drawStraightLine(yarp::dev::Nav2D::XYCell src, yarp::dev::Nav2D::XYCell dst);
133 void wall_the_robot(double siz = 1.0, double dist = 1.0);
134 void obst_the_robot(double siz = 1.0, double dist = 1.0);
135 void trap_the_robot(double siz = 1.0);
136 void free_the_robot();
137
138 double checkStraightLine(yarp::dev::Nav2D::XYCell src, yarp::dev::Nav2D::XYCell dst);
139 bool LiangBarsky_clip(int edgeLeft, int edgeRight, int edgeTop, int edgeBottom,
141 yarp::dev::Nav2D::XYCell& src_clipped, yarp::dev::Nav2D::XYCell& dst_clipped);
142
143public:
144 //IRangefinder2D interface
145 bool setDistanceRange (double min, double max) override;
146 bool setScanLimits (double min, double max) override;
147 bool setHorizontalResolution (double step) override;
148 bool setScanRate (double rate) override;
149
150public:
151 // internal stuff
152 std::string* _axisName = nullptr; // axis name
153 yarp::dev::JointTypeEnum* _jointType = nullptr; // axis type
154 int* _controlModes = nullptr;
155 double* _encoders = nullptr; // encoders
156 double* _posCtrl_references = nullptr; // used for position control.
157 double* _ref_speeds = nullptr; // used for position control.
158 double* _command_speeds = nullptr; // used for velocity control.
159 double* _ref_accs = nullptr; // used for velocity control.
160
161 bool alloc(int njoints);
162 bool dealloc();
163
164public:
165 //motor interfaces
166 bool resetEncoderRaw(int j) override;
167 bool resetEncodersRaw() override;
168 bool setEncoderRaw(int j, double val) override;
169 bool setEncodersRaw(const double* vals) override;
170 bool getEncoderRaw(int j, double* v) override;
171 bool getEncodersRaw(double* encs) override;
172 bool getEncoderSpeedRaw(int j, double* sp) override;
173 bool getEncoderSpeedsRaw(double* spds) override;
174 bool getEncoderAccelerationRaw(int j, double* spds) override;
175 bool getEncoderAccelerationsRaw(double* accs) override;
176
177 bool getEncodersTimedRaw(double* encs, double* stamps) override;
178 bool getEncoderTimedRaw(int j, double* encs, double* stamp) override;
179
180 // POSITION CONTROL INTERFACE RAW
181 bool getAxes(int* ax) override;
182 bool positionMoveRaw(int j, double ref) override;
183 bool positionMoveRaw(const double* refs) override;
184 bool relativeMoveRaw(int j, double delta) override;
185 bool relativeMoveRaw(const double* deltas) override;
186 bool checkMotionDoneRaw(bool* flag) override;
187 bool checkMotionDoneRaw(int j, bool* flag) override;
188 bool setRefSpeedRaw(int j, double sp) override;
189 bool setRefSpeedsRaw(const double* spds) override;
190 bool setRefAccelerationRaw(int j, double acc) override;
191 bool setRefAccelerationsRaw(const double* accs) override;
192 bool getRefSpeedRaw(int j, double* ref) override;
193 bool getRefSpeedsRaw(double* spds) override;
194 bool getRefAccelerationRaw(int j, double* acc) override;
195 bool getRefAccelerationsRaw(double* accs) override;
196 bool stopRaw(int j) override;
197 bool stopRaw() override;
198
199 bool positionMoveRaw(const int n_joint, const int* joints, const double* refs) override;
200 bool relativeMoveRaw(const int n_joint, const int* joints, const double* deltas) override;
201 bool checkMotionDoneRaw(const int n_joint, const int* joints, bool* flags) override;
202 bool setRefSpeedsRaw(const int n_joint, const int* joints, const double* spds) override;
203 bool setRefAccelerationsRaw(const int n_joint, const int* joints, const double* accs) override;
204 bool getRefSpeedsRaw(const int n_joint, const int* joints, double* spds) override;
205 bool getRefAccelerationsRaw(const int n_joint, const int* joints, double* accs) override;
206 bool stopRaw(const int n_joint, const int* joints) override;
207 bool getTargetPositionRaw(const int joint, double* ref) override;
208 bool getTargetPositionsRaw(double* refs) override;
209 bool getTargetPositionsRaw(const int n_joint, const int* joints, double* refs) override;
210
211 //IControlMode
212 bool getControlModeRaw(int j, int* v) override;
213 bool getControlModesRaw(int* v) override;
214 bool getControlModesRaw(const int n_joint, const int* joints, int* modes) override;
215 bool setControlModeRaw(const int j, const int mode) override;
216 bool setControlModesRaw(const int n_joint, const int* joints, int* modes) override;
217 bool setControlModesRaw(int* modes) override;
218
219 //IVelocityControl
220 bool velocityMoveRaw(int j, double sp) override;
221 bool velocityMoveRaw(const double* sp) override;
222 bool velocityMoveRaw(const int n_joint, const int* joints, const double* spds) override;
223 bool getRefVelocityRaw(const int joint, double* ref) override;
224 bool getRefVelocitiesRaw(double* refs) override;
225 bool getRefVelocitiesRaw(const int n_joint, const int* joints, double* refs) override;
226
227 bool getAxisNameRaw(int axis, std::string& name) override;
228 bool getJointTypeRaw(int axis, yarp::dev::JointTypeEnum& type) override;
229public:
230 //Lidar2DDeviceBase
231 bool acquireDataFromHW() override final;
232
233public:
234 bool read(yarp::os::ConnectionReader& connection) override;
235};
236
237#endif
define control board standard interfaces
contains the definition of a map type
contains the definition of a Vector type
This class is the parameters parser for class FakeLaserWithMotor.
fakeLaserWithMotor : fake sensor device driver for testing purposes and reference for IRangefinder2D ...
bool setRefSpeedsRaw(const double *spds) override
Set reference speed on all joints.
bool stopRaw() override
Stop motion, multiple joints.
bool setDistanceRange(double min, double max) override
set the device detection range.
bool getEncodersTimedRaw(double *encs, double *stamps) override
Read the instantaneous acceleration of all axes.
bool getEncodersRaw(double *encs) override
Read the position of all axes.
bool getTargetPositionRaw(const int joint, double *ref) override
Get the last position reference for the specified axis.
bool setScanRate(double rate) override
set the scan rate (scans per seconds)
bool getEncoderSpeedsRaw(double *spds) override
Read the instantaneous acceleration of an axis.
bool setEncodersRaw(const double *vals) override
Set the value of all encoders.
void run() override
Loop function.
bool getRefSpeedsRaw(double *spds) override
Get reference speed of all joints.
bool getJointTypeRaw(int axis, yarp::dev::JointTypeEnum &type) override
bool setControlModesRaw(const int n_joint, const int *joints, int *modes) override
bool resetEncoderRaw(int j) override
Reset encoder, single joint.
yarp::dev::Nav2D::MapGrid2D m_originally_loaded_map
bool threadInit() override
Initialization method.
bool checkMotionDoneRaw(bool *flag) override
Check if the current trajectory is terminated.
bool close() override
Close the DeviceDriver.
bool getControlModesRaw(int *v) override
bool positionMoveRaw(int j, double ref) override
Set new reference point for a single axis.
bool getRefAccelerationsRaw(double *accs) override
Get reference acceleration of all joints.
bool getEncoderRaw(int j, double *v) override
Read the value of an encoder.
bool getEncoderTimedRaw(int j, double *encs, double *stamp) override
Read the instantaneous acceleration of all axes.
FakeLaserWithMotor(double period=0.02)
bool getTargetPositionsRaw(double *refs) override
Get the last position reference for all axes.
bool getControlModeRaw(int j, int *v) override
bool getEncoderSpeedRaw(int j, double *sp) override
Read the instantaneous speed of an axis.
bool getRefVelocityRaw(const int joint, double *ref) override
Get the last reference speed set by velocityMove for single joint.
bool setHorizontalResolution(double step) override
get the angular step between two measurements (if available)
bool getAxisNameRaw(int axis, std::string &name) override
bool resetEncodersRaw() override
Reset encoders.
void threadRelease() override
Release method.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool setRefSpeedRaw(int j, double sp) override
Set reference speed for a joint, this is the speed used during the interpolation of the trajectory.
std::random_device * m_rd
bool setRefAccelerationRaw(int j, double acc) override
Set reference acceleration for a joint.
bool getRefAccelerationRaw(int j, double *acc) override
Get reference acceleration for a joint.
bool relativeMoveRaw(int j, double delta) override
Set relative position.
bool getRefVelocitiesRaw(double *refs) override
Get the last reference speed set by velocityMove for all joints.
yarp::dev::JointTypeEnum * _jointType
bool getEncoderAccelerationsRaw(double *accs) override
Read the instantaneous acceleration of all axes.
bool setEncoderRaw(int j, double val) override
Set the value of the encoder for a given joint.
bool getEncoderAccelerationRaw(int j, double *spds) override
Read the instantaneous acceleration of an axis.
bool velocityMoveRaw(int j, double sp) override
Start motion at a given speed, single joint.
bool setRefAccelerationsRaw(const double *accs) override
Set reference acceleration on all joints.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool setScanLimits(double min, double max) override
set the scan angular range.
bool getAxes(int *ax) override
Get the number of controlled axes.
bool acquireDataFromHW() override final
This method should be implemented by the user, and contain the logic to grab data from the hardware.
bool getRefSpeedRaw(int j, double *ref) override
Get reference speed for a joint.
yarp::os::Port m_rpcPort
std::uniform_real_distribution * m_dis
yarp::dev::Nav2D::MapGrid2D m_map
bool setControlModeRaw(const int j, const int mode) override
Interface implemented by all device drivers.
Interface for getting information about specific axes, if available.
Definition IAxisInfo.h:72
Interface for setting control mode in control board.
Control board, extend encoder raw interface adding timestamps.
Interface for a generic control board device implementing position control in encoder coordinates.
Interface for control boards implementig velocity control in encoder coordinates.
ImplementAxisInfo(yarp::dev::IAxisInfoRaw *y)
ImplementEncodersTimed(yarp::dev::IEncodersTimedRaw *y)
Interface settings the way the robot interacts with the environment: basic interaction types are Stif...
ImplementInteractionMode(yarp::dev::IInteractionModeRaw *Class_p)
Constructor.
Default implementation of the IPositionControl interface.
ImplementPositionControl(yarp::dev::IPositionControlRaw *y)
Constructor.
ImplementVelocityControl(yarp::dev::IVelocityControlRaw *y)
Constructor.
The Lidar2DDeviceBase class.
Stub implementation of IInteractionMode interface.
An abstraction for a periodic thread.
PeriodicThread(double period, ShouldUseSystemClock useSystemClock=ShouldUseSystemClock::No, PeriodicThreadClock clockAccuracy=PeriodicThreadClock::Relative)
Constructor.
void step()
Call this to "step" the thread rather than starting it.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
A mini-server for network communication.
Definition Port.h:46
A base class for nested structures that can be searched.
Definition Searchable.h:31
The main, catch-all namespace for YARP.
Definition dirs.h:16