Skip to content

[B] Create a simple ROS Package

Jan edited this page May 13, 2016 · 1 revision

This tutorial will walk you through the first steps of creating a catkin package that uses the Youbot Controller API.

First change to a directory where you want to create your package.

$ cd ~/catkin_ws/src/sandbox

Then create a package named e.g. ''my_youbot_pkg'' with dependencies on ''roscpp'' and ''luh_youbot_controller_api''.

$ catkin_create_pkg my_youbot_pkg roscpp luh_youbot_controller_api

Create a source file.

$ touch my_youbot_pkg/src/my_youbot_node.cpp

Paste the following code to ''my_youbot_node.cpp'' file.

#include `<ros/ros.h>`
#include `<luh_youbot_controller_api/controller_api.h>`

using namespace youbot_api;

int main(int argc, char** argv)
{
    // initialise ROS
    ros::init(argc, argv, "move_arm");
    ros::NodeHandle node_handle;

    // Initialise arm
    YoubotArm arm;
    arm.init(node_handle);

    // Move arm to ARM_UP pose
    arm.moveToPose("ARM_UP");
    arm.waitForCurrentAction();

    // Move arm back to HOME pose
    arm.moveToPose("HOME");
    arm.waitForCurrentAction();

    return 0;
}

Now configure your ''CMakeLists.txt'' file.

In the Build section add the executable and link the catkin libraries:

add_executable(my_youbot_node src/my_youbot_node.cpp)

target_link_libraries(my_youbot_node
    ${catkin_LIBRARIES}
)

Now build your package.

$ cd ~/catkin_ws
$ catkin_make

That's it. Follow the next tutorial to learn how to launch your node.