Skip to content

Implementation of dynamic agent

Maksym Figat edited this page Jun 26, 2015 · 16 revisions

Home | Previous | Next


Dynamic agent dependencies

Dynamic agent includes the following libraries:

  • rapp_api/NaoCommunication - library that contains functions (textToSpeech, wordSpotting, captureAudio, sendEmail)
  • rapp_api/NaoVision
  • rapp_api/NaoNavigation

Structure of dynamic agent

Dynamic agent is a ROS package that contains:

  • launch - folder with launch files
  • src - folder with src
  • CMakeLists.txt
  • package.xml

Create your dynamic agent package

Let's create your first exemplary dynamic agent package

Let's create a new ROS package in workspace ws_rapp_applications_nao. Let assume that an exemplary package that will make that robot will say "My new test package".

Let's create a package with name test. It requires rapp_api package as a dependence.

cd /home/nao/ws_rapp_applications_nao/src
source /home/nao/ws_ros/install_isolated/setup.bash
catkin_create_pkg test rapp_api

Prepare package

Test package requires two new folders:

  • launch - where launch files will be held for dynamic agent
  • src - where source code will be held

Create then a launch and a src folders

cd ~/ws_rapp_applications_nao/src/test
mkdir launch
mkdir src

Edit CMakeLists.txt file

Edit your CMakelists.txt file following the instructions.

  • Give the name of for source file, e.g: test.cpp. Specify the name of binary file that will be build from a test.cpp file.
add_executable(test src/test.cpp)
  • Specify libraries that will be linked to a given target:
target_link_libraries(test ${catkin_LIBRARIES})
  • Add dependencies to a given target:
add_dependencies(test ${catkin_EXPORTED_TARGETS})
  • install targets. It will result in the emergence of required files in /home/nao/ws_rapp_applications_nao/install_isolated folder:
install(TARGETS test
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
  • Add to CMakeLists an information about the path to your launch files:
install(DIRECTORY launch/
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
  PATTERN ".svn" EXCLUDE)

The whole CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)
project(helloworld)

find_package(catkin REQUIRED COMPONENTS
  rapp_api
)

find_package(vmime)

catkin_package(
CATKIN_DEPENDS roscpp rapp_api)

include_directories(${catkin_INCLUDE_DIRS})

add_executable(helloworld src/helloworld.cpp)

target_link_libraries(helloworld ${catkin_LIBRARIES}  ${vmime_LIBRARIES} /home/nao/ws_ros_additional_packages/install_isolated/lib/libvmime.so )

add_dependencies(helloworld ${catkin_EXPORTED_TARGETS})

install(TARGETS helloworld
  RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY launch/
  DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
  PATTERN ".svn" EXCLUDE)

Edit your packages.xml file

Edit your packages.xml file following the instructions.

  • Edit version of your package:
<version>0.0.1</version>
  • Modify the description of test package:
<description>This is a test package, from rapp tutorial</description>
  • Add necessary dependencies:
<build_depend>rapp_api</build_depend>
<run_depend>rapp_api</run_depend>

The whole package.xml file:

<?xml version="1.0"?>
<package>
  <name>helloworld</name>
  <version>0.0.1</version>
  <description>Description of helloworld</description>
  <license>TODO</license>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rapp_api</build_depend>

  <run_depend>rapp_api</run_depend>
  <run_depend>roscpp</run_depend>
</package>

Create your launch file

Each dynamic package requires a launch file with a given name dynamic_agent.launch. It will be necessary for dynamically launching a dynamic agent. Let's create an above given launch file:

cd ~/ws_rapp_applications_nao/src/test/launch
touch dynamic_agent.launch

Edit your launch file. It should contain name of package that we are creating test, name of node that will be created test_node and a node type, which must be a corresponding executable with the same name test:

<launch>
    <node pkg="test" name="test_node" type="test" output="screen"/> 
</launch>

Remember that each dynamic agent that you have created should have launch file of name: dynamic_agent.launch

Write source code for your program

While writting source code for your task you can use RAPP Api functions

  • Include NaoCommunication nad DAInit libraries from rapp_api package:
#include <rapp_api/NaoCommunication.h>
#include <rapp_api/DAInit.h>
  • You need to create two instances of classes. The first one is used for sending actual status of dynamic agent to core agent. As an object da_init is initialized, core agent receives the "Init" status of dynamic agent. The second one allows using communication functions from Rapp API:
DAInit da_init(argc,argv);
NaoCommunication Nao_comm(argc,argv);
  • Set My new test package as the text to be said by Nao robot:
Nao_comm.textToSpeech("My new test package");

While main function ends, the da_init destructor sends to core agent a dynamic agent status Finished. Dynamic agent ends its work and core agent is ready to ask for other commands.

The whole source code src/test.cpp

#include <rapp_api/NaoCommunication.h>
#include <rapp_api/DAInit.h>
#include <sstream>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

main(int argc, char **argv)
{
        // Constructor for communication library.
	NaoCommunication Nao_comm(argc,argv);
        // Constructor of class which is used to share an information about a core agent status. It sends to core agent an "Init" status.
   	DAInit da_init(argc,argv);
        // It sends to core agent a "Working" status.
 	da_init.sendDAStatus("Working");
        // Setting a "Hello world" string to be spoken by Nao robot.
	string str = "Hello world";
        // Calling a RAPP Api function from communication library. Robot says the given string.
	Nao_comm.textToSpeech(str);
   
	return 0;
}

Home | Previous | Next

Clone this wiki locally