-
Notifications
You must be signed in to change notification settings - Fork 17
Creating nodes with bride
In this small tutorial you will learn how to create ROS nodes with BRIDE.
You can startup bride from your terminal by calling:
rosrun bride eclipse
Make sure you the terminal you start bride from has all the necessary ROS settings for you application. For this tutorial a standard ROS installation will be enough.
After the start of BRIDE you will be asked for a workspace directory. Choose a directory that lies in your ROS_PACKAGE_PATH.
You can now create a new project by choosing the wizard in File -> New -> Project and then choose C/C++ -> C++ Project.
In the wizard give the new project the name of the package you want to create and choose as project type "Makefile project" -> "Empty Project". In the case of the tutorial we want to create the package "talker"
Now finish the wizard and close the welcome page.
Create a new folder in the talker project called "model" by right clicking on the project in the project explorer on the left and choose New -> Folder.
Now create a new capability model by right clicking on the new folder and choosing New -> Other and then "ROS Package Diagram" in the BRIDE section. Follow the wizard by giving the RosPackage Diagram the name of the node. In the case of this tutorial "talker.ros_package_diagram". Then on the next page type make sure the name of the model is also the name of the node. In this tutorial it should be talker.ros_package. Now you can finish the wizard.
You now should have 2 new files inside the model directory and the graphical editor for your new model should be opened. Choose the "Capability Developer" perspective on the upper right area of eclipse. (the "Open Perspective" icon).
With the palette on the right you can now add a node called "talker" to the graphical plane and add a Publisher called "pub" and an ActionServer TriggerPublish as well. You should then see the following screen:
Now we have to do a few setting for the package and the nodes. Select the properties pane in the lower area of the screen. When you click in the white area of the screen you should see the package properties below. Fill them out as in the screenshot below:
Now select the publisher you created. In the property pane you now see the settings for the publisher and actionserver. The options you see in the msg drop-down menu are based on the dependencies you set in the package settings. You should therefore see the types of std_msgs in here. Fill out the settings of the publisher and actionserver as in the following screen:
Now we update the loop rate in Hz of the node by selecting the node and setting the "Loop Rate" property to 10.0. The parameter is of type string and the default value should be "HelloROS".
You are now done creating the model for the talker ros node.
You can now generate the source code of the node automatically based on the model you created. You do this by selecting BRIDE -> ROS -> "Generate C++ Code" from the menu. When you refresh your project in the project explorer by right-clicking on the project and selecting "Refresh". You should now see the complete ROS package structure in the project explorer as in the screenshot below:
To implement the actual capability code for your ROS node you have to only focus on the talker_common.cpp file in the common directory. You can open the file by double clicking it in the project explorer. The file contains protected regions you can use for your code that will not be overwritten once you regenerate the node by the tool chain.
For this example you can now go to the talker_impl class and edit the code as follows:
class talker_impl
{
/* protected region user member variables on begin */
int counter;
bool running;
/* protected region user member variables end */
public:
talker_impl()
{
/* protected region user constructor on begin */
counter = 0;
running = false;
/* protected region user constructor end */
}
void configure(talker_config config)
{
/* protected region user configure on begin */
/* protected region user configure end */
}
void update(talker_data &data, talker_config config)
{
/* protected region user update on begin */
if(running == true)
{
counter ++;
std::stringstream ss;
ss << config.word << " : " << counter;
data.out_pub.data = ss.str();
}
if(counter > 10)
running = false;
/* protected region user update end */
}
void callback_TriggerPublish_(const bride_tutorials::TriggerPublishGoalConstPtr &goal, actionlib::SimpleActionServer<bride_tutorials::TriggerPublishAction> *as_)
{
/* protected region user implementation of action callback for TriggerPublish on begin */
counter = 0;
running = true;
while(running == true)
sleep(0.1);
as_->setSucceeded();
/* protected region user implementation of action callback for TriggerPublish end */
}
};
You can now build the node by right clicking the project in the "Project Explorer" and choosing "Built Project". You can see the output of the triggered rosmake in the "Console" Pane in the lower area of BRIDE.
Congratulation you just created your first model-based ROS node.
To create another node that can listen to the talker node you should create a new C++ Project as above and call it "listener". Now again create a new folder "model" and a "New -> Other" and then "ROS Package Diagram" from the BRIDE section. Name the new diagram listener.ros_package_diagram" and the new model "listener.model". Now fill out the package property as follows:
You can now add a subscriber "sub" to the new node with the Msg type: "std_msgs::Sting". Also add a new ServiceServer and name it "TestService" and the Msg type: "std_srvs::Empty".
After generating the code out of the model you can alter the update function of the listener_impl class of the common/src/listener_common.cpp file as follows:
/* protected region user update on begin */
std::cout << "Received: " << data.in_sub << "\n";
/* protected region user update end */
You will also see a generated "callback_TestService" function you can alter as follow:
/* protected region user implementation of service callback on begin */
std::cout << "Service was called\n";
/* protected region user implementation of service callback end */
return true;
You can now build the node by right clicking the project in the "Project Explorer" and choosing "Built Project". Afterwards you have finished creating the second node. If you have problems complaining about missing header files from bride_tutorials, do a rosmake in bride_tutorials to generate the msg headers.
If you like you can now continue to the system creation tutorial.