This tutorial will explore and run a simple obstacle avoidance system with a robot that moves collision-free with a laser ranger. It illustrates a simple—but realistic—example to get hands-on experience with the SmartMDSD Toolchain.
|Role||System builder, but also other roles while browsing through the system's building blocks|
|System Requirements||Virtual Machine Image Installed, see ready-to-go virtual machine|
|You will learn|| How to work with software components in the SmartMDSD Toolchain
About the file structure of software components in the toolchain
How the laser obstacle avoid algorithm works
How to modify and rebuild a component at the source code level
This tutorial will guide you in understading simple application for laser-based obstacle avoidance in simulation. We will explore the software component and implemented algorithm in the SmartMDSD Toolchain to get hands-on experience. You will learn:
We will use an already existing software component project “ComponentLaserObstacleAvoid” as well as the system project “SystemLaserObstacleAvoidP3dxPlayerStageSimulator”.
Please see one of the next tutorials to learn how to create a component and system on your own.
Before we start the system, we will take a look at the architecture.
First, open the project if necessary: Right-click on “SystemLaserObstacleAvoidP3dxPlayerStageSimulator” in the “Project Explorer” and select “Open Project”.
Open the Component Architecture to explore the system. It is named SystemLaserObstacleAvoidP3dxPlayerStageSimulatorComponentArchitecture. There are two ways to open the Component Architecture. Double click one of the highligted entries as indicated in the below figure:
As you can see in the below picture, the system contains the two components: one to represent the simulator and one for obstacle avoidance. Both components provide or require services. Two pairs of component ports are connected. The obstacle avoidance component will receive laser scans from the simulated robot, calculate commands, and provide/send them as navigation velocity commands to the simulated robot.
We will later explore and modify the obstacle avoidance algorithm.
To run the system, we need to deploy it and run the components.
Deploying copies/transfers the system and all necessary parts to the target machine. In this case it is the local computer or virtual machine guest system. Right-click on the system project and select SmartMDSD Build Tools → Deploy
The system is now ready to start and you will be asked to execute it. Note that there are other ways to execute a deployed system, e.g. on a remote robot.
Choose yes in the popup dialogue to start the system. A terminal window will open and show the scenario control menu:
Choose menu-start to start the scenario. Further terminals open automatically. One per component and one additional window for the naming service. Note that they may not be visibile initally in case they overlap.
You have to select a environment for the simulated robot. In the window with red font, choose a world number, e.g. 0 (Hospital world) and press enter.
Now, all software components and the simulator start running. You will see the GUI of the simulator showing the robot moving around in the hospital world:
To stop the simulation and all components, select the following options in the scenario control window/menu :
All components and the simulator will shut down managed by the components shutdown procedure. Only one window will stay open. Do not close any window manually, except the last one that remains open and will ask you to close it manually.
To better understand the components in this scenario, we will explore the software component ComponentLaserObstacleAvoid. We will inspect it at the model and source code level. We will run the build process from model transformation, code generation, and compilation and test it in our system.
Open the software component model by double clicking one of the entries highlighted in the below image:
The model of the obstacle avoidance component looks as follows:
The component has one activity named as RobotTask which is connected to two component ports. One port is an input port for the laser service LaserServiceIn. The other port is output port for NavigationVelocityServiceOut. Click on a port and open the properties view to see its details as shown in the below figure. This port realizes the service definition ForkingServiceDefinition LaserService.
The algorithm calculates movements based on the laser scan and provides these movements as navigation velocities to command the robot. Open the output port properties, and you can see it realizes JoiningServiceDefinition NavigationVelocityService.
This algorithm is implemented in an activity. Its model representative is the RobotTask. To Open the source code of the RobotTask, open the file /ComponentLaserObstacleAvoid/smartsoft/src/RobotTask.cc. The method RobotTask::on_execute() holds the implementation of the algorithm. It first receives laser scans,then calculates new navigation commands and finally sends them to the robot base.
Now read through the source code to understand the algorithm. Not how the algorithm received scans from the component port and provides the result to the component port.
You may now modify the source code and enhance the algorithm or you may remove the implementation and use this component to work on the exercises.
The following figure describes the relation of the ports and activity of the component model to the source code that implements the algorithm in the RobotTask.
After modifying the source code, you need to compile the component:
To test your improved component you need to deploy and run the system project where this component is included. You have learned how to do this in the first part of the tutorial.
Please proceed with next tutorial (A More Complex System using the Flexible Navigation Stack) to have a look on a more complex system. You can also then check further tutorials for learning “how to develop your own Component and System”.