Robotiq Open-Source C++ SDK for Adaptive Grippers - Quick Start
Robotiq · Uploaded · 32:35 · Watch on YouTube
Robotiq engineer Benoit continues his C++ quick start, showing how to connect to an adaptive gripper over a serial port and activate it. He then walks through building a gripper command, reading status bytes, and using wait-for helpers to confirm the gripper reaches its target.
Transcript
Captions as a .vtt fileEmbed with the transcript
- 0:00Hello everyone, my name is Benoit. I'm a Physical Engineer for Physical AI at Robotic
- 0:06and in this video I'm going to give you a quick start on our C++ library to control
- 0:12robotic adaptive grippers. So let's get started. In the previous video we set up the environment
- 0:19to compile the C++ code. Now we are actually going to use the different function of the C++
- 0:26library to control the robotic adaptive grippers. So let's access again to the
- 0:34C++ library documentation from the GitHub of Robotic. I'm going to select the C++ tool here
- 0:42and access the documentation. We are going to check the introduction guides and we are going
- 0:49now to review the quick start guide. Okay, so on the right I have a VS code with my main.cpp
- 1:00file currently open. So this is a hello world code from the previous video. So we are going to modify
- 1:08that and actually implement some function of the C++ library. So following the quick start guide,
- 1:18first I'm going to place the dependency. We are going to include the different dependencies. So we
- 1:27have obviously the dependency for the robotic gripper library. We also add the IO stream library to display
- 1:38a few things in the terminal for demo purpose. We also have here a library called chrono. It's used to
- 1:47to set some time variable in the program. So in the main I'm going to remove the hello world
- 1:58that we did previously. So first of all, before we create a gripper object and we start, we make the gripper move,
- 2:06we need to establish the connection with the gripper. So to do that we need to provide, to retrieve the serial
- 2:14port name on which is connected the gripper. And we will retrieve it from the terminal in this example.
- 2:23So that will be an exact variable, an argument that is provided when we call the executable in the terminal.
- 2:34So in the main function, we are going to retrieve the arguments like this.
- 2:43So we will check that one argument is provided, at least one argument is provided when the executable
- 3:01is launched. And so this single argument will be the comport. So this is a little check here to see if we
- 3:10have one argument that has been passed. And if it's not here, we will display a message saying
- 3:17that the comport is missing. So then we are going to create
- 3:26a connection config object to define the connection with the gripper.
- 3:34So in the robotic space name, I will create, select the class connection config and create
- 3:47a connection config object like this. And then I will set some parameters on this object.
- 3:56So the serial port, I will set it to the argument we retrieve from the terminal like this.
- 4:16Actually, you can use tools like VS Code to check what you have in the different objects. So for
- 4:25example, in the connection config, like you can see, you can set the modbus slave ID address.
- 4:35You can set also the serial object so that we reset just previously. You can set the connection
- 4:42frequency. If you check the serial object, you can see that you can adjust the board rate, the latency
- 4:50timer. You can adjust the port that we set previously here and the timeout. So it's a good way to navigate
- 4:58through object and see what you can do. You can also check the related documentation. Easy way is to
- 5:06check the global index here. For example, I'm going to check the documentation for the connection config.
- 5:14And here I have a description. I have an example about the different parameters I can set for the connection configuration.
- 5:24And I have also the description of the different functions here, the different parameters.
- 5:33So I'm going to build this example like this and just execute the file that have been compiled.
- 6:02So the file actually is named quickstart.exe. So the cmake list have been adjusted. Here we change the name from
- 6:16yourhop to quickstart.exe. So quickstart.exe has been created. I'm going to execute that. So you see, I didn't
- 6:30give the comp port. So I get the error message telling me that there is a missing argument. And now I'm going to
- 6:39pass like comp port 4. And so it executes without any error. So this configuration, this connection
- 6:51is working is working. And so we can continue with the programming. So yeah, so now next step is to
- 7:05create our gripper object. So I'm going back to the quickstart guide. And we are going to create the
- 7:14the gripper object. So we are going to use in the robotic space name, we are going to use the gripper class.
- 7:26And we are going to create an object called gripper. And we are going to construct this
- 7:35this gripper object using the connection config that we created previously like this.
- 7:43So before we start playing with the gripper object and try to make the gripper move,
- 7:50I'm going to explain you a little bit how things are working and how you control the gripper
- 7:56through the gripper object. So let's check the documentation. So there is a how it works
- 8:05document that that you can check to familiarize yourself with the gripper object. So here is how it
- 8:12works. So the gripper object is the object that we communicate with the gripper. So it handles all
- 8:21the mode burst communication. So you don't need to worry about it. So the way you control the gripper
- 8:31is through the gripper object is like this. So you send command to the gripper object, or you retrieve
- 8:39status from the gripper object. So you will ask for the, for example, to the gripper, like move at a
- 8:44given position with a given speed. And the gripper will answer you from its status, like I am here at this
- 8:54position, moving toward the target. I am at the target. The motion is complete. So it's a, it's kind of the
- 9:03dialogue with the gripper object. So there is also some free function around the gripper object
- 9:15that help you to do some particular actions. And those functions are the activate function. The job of the
- 9:28activation function is to activate the gripper. So the gripper will make a full close, full open to
- 9:36find its extreme position. There is also a free function called recover from fault. This function
- 9:46will clear the fault that you have on the gripper and if necessary, redo the activation.
- 9:56So those functions are free functions, not part of the gripper object,
- 10:00but available to perform some specific tasks. So I will also give you some explanation about
- 10:12what is a command, what do you have in a command, and also what kind of information you can get from
- 10:18the status. All of this is well documented as well in the gripper manual. So I invite you to use the manual
- 10:26as a reference to see how you can control and how you can get the status of the gripper. So here is what
- 10:36you have in a command. In a command you have six bytes of eight bits and so each byte have a specific
- 10:47function. So the first byte here is called action request and inside this byte there are several bits.
- 10:56that have a specific function. So you can see here the details and here the description. So
- 11:07for example, you will find the byte air act for activate, you have the byte go to, you have the
- 11:16byte for the auto release and so on. So this is like to perform specific, to trigger specific function of the
- 11:28the gripper. You then have a byte for the position request. So it's just the position you want the
- 11:36gripper to move from zero to 255. Then you have the speed of the gripper from zero to 255 and the force
- 11:44same from zero to 255. So this is what you have in a command. And you have some examples here on how to build a command.
- 12:01So you create a command. For example, if you want to set some bits in the action byte, you can write
- 12:13like command dot action and set specific bits inside the action byte using the set command function.
- 12:28So here for example, in the action byte, I'm setting the bit activate to true.
- 12:40Then there is here the go to byte that is set to true.
- 12:48So that's what you have in the command. Then for the status, the status is also made of six bytes.
- 13:03Each byte is made of eight bits. The first byte is the gripper status. Here also it's a packed byte.
- 13:14There are several bits inside with specific information. In the same way, you have the false status that is also a packed byte,
- 13:32where there are some bits with specific information. Then you have the position request echo.
- 13:42So actually this is a gripper that just tells you that he received the position request you give to him.
- 13:53So he acknowledges that he tells you that he received the position request properly.
- 14:04Then there is a position register. So this is the current position of the finger.
- 14:11And you can also retrieve the current. So here also in the documentation,
- 14:18you find some examples about information you can retrieve from the status.
- 14:25We spoke just before about the free function around the gripper object with activate and recover from faults.
- 14:34There is also one free function that is quite useful. It's called wait for.
- 14:43So wait for is just here to wait for a given, for a certain condition of the gripper.
- 14:53So for example, you can wait for the gripper to acknowledge the position request you just sent to him.
- 15:03You can wait for the gripper to reach its target position. We are going to use it in our program.
- 15:12So now we have our gripper object. We know how to work with it. We know that we can send command to the gripper, retrieve status.
- 15:21We know there are some free functions around the gripper object, like the activate function, the retrieve fold function and the wait function.
- 15:32So let's use all of this to actually operate the gripper. So first thing we will do is to activate the gripper using the free function activate.
- 15:44We give him the gripper object as argument. I'm going to save that and just press on play.
- 16:03So you see the gripper perform the activation. You may notice that if I start the program again, nothing happened.
- 16:13Actually, it's because the gripper is already activated. So if the gripper is already activated, the activate function just does nothing.
- 16:25There is nothing to do. The gripper is already activated.
- 16:30So now we are going to build a command and send it to the gripper. So we will request the gripper to move at a certain position.
- 16:39So let's create a gripper command object. So we call this command and we will set this command
- 16:58with the default command. So you can access the default command from the gripper command object like this.
- 17:17And so we are going to set the different parameters from the command. So what we want here is that we want the
- 17:27the gripper to move at the position that we will set in the command. So to do that, we need to have the
- 17:35goto byte of the gripper set to one. So in the command action byte, we are going to set the goto bit to one.
- 17:50So let's do that. I'm in the command. I'm setting in the action bytes. I'm setting the the byte
- 18:05called robotic action action request bytes. Go to. So you see here, I have
- 18:22the different bits that I can set inside the action bytes. So here I'm just setting the goto byte to one.
- 18:39So the set function, actually, you can pass a second argument like set true or false. But actually,
- 18:52if you don't provide any argument, set will will set the byte to true by default. So here I don't
- 19:00precise the second argument. I want just this to be to true to one. Okay, then I'm going to set
- 19:09the position request byte. And I will set the position 100. Then we are going to set the speed byte.
- 19:22And we are going to ask for the maximum speed 255. And we will also ask the force byte to be at 255.
- 19:40Okay, so we have our command that is ready to be sent to our gripper object. And now we are going to
- 19:48send it to our gripper object using the set command function of the gripper object. So
- 19:53let's do that. So let's do that. So gripper dot set command. And I'm going to pass the command we just
- 20:02previously created like this. So now we prepare the command and we send it to the gripper. If you execute
- 20:20this code like this, you notice that nothing happened. The gripper did not move to the position 100.
- 20:30And actually, it's normal. The thing is that in this program, we request the gripper to go at position 100.
- 20:38We send it to the gripper object. We send it to the gripper object, but then the program complete
- 20:44even before the gripper object had the opportunity to communicate this command to the gripper.
- 20:51So we need to wait for the gripper to acknowledge you receive the command
- 21:00and wait for the command to complete before we actually close the
- 21:08the program. So we are going to use the wait for function to wait for three things. So first,
- 21:14we are going to wait for the gripper to acknowledge you receive the
- 21:19the position request. Then we wait for the gripper to move. And finally, we will wait for the gripper to
- 21:27reach its final destination. So let's do that. So I'm going to use the
- 21:35wait for function that is in the robotic namespace. So this function takes
- 21:46two arguments like your predicate. So this is a condition that we are waiting for. So we are waiting
- 21:53for first for the gripper to acknowledge he received the position request. And so the second argument is a
- 22:02a timeout. So for the condition you use you set the condition with the nabla function.
- 22:14So we are going to check the gripper status.
- 22:21So I'm using the getStatus function of the gripper object.
- 22:26So in the retrieve status, I'm going to check the byte position request echo.
- 22:38So I want the position request echo to be equal to the position request that is in the command that we
- 22:49we send to the gripper. Like this. And we are going to make a timeout of let's say like one second.
- 23:14So then we are going to wait for the gripper to to be actually moving. So once again I'm using the
- 23:24I forget the semicolon here. I'm going to use the wait for function again. And this time
- 23:38we are going to wait for the gripper to be moving. And you can check that by looking at the
- 23:47the object detection byte in the gripper status. So here we retrieve once again the gripper status.
- 24:02We'll check the gripper status byte and and we are going to check the object
- 24:11detection. So we want the object detection tell you if you if you detect an object but it also tell you
- 24:21if the gripper if the gripper is actually moving toward its target. So we are here we retrieve the object detection
- 24:34information and so we are going to check that the the object detection is actually at the status gripper moving.
- 24:47So you can see the different value that I can take the object detection
- 24:56using the object detection enum. Here we we want to check that the gripper is moving. Then we set timeouts
- 25:20say once again once again. And finally
- 25:24So I'm going to enlarge here. Finally
- 25:30We are going to wait for the gripper to reach its final destination. So wait for
- 25:43Nabla function. We are going to wait for the the gripper object detection status to be
- 25:57like a gripper at final position. So I retrieve the gripper status
- 26:05I'm going to check the gripper status
- 26:09bytes and
- 26:12retrieve the information
- 26:14object detection once again
- 26:19and I'm going to check that it's
- 26:22equal to
- 26:24the
- 26:26the enum like
- 26:31at requested position
- 26:33like this
- 26:40Okay, and we set the timeout once again at one second. Okay
- 26:53So
- 26:55we have everything in place
- 26:57so we can now execute the code. So we are going to
- 27:01wait for the gripper to acknowledge
- 27:04that he received the the position request. We are going to wait for the gripper to be moving
- 27:11and finally we are going to wait
- 27:15for the gripper to reach its final destination. So let's play this program
- 27:24and you can see that the the gripper
- 27:27effectively went to the position 100.
- 27:30we could modify this
- 27:34put position like 50
- 27:37and execute
- 27:40and you see the gripper it's at position 50.
- 27:43To conclude this introduction to the robotic
- 27:46C++ library for adaptive grippers
- 27:50we are going to retrieve
- 27:52some piece of information from the gripper status. So we are going to retrieve the
- 27:57actual position of the gripper and display it in the terminal. So let's do that.
- 28:03So first
- 28:04we are going to
- 28:06retrieve the current position
- 28:08so let's create a variable current position
- 28:15so this will be equal to
- 28:20the gripper
- 28:22current position in this in the gripper status. So I'm retrieving the the status of the gripper
- 28:28with the gate status function and then from the status I'm going to
- 28:34retrieve the position byte. So if you go over position you will see that the the type of position
- 28:49the position parameter is a unsight int 8. Here I put auto for the
- 28:58for the type but I can specify precisely this type here
- 29:07u8
- 29:17unsight int
- 29:19coded on 8 bytes
- 29:22that's it. So I have the current position here and we are going to display it
- 29:26in the terminal using the stdout function like this. We are going to use the
- 29:55static cast function here to convert
- 30:02the unsight int variable into something we can actually print in the terminal.
- 30:20and here we are. So
- 30:23I'm going to change the position back to 100
- 30:30and execute. So the gripper move to position 100. I can see like the current position is 101.
- 30:44Okay, let's execute it again. I can see that now the position is 100.
- 30:53So this is how you retrieve information from the the status of the gripper.
- 31:02So we've completed the the this introduction to the robotics C++ library to control adaptive grippers.
- 31:11So as you see, so it goes like this. You create your connection.
- 31:19With the connection, you object, you create the gripper object.
- 31:24You activate the gripper and you feed some command to the gripper and retrieve status
- 31:31to control the gripper the way you want.
- 31:36So yeah, we send the command. We wait for the command to to be received.
- 31:42We wait for the command to be fully executed.
- 31:48Then we can retrieve other status like to check the current position,
- 31:54check if there is an object detected and so on.
- 31:57The C++ library is in continuous development.
- 32:02So you can expect to see in the future some more functions coming.
- 32:08Probably free function, a little bit like activate or retrieve from fault.
- 32:17So we probably will have a free function
- 32:21like move to to move the gripper to a given position.
- 32:24So stay tuned. Thank you.
Discussion
A mail when somebody comments. No account needed.
The newsletter
Get our free newsletter with new robots, prices and robotics news.