Skip to content

Change robot speed at runtime#1456

Merged
SteveMacenski merged 2 commits intoros-navigation:masterfrom
fmrico:change_speed_runtime
Jan 13, 2020
Merged

Change robot speed at runtime#1456
SteveMacenski merged 2 commits intoros-navigation:masterfrom
fmrico:change_speed_runtime

Conversation

@fmrico
Copy link
Copy Markdown
Contributor

@fmrico fmrico commented Jan 7, 2020

Signed-off-by: Francisco Martin Rico [email protected]

Basic Info

Info Please fill out this column
Ticket(s) this addresses #1455
Primary OS tested on Ubuntu
Robotic platform tested on gazebo simulation of Tally

Description of contribution in a few bullet points

  • I added the option of changing the speed of the robot at runtime. Actually, this PR lets to change any parameter of the DWB controller

Future work that may be required in bullet points

fmrico added 2 commits January 7, 2020 10:02
Signed-off-by: Francisco Martin Rico <[email protected]>
Signed-off-by: Francisco Martin Rico <[email protected]>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 7, 2020

Codecov Report

Merging #1456 into master will decrease coverage by 2.35%.
The diff coverage is 2.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1456      +/-   ##
==========================================
- Coverage   39.92%   37.57%   -2.36%     
==========================================
  Files         229      229              
  Lines       11729    11771      +42     
  Branches     5057     5073      +16     
==========================================
- Hits         4683     4423     -260     
- Misses       3689     4146     +457     
+ Partials     3357     3202     -155
Flag Coverage Δ
#project 37.57% <2.43%> (-2.36%) ⬇️
Impacted Files Coverage Δ
...ugins/include/dwb_plugins/kinematic_parameters.hpp 100% <ø> (ø) ⬆️
...ontroller/dwb_plugins/src/kinematic_parameters.cpp 14.28% <2.43%> (-11.3%) ⬇️
..._2d/include/nav2_costmap_2d/observation_buffer.hpp 0% <0%> (-100%) ⬇️
nav2_costmap_2d/src/observation_buffer.cpp 0% <0%> (-40.6%) ⬇️
nav2_costmap_2d/plugins/voxel_layer.cpp 0.46% <0%> (-20.94%) ⬇️
nav2_map_server/src/main.cpp 36.36% <0%> (-18.19%) ⬇️
nav2_voxel_grid/src/voxel_grid.cpp 49.53% <0%> (-14.96%) ⬇️
nav2_costmap_2d/plugins/obstacle_layer.cpp 24.72% <0%> (-14.91%) ⬇️
nav2_navfn_planner/src/navfn.cpp 49.13% <0%> (-14.01%) ⬇️
nav2_util/src/robot_utils.cpp 10% <0%> (-10%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ea42a7d...3ff7705. Read the comment docs.

Copy link
Copy Markdown
Collaborator

@mkhansenbot mkhansenbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SteveMacenski SteveMacenski merged commit 124663a into ros-navigation:master Jan 13, 2020
@ghost
Copy link
Copy Markdown

ghost commented Jan 13, 2020

This needs some thread synchronization. The kinematic parameters are used on a different thread than the reconfigure call back.

The simple fix would be to add a mutex to the KinematicParameters class that we take in on_parameter_event_callback and every function that accesses these parameters. However, that's not going to be very efficient; every parameter has an individual accessor method.

Instead this class should be refactored so clients can grab the set of parameters instead of individual parameters.

@SteveMacenski
Copy link
Copy Markdown
Member

However, that's not going to be very efficient; every parameter has an individual accessor method.

Aren't the callbacks triggered by a ros thread spinning? If we're using single threaded executors (which we are), this is going to be already be thread safe, right?

@ghost
Copy link
Copy Markdown

ghost commented Jan 13, 2020

The callbacks run in the context of the ros spin function, but the actions runs on their own thread. So, in this case, all the FollowPath logic is on it's own thread, independent of the callbacks.

Here's where the thread is kicked off:
https://github.com/ros-planning/navigation2/blob/124663a8b7def5cad403a97223c0483bb6173877/nav2_util/include/nav2_util/simple_action_server.hpp#L134

All our action servers run this way, so it is something we need to watch out for mostly everywhere.

@SteveMacenski
Copy link
Copy Markdown
Member

Got it. Another option is to just make all the variables atomic. I know atomic doubles don't "technically" exist, but the template will work fine for our purposes because we're not using the operators on the values, they're just being stored and retrieved.

@ghost
Copy link
Copy Markdown

ghost commented Jan 13, 2020

Yeah. You're right. Atomics would be a better option than taking the mutex everywhere.

I'm not sure where the cutoff lies between the cost of accessing many atomics and the cost of taking one mutex. I suspect we're approaching that in this class though, so I think refactoring the interface makes sense in the long run.

Just making them all atomic though, would be a good short term fix and may be good enough that we never need to come back to the long run fix :-)

@SteveMacenski
Copy link
Copy Markdown
Member

SteveMacenski commented Jan 13, 2020

https://developernote.com/2017/06/comparison-stdmutex-and-stdatomic-performance/

42x, it appears from that dummy example. I'm actually a little surprised to see much overhead at all from just reading, I thought atomics were programmed to check for a condition that would make it near-zero overhead when something wasn't actively trying to write.

@ghost
Copy link
Copy Markdown

ghost commented Jan 13, 2020

I believe they do memory fence instructions to force writes all the way out to cache and reads to refresh from cache, at least on x86

This is going to impose some overhead and it might vary depending on how much data is in the write buffers and, ... well, I'm a bit fuzzy on exactly what a read fence does. :-)

@ninamwa
Copy link
Copy Markdown

ninamwa commented Feb 7, 2020

Hi! I really like this feature, it was exactly what I needed for my project :-)

The functionality works as expected, the parameters are changed in runtime and the velocity commands from the controller are changed. What I am having trouble with is that the navigation seems to fail a few seconds (or shorter) after I have changed the parameters. I have been testing this by simulating the Turtlebot multiple times, and it happens every time. A very short time after I reduce the maximum velocity, the recovery service hits and the robot is not able to recover. When running without recovery service I get the error: [controller_server-4] [ERROR] [controller_server]: Failed to make progress.

By looking at the code I get the impression that this error is printed if the robot has not moved long enough in a given time (default: 0.5m in 10 seconds). The time between changing the parameters and the robot stops moving is not 10 seconds, so I'm not sure if this is the correct source of the problem.

This does not happen if the robot is standing still when I am changing the parameters (only during navigation).

My default parameters are: [0.26, 0.0, 1.0, 0.26] (max_vel_x, max_vel_y, max_vel_theta, max_vel_xy). During runtime I am changing them to: [0.1, 0.0, 0.5, 0.1]

Have you experienced any similar behaviour while testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants