YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeNavigation.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 <yarp/os/Network.h>
7#include <yarp/os/RFModule.h>
8#include <yarp/os/Time.h>
9#include <yarp/os/Port.h>
11#include <yarp/os/LogStream.h>
13#include "FakeNavigation.h"
14#include "yarp/dev/Map2DPath.h"
15#include <math.h>
16#include <cmath>
17
18using namespace yarp::dev;
19using namespace yarp::dev::Nav2D;
20
21namespace {
22YARP_LOG_COMPONENT(FAKENAVIGATION, "yarp.device.fakeNavigation")
23}
24
25
27{
28 if (!this->parseParams(config)) {return false;}
29
30 m_time_counter = m_navigation_time;
31
32 this->start();
33 return true;
34}
35
36FakeNavigation::FakeNavigation() : yarp::os::PeriodicThread(0.010)
37{
38}
39
40//module cleanup
42{
43 return true;
44}
45
47{
48 if (m_status == NavigationStatusEnum::navigation_status_idle)
49 {
50 m_status = NavigationStatusEnum::navigation_status_moving;
51 m_absgoal_loc = loc;
52 m_time_counter= this->m_navigation_time;
53 }
54 return ReturnValue_ok;
55}
56
58{
59 yCInfo(FAKENAVIGATION) << "gotoTargetByRelativeLocation not yet implemented";
60 return ReturnValue_ok;
61}
62
64{
65 yCInfo(FAKENAVIGATION) << "gotoTargetByRelativeLocation not yet implemented";
66 return ReturnValue_ok;
67}
68
70{
71 yCInfo(FAKENAVIGATION) << "followPath not yet implemented";
72 return ReturnValue_ok;
73}
74
75ReturnValue FakeNavigation::applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout)
76{
77 m_control_out.linear_xvel = x_vel;
78 m_control_out.linear_yvel = y_vel;
79 m_control_out.angular_vel = theta_vel;
80 m_control_out.timeout = timeout;
81 m_control_out.reception_time = yarp::os::Time::now();
82 return ReturnValue_ok;
83}
84
85ReturnValue FakeNavigation::getLastVelocityCommand(double& x_vel, double& y_vel, double& theta_vel)
86{
88 x_vel = m_control_out.linear_xvel;
89 y_vel = m_control_out.linear_yvel;
90 theta_vel = m_control_out.angular_vel;
91 return ReturnValue_ok;
92}
93
95{
96 m_status=NavigationStatusEnum::navigation_status_idle;
97 m_absgoal_loc=Map2DLocation();
98 return ReturnValue_ok;
99}
100
102{
103 if (m_status == NavigationStatusEnum::navigation_status_moving)
104 {
105 m_status=NavigationStatusEnum::navigation_status_paused;
106 }
107 return ReturnValue_ok;
108}
109
111{
112 if (m_status == NavigationStatusEnum::navigation_status_paused)
113 {
114 m_status = NavigationStatusEnum::navigation_status_moving;
115 }
116 return ReturnValue_ok;
117}
118
120{
121 yCInfo(FAKENAVIGATION) << "getAllNavigationWaypoints not yet implemented";
122 return ReturnValue_ok;
123}
124
126{
127 yCInfo(FAKENAVIGATION) << "getCurrentNavigationWaypoint not yet implemented";
128 return ReturnValue_ok;
129}
130
132{
133 yCInfo(FAKENAVIGATION) << "getCurrentNavigationMap not yet implemented";
134 return ReturnValue_ok;
135}
136
142
144{
145 target = m_absgoal_loc;
146 return ReturnValue_ok;
147}
148
150{
151 if (m_status == NavigationStatusEnum::navigation_status_moving)
152 {
153 //do something
154 }
155 return ReturnValue_ok;
156}
157
159{
160 yCInfo(FAKENAVIGATION) << "getRelativeLocationOfCurrentTarget not yet implemented";
161 return ReturnValue_ok;
162}
163
165{
166 return true;
167}
168
170{
171
172}
173
175{
176 if (m_status == NavigationStatusEnum::navigation_status_moving)
177 {
178 if (m_time_counter>0)
179 {
180 m_time_counter--;
181 }
182 else
183 {
184 m_status = NavigationStatusEnum::navigation_status_goal_reached;
185 m_time_counter = m_reached_time;
186 }
187 }
188 if (m_status == NavigationStatusEnum::navigation_status_goal_reached)
189 {
190 if (m_time_counter > 0)
191 {
192 m_time_counter--;
193 }
194 else
195 {
196 m_status = NavigationStatusEnum::navigation_status_idle;
197 }
198 }
199}
define control board standard interfaces
contains the definition of a Map2DPath type
#define ReturnValue_ok
Definition ReturnValue.h:77
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue resumeNavigation() override
Resume a previously suspended navigation task.
virtual bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue getLastVelocityCommand(double &x_vel, double &y_vel, double &theta_vel) override
Returns the last applied velocity command.
yarp::dev::ReturnValue suspendNavigation(double time) override
Ask to the robot to suspend the current navigation task for a defined amount of time.
yarp::dev::ReturnValue followPath(const yarp::dev::Nav2D::Map2DPath &path) override
Ask the robot to navigate through a set of locations defined in the world reference frame.
yarp::dev::ReturnValue gotoTargetByRelativeLocation(double x, double y, double theta) override
Ask the robot to reach a position defined in the robot reference frame.
void run() override
Loop function.
yarp::dev::ReturnValue getCurrentNavigationWaypoint(yarp::dev::Nav2D::Map2DLocation &curr_waypoint) override
Returns the current waypoint pursued by the navigation algorithm.
yarp::dev::ReturnValue stopNavigation() override
Terminates the current navigation task.
yarp::dev::ReturnValue getAbsoluteLocationOfCurrentTarget(yarp::dev::Nav2D::Map2DLocation &target) override
Gets the last navigation target in the world reference frame.
bool threadInit() override
Initialization method.
virtual bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::dev::ReturnValue gotoTargetByAbsoluteLocation(yarp::dev::Nav2D::Map2DLocation loc) override
Ask the robot to reach a position defined in the world reference frame.
yarp::dev::ReturnValue getAllNavigationWaypoints(yarp::dev::Nav2D::TrajectoryTypeEnum trajectory_type, yarp::dev::Nav2D::Map2DPath &waypoints) override
Returns the list of waypoints generated by the navigation algorithm.
void threadRelease() override
Release method.
yarp::dev::ReturnValue applyVelocityCommand(double x_vel, double y_vel, double theta_vel, double timeout=0.1) override
Apply a velocity command.
yarp::dev::ReturnValue recomputeCurrentNavigationPath() override
Forces the navigation system to recompute the path from the current robot position to the current goa...
yarp::dev::ReturnValue getCurrentNavigationMap(yarp::dev::Nav2D::NavigationMapTypeEnum map_type, yarp::dev::Nav2D::MapGrid2D &map) override
Returns the current navigation map processed by the navigation algorithm.
yarp::dev::ReturnValue getNavigationStatus(yarp::dev::Nav2D::NavigationStatusEnum &status) override
Gets the current status of the navigation task.
yarp::dev::ReturnValue getRelativeLocationOfCurrentTarget(double &x, double &y, double &theta) override
Gets the last navigation target in the robot reference frame.
bool start()
Call this to start the thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31
std::string current_time()
Definition utils.h:24
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121
The main, catch-all namespace for YARP.
Definition dirs.h:16