Teleop Keyboard Node in Rust! 🦀

Rust Implementation of the Generic Keyboard Teleop for ROS2: teleop_twist_keyboard_rust

Running the Node


git  clone  https://github.com/AtharvaBhorpe/teleop_twist_keyboard_rust

cd  teleop_twist_keyboard_rust

cargo run

Dependencies:

  1. r2r
  2. termios
  3. lazy_static

Please support the project by star-ing the repo if you liked it!:sparkles:
Any suggestions for optimization or improvement are welcome!

3 Likes

Yes, I have had a look. The problem is that you can only build a Rust programm that communicates with ros2 when it is started. Why in this way and not so that it can be started directly with ros2 as a node?

Thank you for investing your valuable time in my little project !! :sparkles:

  • The ros2 client library that I have used [r2r] can be implemented without going through colcon and the standard ROS way. This was my first completed project in my journey of learning Rust, and hence I decided to avoid the standard ROS way and try this one.
  • However, there is development happening on the official rclrust client library [ros2_rust]. This crate is pretty new and the r2r has more features already implemented than ros2_rust. However, the ros2_rust is implemented in the standard ROS way. I have added this to the TODO list and started working on it. Using this crate, having a launch file will be possible as well.

Thank you for your valuable feedback and stay tuned for this update!:dizzy:

Any more feedback is happily welcomed!

As one of the members of the ROS 2 Rust Working Group that’s working on the ros2_rust client library, I would just like to say that if decide to try it out and you have any feedback as to how well it works for you and how it “feels” to use, please let us know! We are always looking to improve the user experience.

[Package Update]

Hey peeps!

I have implemented the teleop rust node using the official rclrust client library, which follows the “ROS way”.
Please try this package and convey if there are issues or improvements.

@jhdcs Thank you for lending your support! The ros2_rust client library is simple. I also found the syntax similar to rclcpp, which resulted in a smooth transition. I’m just starting with the client library. I will let you know any comments/queries if I get any.

Cheers!

1 Like

I really like this implementation. Above all, I like the integration of lazystatic. I didn’t know that before. I’m always happy when I get to know new rust functionalities.
I am interested in what the exact use case of this node is.

What I don’t like are the unsafe parts in the code. This should always be used with caution, as the RUST compiler can/should no longer help with certain errors in these areas and in this way you can intervene very efficiently and also accidentally in the behaviour of other programs.

I have also written a teleop node with rclrs. Maybe some of it will inspire you.

1 Like

Thank you for the feedback and for sharing your code. I will continue improving my code and further develop my rust skills; your implementation inspired me.

Cheers!

I would also recommend to remove the unsafe parts. The reason that the access to static mut is unsafe, is because it could be changed from any thread without proper synchronisation. However, you are not using multiple threads, you have only the main thread, so you can move all the mutable state to your main function and avoid the lazy_statics completely. Further I recommend to look into the use of enums within Rust. They are really powerful and could make your key input parsing code much more concise

2 Likes

Thank you for these valuable suggestions!
I was banging my head to find solutions to eliminate the unsafe parts.
Also, to use enums in this case is an amazing excuse for me to learn about and experiment with enums.
I will try these solutions and update if there are any queries/successes.

Cheers!