YARP
Yet Another Robot Platform
FakeOdometry.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 "FakeOdometry.h"
7
9#include <yarp/os/LogStream.h>
10#include <yarp/math/Rand.h>
11
12
13namespace {
14 YARP_LOG_COMPONENT(FAKEODOMETRY, "yarp.device.FakeOdometry")
15}
16
17
19PeriodicThread(default_period)
20{
21 m_period = default_period;
22 yCTrace(FAKEODOMETRY);
23}
24
25
27{
28 yCTrace(FAKEODOMETRY);
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
50{
51}
52
53
55{
56 // check period
57 if (!config.check("period", "refresh period of the broadcasted values in s")) {
58 yCInfo(FAKEODOMETRY) << "Using default 'period' parameter";
59 } else {
60 m_period = config.find("period").asFloat64();
61 }
62 yCInfo(FAKEODOMETRY) << "thread period set to " << m_period << "s";
63 PeriodicThread::setPeriod(m_period);
64 return PeriodicThread::start();
65}
66
67
69{
70 if (PeriodicThread::isRunning())
71 {
72 PeriodicThread::stop();
73 }
74 return true;
75}
76
77
79{
80 std::lock_guard lock(m_odometry_mutex);
81 odom.odom_x = m_odometryData.odom_x;
82 odom.odom_y = m_odometryData.odom_y;
83 odom.odom_theta = m_odometryData.odom_theta;
84 odom.base_vel_x = m_odometryData.base_vel_x;
85 odom.base_vel_y = m_odometryData.base_vel_y;
86 odom.base_vel_theta = m_odometryData.base_vel_theta;
87 odom.odom_vel_x = m_odometryData.odom_vel_x;
88 odom.odom_vel_y = m_odometryData.odom_vel_y;
89 odom.odom_vel_theta = m_odometryData.odom_vel_theta;
90 if (timestamp!=nullptr)
91 {
92 *timestamp = m_timestamp;
93 }
94 return true;
95}
96
97
99{
100 std::lock_guard lock(m_odometry_mutex);
101 m_odometryData.odom_x = 0;
102 m_odometryData.odom_y = 0;
103 m_odometryData.odom_theta = 0;
104 m_odometryData.base_vel_x = 0;
105 m_odometryData.base_vel_y = 0;
106 m_odometryData.base_vel_theta = 0;
107 m_odometryData.odom_vel_x = 0;
108 m_odometryData.odom_vel_y = 0;
109 m_odometryData.odom_vel_theta = 0;
110 return true;
111}
constexpr double default_period
Definition: FakeOdometry.h:14
virtual void threadRelease() override
Release method.
virtual void run() override
Loop function.
virtual bool threadInit() override
Initialization method.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool resetOdometry() override
Resets the odometry of the robot to zero.
bool 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...
double base_vel_x
velocity of the robot [m/s] expressed in the robot reference frame
Definition: OdometryData.h:41
double odom_vel_y
velocity of the robot [m/s] expressed in the world reference frame
Definition: OdometryData.h:57
double base_vel_theta
angular velocity of the robot [deg/s] expressed in the robot reference frame
Definition: OdometryData.h:49
double odom_vel_theta
angular velocity of the robot [deg/s] expressed in the world reference frame
Definition: OdometryData.h:61
double base_vel_y
velocity of the robot [m/s] expressed in the robot reference frame
Definition: OdometryData.h:45
double odom_x
position of the robot [m], expressed in the world reference frame
Definition: OdometryData.h:29
double odom_y
position of the robot [m], expressed in the world reference frame
Definition: OdometryData.h:33
double odom_theta
orientation the robot [deg], expressed in the world reference frame
Definition: OdometryData.h:37
double odom_vel_x
velocity of the robot [m/s] expressed in the world reference frame
Definition: OdometryData.h:53
static double scalar()
Get a random number from a uniform distribution in the range [0,1].
Definition: Rand.cpp:59
A base class for nested structures that can be searched.
Definition: Searchable.h:63
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition: Value.cpp:222
#define yCInfo(component,...)
Definition: LogComponent.h:171
#define yCTrace(component,...)
Definition: LogComponent.h:84
#define YARP_LOG_COMPONENT(name,...)
Definition: LogComponent.h:76
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition: Time.cpp:121