Your First C++ MoveIt 2 Project - Part 1
PickNik’s Tyler Weaver reviews Your First C++ MoveIt Project, found here
This tutorial will step you through writing your first C++ application with MoveIt.
- If you haven’t already done so, make sure you’ve completed the steps in Getting Started.
- This tutorial assumes you understand the basics of ROS 2. To prepare yourself for this please complete the Official ROS 2 Tutorials up until “Writing a simple publisher and Subscriber (C++)”.
Transcript: Hello, and welcome to a threepart series on Getting Started with MoveIt. I am Tyler Weaver, and in this series, I’m going to walk you through a set of three tutorials to build your first project with Move. It these are new tutorials, tutorials that I wrote currently target rolling, but will target Humble.
To get there, you need to go to this website, MoveIt Picknik AI. And it will take you to this home page, which is actually the galactic version, doesn’t have these tutorials. We’ll switch to the main version, which is Brawling, and soon this will all be available on Humble, as we really symbol. First thing you have to do is go to this Getting Started page. This Getting Started page walks you through setting up your workspace and building the tutorials.
I’m not going to do this in a tutorial. I’ve already done it. It’s already set up. But follow these instructions. It should work well for you. At the end of this, there’s this tutorial on using RVs and interacting with the motion planning plugging in RVs. This is something that’s been here for a long time, but you should walk through this first. Before going on.
Now I’m gonna get you into the meat of what you came here to see. The first of them creating your first Move project. So, prerequisites you’ve already done getting started, you already have followed some of the official tutorials, so some of this stuff will look really familiar to you. Because it’s ROS coat. The first thing we’re going to do is create our package. So it says to open a terminal and source your ROS two installation. ROS two commands will work. I’m going to do that by switching over to my terminal here and there, I sourced rolling.
The next thing I’m going to do is change the source directory where we put our code and run this command. You can click on this to copy it and paste that. And it just created this new folder called Hello, MoveIt. You can see it there at the top, open in our editor. Move our editor over to a different window and we’ll go look at that later.
So this next thing it talks about is like what this command did. It set up your basic ROS package using immense CMake, created a hello move it node. The first thing we need to do is create a ROS node and executor. So I’m going to copy this code right here. I’ll paste in here and we’ll go talk through it, go source how to move it. So the first and most important thing here, just the beginning is we got to include our CLCP. That’s the ROS client library for sequels plus.
And then the second thing is we need this move group interface for Movegroup. And that’s how we’re going to interact with move. It has this node that’s called Movegroup that contains a lot of the stuff. Different behaviors that move it can do. And the planning and executing and move group interface is a C class that contains ROS interfaces but you can call those ROS interfaces usually with function calls or method calls. On the move group interface we initialize our clcpp first with the RX and RV values that are passed in. Then we got to create a node. Now we have to do this automatically declare parameters from overrides. This is because of how move it uses parameters. Just copy and paste it. It doesn’t really matter.
The next thing we do is create a logger. A logger is just a namespace in the logging. It helps when filtering logs if you’re looking for specific logs to this program. The next steps we’re going to go here. But first I want to point out that there’s this Rclcpp shutdown. It’s sort of a final method that cleans up a bunch of the stuff that got created during it. So that’s all we need for now.
Let’s go back and get some more code. It’s going to talk us through building it. I can show you that we can build it over here. Excuse see cash. But this will build fairly. Quickly. We’re waiting on this. There it goes. All right. So if we were to run it, it will run an exit without error. I can show you that. We need a source. The install here. Yeah. It doesn’t do anything right now. Just runs and exits. All right. This talks through the code a little bit more, what we did.
The next thing we got to do is we got to plan next to you using the move group node. This is the core of the tutorial. So I’m going to copy that and paste it where it says, next step goes here because of an issue with indenting. This is indented. Fix that. So we create this thing called new group interface. This is a using statement so we don’t have to type out all that. But anyway, that’s all this is. We create this thing called new group interface. The payroll and arm, that’s the group of joints, the move group that we’re going to plan and execute with. The seven joints of the arm in the robot description.
Next thing we do is we create a target pose. You’ll notice this technique here that may be new to you. You’ll see it in a lot of modern CPUs plus. What it does is it allows us to it’s an inline in place executed lambda, initializing as many eyes as you want, lambda expression, those parentheses there. So you create this lambda and then immediately execute it. And then the results, which is this message that we created, we put in this target pose. One of the big advantages to doing this is that the target plus can be cons. There’s no constructor right now for any messages, and that’s because C++ doesn’t have named parameters.
And so if you were to change the order of these or whatever the implicit parameters to be constructed might. Might be confusing to people. And so this is a more declarative or explicit way to create messages. The orientation is a quaternion. All the other values in the Quaternian, the X, Y and z are set to zero, initialized to zero. So we don’t have to initialize those, but we do have to initialize this one to one to get a unit turning. And then this is XYZ position. Everything is in meters, si units by default. And then we set a target post. So this target post is the position for the end effector.
The next that we want it to plan to do. And by default when it starts up, the starting pose is the position of the robot is in and then we ask it to plan. Here’s another one of these immediately invoked lambda expressions. And in this case we’re using structured binding to separate this success and plan variable. The plan is a message that is going to be populated. It has a trajectory and other details in it. It’s. It’s gotten through a service interface move. It will plan for you and then give you back this thing. This thing returns a type that can be cast a bull to tell you whether we succeeded or not. So I start in this okay variable and then we make a pair of okay, a message which get put into the success and plan.
And then if the plan succeeded, then I can ask move group interface the plan to execute that plan which will move the robot if it didn’t, here’s a logging statement that will log telling us that the plan failed and finally that we shut down. So that’s the whole program. Let’s go build it.
So here we are building note we’re going to use the the demo launch pi that you may have seen before. It contains all the stuff to start move proof and Rviz and all the rest of that. So this is finished. So I need to source the install and I need a separate terminal, actually, because and the reason for the second terminal I’m trying to resize my windows a little bit. The reason for the second terminal is I have to run the demo separately. The demo launch separately. 5s All right, so here’s the demo launch. We’re launching.
Rviz went here. I’m going to move Arvis display over to a new window. Where did it go? It went over here. 5s All right, so here’s our vis. I’m going make some terminal windows because of the resolution of my screen to make it. Little easier to see all of our vis. One thing about these tutorials is we can leave. Ours is running for the entirety of writing these once we get it up and going because our our program is separate and it interacts with it but isn’t the same there. All right, so here is our business is up. We’re good to go.
The next thing I want to do is run our program. So ROS to run a run our program, and then I’ll switch over to show you what it does. And there we go. It is planning. And if I turn off I’ll turn off a motion planning plug in because we’re not really using that. But yeah, there we plan to oppose. We moved. This is the end of the first of the three tutorials. I welcome you to watch the rest of them with me. Thank you.