YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeOdometry2D.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6#include "FakeOdometry2D.h"
7
9#include <yarp/os/LogStream.h>
10#include <yarp/math/Rand.h>
11
12
13namespace {
14 YARP_LOG_COMPONENT(FAKEODOMETRY2D, "yarp.device.FakeOdometry2D")
15}
16
17
19PeriodicThread(default_period)
20{
21 m_period = default_period;
22 yCTrace(FAKEODOMETRY2D);
23}
24
25
27{
28 yCTrace(FAKEODOMETRY2D);
29 return true;
30}
31
32
34{
35 std::lock_guard lock(m_odometry_mutex);
36 m_odometryData.base_vel_x = yarp::math::Rand::scalar(0,5);
37 m_odometryData.base_vel_y = yarp::math::Rand::scalar(0,5);
38 m_odometryData.base_vel_theta = yarp::math::Rand::scalar(0,5);
39 m_odometryData.odom_vel_x = m_odometryData.base_vel_x;
40 m_odometryData.odom_vel_y = m_odometryData.base_vel_y;
41 m_odometryData.odom_vel_theta = m_odometryData.base_vel_theta;
42 m_odometryData.odom_x = m_odometryData.odom_x + m_period * m_odometryData.base_vel_x;
43 m_odometryData.odom_y = m_odometryData.odom_y + m_period * m_odometryData.base_vel_y;
44 m_odometryData.odom_theta = m_odometryData.odom_theta + m_period * m_odometryData.base_vel_theta;
45 m_timestamp = yarp::os::Time::now();
46}
47
48
52
53
55{
56 if (!this->parseParams(config)) {return false;}
57
58 setPeriod(m_period);
59
60 return PeriodicThread::start();
61}
62
63
65{
66 if (PeriodicThread::isRunning())
67 {
68 PeriodicThread::stop();
69 }
70 return true;
71}
72
73
75{
76 std::lock_guard lock(m_odometry_mutex);
77 odom.odom_x = m_odometryData.odom_x;
78 odom.odom_y = m_odometryData.odom_y;
79 odom.odom_theta = m_odometryData.odom_theta;
80 odom.base_vel_x = m_odometryData.base_vel_x;
81 odom.base_vel_y = m_odometryData.base_vel_y;
82 odom.base_vel_theta = m_odometryData.base_vel_theta;
83 odom.odom_vel_x = m_odometryData.odom_vel_x;
84 odom.odom_vel_y = m_odometryData.odom_vel_y;
85 odom.odom_vel_theta = m_odometryData.odom_vel_theta;
86 if (timestamp!=nullptr)
87 {
88 *timestamp = m_timestamp;
89 }
90 return yarp::dev::ReturnValue_ok;
91}
92
93
95{
96 std::lock_guard lock(m_odometry_mutex);
97 m_odometryData.odom_x = 0;
98 m_odometryData.odom_y = 0;
99 m_odometryData.odom_theta = 0;
100 m_odometryData.base_vel_x = 0;
101 m_odometryData.base_vel_y = 0;
102 m_odometryData.base_vel_theta = 0;
103 m_odometryData.odom_vel_x = 0;
104 m_odometryData.odom_vel_y = 0;
105 m_odometryData.odom_vel_theta = 0;
106 return yarp::dev::ReturnValue_ok;
107}
constexpr double default_period
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
virtual void threadRelease() override
Release method.
virtual void run() override
Loop function.
yarp::dev::ReturnValue resetOdometry() override
Resets the odometry of the robot to zero.
bool close() override
Close the DeviceDriver.
virtual bool threadInit() override
Initialization method.
yarp::dev::ReturnValue getOdometry(yarp::dev::OdometryData &odom, double *timestamp=nullptr) override
Gets the odometry of the robot, including its velocity expressed in the world and in the local refere...
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
double base_vel_x
velocity of the robot [m/s] expressed in the robot reference frame
double odom_vel_y
velocity of the robot [m/s] expressed in the world reference frame
double base_vel_theta
angular velocity of the robot [deg/s] expressed in the robot reference frame
double odom_vel_theta
angular velocity of the robot [deg/s] expressed in the world reference frame
double base_vel_y
velocity of the robot [m/s] expressed in the robot reference frame
double odom_x
position of the robot [m], expressed in the world reference frame
double odom_y
position of the robot [m], expressed in the world reference frame
double odom_theta
orientation the robot [deg], expressed in the world reference frame
double odom_vel_x
velocity of the robot [m/s] expressed in the world reference frame
static double scalar()
Get a random number from a uniform distribution in the range [0,1].
Definition Rand.cpp:59
bool setPeriod(double period)
Set the (new) period of the thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121