Hands On ROS: ROS2 Version

It may be a long time before anyone else tries following “Hands-On ROS For Robotics Programming” using ROS2.

Nevertheless, I have put my

  • Desktop “ROS2 Migration” and “Pythonic ROS2 Migration” versions
  • Learning process: NOTES.txt (in directory with the nodes)
  • Useful ROS2 commands and concepts: ROS2_Basics.txt
  • ROS1_TO_ROS2_MIGRATION_GUIDE: collected techniques for migrating
     

here:

Only Chapter3_ROS_basics done so far.

2 Likes

NOTE: One of my complaints about ROS logging is the timestamp. It is a giant number of seconds with giant precision that is only useful after copying two of them into a calculator.

This is my helper function for adding local date-time to log strings:

import datetime as dt

# add_dt(str) - prepends datetime "[YYYY-MM-DD HH:MM:SS]" to str
def add_dt(str):
  new_str = dt.datetime.now().strftime('[%Y-%m-%d %H:%M:%S] ') + str
  return new_str```
$ ros2 run chapter3_ros2_basics log_w_dt 
[INFO] [1624812324.155095487] [log_w_dt]: [2021-06-27 12:45:24] Created log_w_dt node
[INFO] [1624812324.646024785] [log_w_dt]: [2021-06-27 12:45:24] Publishing: 0
[INFO] [1624812325.146772983] [log_w_dt]: [2021-06-27 12:45:25] Publishing: 1  
...  
^C[INFO] [1624812327.262942489] [log_w_dt]: [2021-06-27 12:45:27] control-c: log_w_dt shutting down
2 Likes

So in your ROS programs are you doing something like rospy.loginfo(add_dt(‘message_string’))?

You could write it as a separate module and then import it into your various programs.

/K

1 Like

That’s what I want to get to, but don’t know how. This is only logging to the console window of the node I start in that window.

self.get_logger().info(add_dt('Created log_w_dt node'))

but I created ~/handsonros2/my_logs/
and export ROS_LOG_DIR=~/handsonros2/my_logs
and then I get:

$ more my_logs/python3_2666_1624820273651.log
[INFO] [1624820273.689154073] [log_w_dt]: [2021-06-27 14:57:53] Created log_w_dt node
[INFO] [1624820274.182112446] [log_w_dt]: [2021-06-27 14:57:54] Publishing: 0
[INFO] [1624820274.683068196] [log_w_dt]: [2021-06-27 14:57:54] Publishing: 1
[INFO] [1624820275.183090116] [log_w_dt]: [2021-06-27 14:57:55] Publishing: 2
[INFO] [1624820275.682199611] [log_w_dt]: [2021-06-27 14:57:55] Publishing: 3
[INFO] [1624820275.744985491] [log_w_dt]: [2021-06-27 14:57:55] control-c: log_w_dt shutting down
ubuntu@rosdesk:~/handsonros2$ 

2 Likes

I’m not solid on python modules either. But it the program file is in the same directory as the other scripts, I know you can import the function - I’ve done that before. Not as good as just having it universally available, but not too cumbersome. This is a short function, so just cutting-and-pasting it locally isn’t hard to manage, but for longer functions that gets tedious.

I didn’t realize you could designate a directory for ROS log files. Good to know.
/K

2 Likes

yes putting with the nodes allowed building with no errors, but it doesn’t get moved to the local site-package automatically so it fails when trying to run it.

I’m sure I will figure how to manage imports in ROS2 with a little more google-time. It seems like there’s multiple strategies.

3 Likes

Uggh! This is crazy. I’m in so far over my head. Crazy me thinking “With Google, I can do anything”

Yes, I can create a mess.

  • When I was a kid, I was able to tear things apart.
  • As I got older, I was able to put stuff back together with a few “I don’t know where this goes”.
  • After a few years of OJT, sometimes stuff would actually work.
  • After retiring, I can create stuff from other people’s parts that almost works…
    but nobody can help because it’s my baby, and:
Well, it's a '49, '50, '51, '52, '53, '54, '55, '56
'57, '58' 59' [robot]
It's a '60, '61, '62, '63, '64, '65, '66, '67
'68, '69, '70 [GoPiGo]

 
Johnny Cash: “One Piece At A Time”

2 Likes

What this is about:

https://answers.ros.org/question/381403/ros2-urdf-not-copied-to-install-folder/

2 Likes

:laughing:

I used to do that with VW beetles back in my college days. My dad an I would buy up junkers that nobody else wanted and cobble together cars that worked.

I named them too because they had character.

My favorite was “The Motley Crew” - every part was from a different model year!

2 Likes

And I’m feeling like a cave-man working on the battery’s meter while you guys whip-up fancy robots with spinning LIDAR auto-mapping and embedded cyclotrons looking for the Higgs Boson with Python scripts to filter out noise.

:sob:

That’ll teach me to mess with my betters!

1 Like

Yikes - I looked at your question and could barely follow it. I think I’ll definitely work on getting things going well in ROS1 before jumping to ROS2.
/K

PS - I had actually never heard that song before. It’s hilarious.

2 Likes

Proof that I am totally crazy! I figured it out myself though - It turned out I needed a further mod to the CMakeLists.txt to install the urdf/ files.

I’ve got it “happily” launching

  • robot_joint_publisher
  • robot_state_publisher
  • rviz2 with the model
     

but complaining about no transforms from map to base_link,
and the wheels are in the center of the model for some reason.

I’m definitely getting closer, but the going is really, really crawling on the floor in the dark.

2 Likes

I really should have just been satisfied to “follow someone that knows” and done ROS1. I wanted to be “up with the latest” and that meant either

  • buying turtlebot3 burger which is already ROS2-ified, and knowing nothing about the platform,

or

  • buying a second GoPiGo3 that I have invested 5 years in, and creating ROS2-GoPiGo3.
     

(It is interesting that @brjapon disappeared from this forum in April after publishing the book, and disappeared from Twitter mid-December 2020. Packt publishing gave me a like when I responded to ROS.org asking “What’s holding you back from ROS2?” with “A ROS2 version of HandsOn ROS For Robotics Programming”, but I really can’t expect anything more from them.)

2 Likes

I’m delighted that you are trailblazing. Too bad about @brjapon. I’d certainly buy a second version of the book just to support the work, but just a good github repository would be fine.

CMakeLists.txt is definitely one of the things I’m weak on. Since I program almost exclusively in Python, I find make files daunting.
/K

2 Likes

That’s what I would have done, if for no other reason than to verify that the models are correct and get a platform working.

However, nobody’s ever accused either of us of being sane.

I dive right into creating an interactive web controller for the 'bot, thinking “how difficult can that possibly be?”

You dive into ROS-2 because ROS-1 is already a cinch!

We both crash-and-burn - but we get up, keep going, and learn a LOT in the process.

Thumbs up and keep the faith!
:+1:

2 Likes

Making some progress on Chap 4 Rviz Basics.

I created my own “minimal GoPiGo3” URDF file and finally got the joint_state_publisher happy (not sure what, why, or how, but it stopped complaining and started broadcasting something the robot_state_publisher wants.

Next have to figure out how to get the joint_state_publisher_gui to show up.

Also my launch file doesn’t support the book’s parameters and arguments yet.

Here is so far:

2 Likes

Wow - that is real progress.
On a side note, and I suspect you know this already, but on the off chance you don’t. You can close the Views window on the right side. I think you can un-check it in the Panels menu, or just click the tiny arrow on the right side of the image window. For me it gives more space for the image, and I’ve never changed the views (other than just playing around to look at the options). But others must use it or it wouldn’t be there.
/K

2 Likes

Chapter 4 Rviz2 Basics “migrated to ROS2”, as best I can do, is now final.

SUMMARY OF CHAPTER 4 MIGRATION:

  • ROS2 has made launch files quite complex turning a 10 line XML file into 60 lines of python
  • ROS2 has made ROS1 launch arguments and parameters difficult or impossible
  • ROS2 joint_state_publisher no longer supports use_gui parameter, use joint_state_publisher_gui
  • Made separate launch files rather than passing args and parms
  • Created gpgMin.pdf which more closely models GoPiGo3 body, caster and wheel sizes and positions
2 Likes

(Shaking head)

I know that I have absolutely no right to an opinion, but one thing strikes me:

It shouldn’t be that complicated.

Given the list above, and the other things you’ve mentioned, I see two possible conclusions:

  1. There is some fundamental idea or library that simplifies everything, (as in easygopigo), that you’ve missed.

  2. The people who developed ROS-2 are a bunch of idiot wankers who have no 'naffing clue - and have completely lost sight of The Tao of Programming by making things considerably more complex than necessary.

I also wonder if they deliberately decided to cut their entire user-base off at the knees by completely destroying any possibility of code migration or backwards compatibility? :roll_eyes: :crazy_face:

Makes no sense to me.

@KeithW,
Maybe you know something I, (we?) don’t?

1 Like

There is a third: ROS1 was too simplified and slow (in the distributed agent communication capability) so they upped the complexity to meet the next-gen robotic sense, command and control, abandoning backward compatibility to allow unlimited creative license.

They did provide something they call the “ROS1 Bridge” that will link a set of bots running ROS1 to coexist with ROS2 bots, but even that is not high priority versus creating the new ROS2 features.

2 Likes