Ask Your Question

Re-scaling output values of a topic

asked 2021-09-23 04:27:40 -0500

horvath.daniel gravatar image

Hello guys! I'm working on a teleop project with a Spacenav joystick for a UR5e robot arm. I've remapped the topic to which the spacenav_node published originally to /twist_controller/command but the values which the joystick sends are too big for the robot arm to safely use and so the safety is triggered. How do I re-scale the values to more optimal ones? The maximum values which the joystick publishes are ~0.9. How do I scale that range down to -0.04 and 0.04?

I'm thinking of making a separate package which launches in parallel to the spacenav one and which takes the output values and divides them by a constant. Is this a viable solution or is there a simpler method to resolve this issue?

Thanks in advance.

edit retag flag offensive close merge delete


Hi, I'm not an expert, so this is not an answer, but your solution would also be my approach to solve this. A simple subscriber who publishes the scaled date to a new topic. Another approach could be to implement a scaling factor in the spacenav node.

MarioSpeckert gravatar image MarioSpeckert  ( 2021-09-23 04:48:22 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2021-09-23 05:12:40 -0500

gvdhoorn gravatar image

updated 2021-09-23 05:32:02 -0500

Besides writing a custom node, I can come up with two options:

  1. treat your spacenav as a joystick, and use something like teleop_tools/joy_teleop. That node supports scaling and a few other options which seem to do what you describe
  2. keep using raw values from your spacenav, but scale them using topic_tools/transform. That node subscribes to a topic, runs it through a Python expression and then publishes the result to (preferably) a new topic. A previous Q&A about transform is #q261935, which shows how to format complex expressions

I've used both in the past.

Option 1 will probably be the easiest to implement. Option 2 is the most flexible, as it's almost a custom node, but then as an argument to the topic_tools/transform node.

In any case: try to avoid writing code yourself as much as possible.

And something to realise: any additional nodes (or really: publishers and subscribers) you place between your input device and the final consumer of your Twists is going to add delay and jitter. That may not be a problem in your case, but it is something to keep in mind when working with such a system.

edit flag offensive delete link more

answered 2021-10-05 10:30:27 -0500

fexner gravatar image

Please note that the twist_controller has a dynamic_reconfigure parameter twist_gain to achieve exactly this.

edit flag offensive delete link more


Avoiding feeding values outside a desirable range to a component might be nicer from a 'defensive programming' perspective.

But it's true, if the consumer can also scale, that would also be an option.

Note that, unless precautions are taken, dynamic_reconfigure parameters are not persisted.

gvdhoorn gravatar image gvdhoorn  ( 2021-10-05 11:16:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-09-23 04:27:40 -0500

Seen: 48 times

Last updated: Oct 05 '21