23 May 2015
In this tutorial you will be learning about writing a post for robocomp. I assume that you are already familiar with contributing via Github if you are not then you can follow this article.
switch to gh-pages
branch
You can do this via github client or on the command line by navigating to the directory and executing the command
After checking out to the github pages branch in your navigate to the _posts
directory. Here you will find all the posts.
To write a new post. Create a new file and save it as XYZ.md
Note that you will be using Github markdown language.
Once you save the file as XYZ.md
. It will be saved as draft and not published on to the website.
At the header of every article/post you write. Always add this
Layout can be post
, page
or default
. Always set the layout as post
. The title is the title of the post. Categories and Tags should be set accoridingly whichever is applicable. This is helpful in navigating or finding posts on same topic. Description is a short explanation or gist of the entire post.
A sample header looks like this.
---
layout: post
title: Write a post for robocomp, A step by step guide.
---
After adding the header you can proceed writing the post by using Github Markdown language. Now for the most important step. To publish the post or to change the post from draft to final you will have to rename the file to
Commit and push it to the repo, you would have successfully published a post on to the robocomp’s website.
23 May 2015
We will create now a new component that will connect to the RCIS simulator and run a simple controller for the robot, using the laser data. First we need to install the DSLEditor software that is runtime Eclipse application.
Create another terminal in Yakuake and type:
cd ~/robocomp/tools
python fetch_DSLEditor.py
Select 32 or 64 bits according to your current linux installation. After a little while the DSLEditor will be installed under the robocompDSL directory:
cd roboCompDSL/DSLEditor
./DSLEditor
Check that you have a RoboComp tab in the upper bar of the DSLEditor window and that the robocomp directory appears in the Project Explorer (left panel). If it does not, right click inside the Project Explorer panel and select import. Then select General and then Existing Projects into Workspace. Then select your robocomp directory and push Finish.
Now we need to bring up some handy tabs in the lower pane. Select the Window tab in the upper bar, then Show View, then Other and again Other. Select now Interfaces and double-click on it. Go back to the main window.
Now, in the left panel, unfold the robocomp directory down to robocomp/components/ and then click on it with the right button. Select New Folder and enter mycomponents in the folder name. Do it again to create a new folder inside mycomponents named myfirstcomp. Select myfirstcomp and then click on the RoboComp tab in the upper bar of the main window. Select Create CDSL file and fill the requested name with MyFirstComp.cdsl
The new file will open inside a syntax-sensitive editor in the central panel. Ctrl-space gives you syntactically correct options. You can see the skeleton of a new empty component. Look for the tab Interfaces in the lower bar and select DifferentialRobot.idsl. Click on the green cross at the right of the bar to include it and accept when prompted in a pop-up window. You will see something like:
import "/robocomp/interfaces/IDSLs/DifferentialRobot.idsl";
Component PFLocalizerComp{
Communications{
};
language Cpp;
};
Repeat the same steps to include Laser.idsl and then add a requires statement inside de Communications section. The file now should look like this:
import "/robocomp/interfaces/IDSLs/DifferentialRobot.idsl";
import "/robocomp/interfaces/IDSLs/Laser.idsl";
Component MyFirstComp{
Communications{
requires DifferentialRobot, Laser;
};
language Cpp;
};
Save the file and click in the upper bar on the RoboComp tab. Select Generate Code. After a little while the new source tree for your MyFirstComp component will be created. You can go back now to Yakuake and create a new tab to compile it. Then:
cd ~/robocomp/components/mycomponents/myfirstcomp
cmake .
make
bin/myfirstcomp --Ice.Config=etc/generic_config
and there it is! your component is running.
What! Dissapointed? Yeah, I know it does nothing, but it runs and it is yours! Now let’s do some real programming.
Stop the component with Ctrl Z and then type:
Now start your favorite IDE. KDevelop will do it just fine and you have it already installed. Open it in another tab, from Ubuntu menu or with Alt-F2. Then:
Click the *Project* tab in the upper bar
Select *Open/Import Project*
Navigate to ~/robocomp/components/mycomponents/myfirstcomp
Select *Makefile* and open the project
In the Project panel to the left of the screen, navigate to src and there select specificworker.cpp and open it. Open also specificworker.h
Now replace the empty void compute() method with this compact version of the classic AVOID-FORWARD-STOP architecture proposed by R. Brooks in the late 80’s:
void SpecificWorker::compute( )
{
static float rot = 0.1f; // rads/sec
static float adv = 100.f; // mm/sec
static float turnSwitch = 1;
const float advIncLow = 0.8; // mm/sec
const float advIncHigh = 2.f; // mm/sec
const float rotInc = 0.25; // rads/sec
const float rotMax = 0.4; // rads/sec
const float advMax = 200; // milimetres/sec
const float distThreshold = 500; // milimetres
try
{
RoboCompLaser::TLaserData ldata = laser_proxy->getLaserData();
std::sort( ldata.begin(), ldata.end(), [](RoboCompLaser::TData a, RoboCompLaser::TData b){ return a.dist < b.dist; }) ;
if( ldata.front().dist < distThreshold)
{
adv = adv * advIncLow;
rot = rot + turnSwitch * rotInc;
if( rot < -rotMax) rot = -rotMax;
if( rot > rotMax) rot = rotMax;
differentialrobot_proxy->setSpeedBase(adv, rot);
}
else
{
adv = adv * advIncHigh;
if( adv > advMax) adv = advMax;
rot = 0.f;
differentialrobot_proxy->setSpeedBase(adv, 0.f);
turnSwitch = -turnSwitch;
}
}
catch(const Ice::Exception &ex)
{
std::cout << ex << std::endl;
}
}
To compile the fancy version of std::sort you will have to first add this line at the end of the file CMakeListsSpecific.txt located in the same src directory:
ADD_DEFINITIONS( -std=c++11 )
and then type:
Hereafter, Press F8 in KDevelop to compile and link. Then, go to Yakuake and restart the component.
Let us take InnerModel simpleworld.xml as an example. Open a new tab in Yakuake and execute
cd robocomp/files/innermodel
rcis simpleworld.xml
Now you should see 2 windows. Now in Yakuake go back to tab where you had compiled myfirstcomp and run
bin/myfirstcomp --Ice.Config=etc/generic_config
You should see the robot maneouvring aroung the box. Now is when Robotics begin! Try to modify the code to let the robot go pass the blocking boxes.
23 May 2015
If you haven’t already, Then do read about aprilTagsComp here for better understanding. In this tutorial you will learn the actual functionality of apriltags.
First make sure you have installed apriltags. Please follow the steps that is given in INSTALL_APRILTAGS_LIB.TXT. Then move to the apriltagscomp folder
cd ~/robocomp/components/robocomp-robolab/components/apriltagsComp
Compile by executing
Now that you have compiled the component and have the binary generated. Open a new tab in yakuake or terminal and execute
cd robocomp/files/innermodel
rcis simpleworld.xml
Here we will considering simpleworld.xml as an example since it has virtual apriltags and a robot with a camera is present for simulation. After execution you should now see two windows, One showing the robot camera’s view pointing at one of the apriltags and the other with the site map showing the robot and two virtual apriltags.
Now go back to the terminal where you had compiled the apriltagsComp and execute
bin/apriltagscomp --Ice.Config=etc/generic_config
You should now see the following output.
user@username:~/robocomp/components/robocomp-robolab/components/apriltagsComp$ bin/apriltagscomp --Ice.Config=etc/generic_config
[/home/username/robocomp/classes/rapplication/rapplication.cpp]: Loading [camera:tcp -h localhost -p 10001] proxy at 'CameraProxy'...
18:20:19:421::Info::apriltagscomp.cpp::139::/home/username/robocomp/components/robocomp-robolab/components/apriltagsComp/src/apriltagscomp.cpp::run::CameraProxy initialized Ok!
[/home/username/robocomp/classes/rapplication/rapplication.cpp]: Loading [rgbd:tcp -h localhost -p 10096] proxy at 'RGBDProxy'...
18:20:19:421::Info::apriltagscomp.cpp::150::/home/username/robocomp/components/robocomp-robolab/components/apriltagsComp/src/apriltagscomp.cpp::run::RGBDProxy initialized Ok!
[/home/username/robocomp/classes/rapplication/rapplication.cpp]: Loading [rgbdbus:tcp -h localhost -p 10239] proxy at 'RGBDBusProxy'...
18:20:19:421::Info::apriltagscomp.cpp::161::/home/username/robocomp/components/robocomp-robolab/components/apriltagsComp/src/apriltagscomp.cpp::run::RGBDBusProxy initialized Ok!
18:20:19:423::Debug::genericworker.cpp::53::/home/username/robocomp/components/robocomp-robolab/components/apriltagsComp/src/genericworker.cpp::setPeriod::Period changed100
18:20:19:423::Info::specificmonitor.cpp::56::/home/username/robocomp/components/robocomp-robolab/components/apriltagsComp/src/specificmonitor.cpp::initialize::Starting monitor ...
InputInterface RGBD
AprilTagsFamily tagCodes36h11
ID:0-10 0.17
ID:11-20 0.17
ID:21-30 0.17
InnerModelPath /home/robocomp/robocomp/files/innermodel/simpleworld.xml
RoboCompAprilTagsComp::AprilTagsComp started
InnerModelReader: reading /home/robocomp/robocomp/files/innermodel/simpleworld.xml
InnerModelRGBD: 0.000000 {10096}
"/home/robocomp/robocomp/files/innermodel/simpleworld.xml" "rgbd"
FOCAL LENGHT: 480
6.45862 fps
7.17213 fps
7.09036 fps
6.94859 fps
7.09561 fps
7.01433 fps
7.09569 fps
7.02332 fps
7.24122 fps
7.17631 fps
6.85862 fps
7.00415 fps
7.14883 fps
6.92038 fps
7.03233 fps
23 May 2015
AprilTags is an augmented reality tag system developed by E. Olson at the U. of Michigan, USA. A complete explanation and related papers can be found here. There is a C++ version written
by Michael Kaes here which is the one we use.
April tags are AR tags designed to be easily detected by (robot) cameras. Understand them as a visual fiducial (artificial features) system that uses a 2D bar code style “tag”, allowing full 6 DOF localization of features from a single image. It is designed to encode smaller data (between 4 and 12 bits) and also these tags can be detected by the camera even at odd conditions. When the tag is seen by the camera, the algorithm computes the tag’s complete pose defining its own reference system relative to the camera (i.e Location of the tag is known with high accuracy). This reference system is defined as follows: If we look perpendicularly to a non rotated tag, The Z+ axis comes out towards us from the center of the tag plane, The X+ axis points leftwards and the Y+ axis points upwards (a left-hand reference system). The values computed by apriltagsComp are the translation vector from the camera to the center of the tag’s reference system, and the three Euler angles that encode the relative orientation of the tag’s reference system wrt to the camera reference system.
The AprilTags.cdsl file specifies how apriltagsComp has been generated and how it can be re-generated:
import "/robocomp/interfaces/IDSLs/GetAprilTags.idsl";
import "/robocomp/interfaces/IDSLs/AprilTags.idsl";
import "/robocomp/interfaces/IDSLs/RGBD.idsl";
import "/robocomp/interfaces/IDSLs/RGBDBus.idsl";
import "/robocomp/interfaces/IDSLs/Camera.idsl";
Component AprilTagsComp{
Communications{
requires Camera, RGBDBus, RGBD;
publishes AprilTags;
implements GetAprilTags;
};
language Cpp;
};
This files tells us that the component requires -will be calling- three RoboComp interfaces: Camera, RGBDBus y RGBD, which are normal and depth camera’s interfaces written in RoboComp’s IDSL language. You can find those files in ~/robocomp/interfaces/IDSLs. Also, the component will publish the data defined in the AprilTags interface and will implement the GetAprilTags interface. This means that using images provided by a component implementing the camera or RGBD interfaces, it will try to detect any tags in them and compute their 6D pose. Finally, it will publish a vector with all the tags id’s and poses to the Ice’s STORM broker, and also it will attend any direct requests (remote procedure calls) received from other components through the GetAprilTags interface. So it is a rather serviceable and handy component!
To access apriltagsComp you need to install from http://github.org/robocomp the repository named robocomp-robolab.
cd ~/robocomp/components
git clone https://github.com/robocomp/robocomp-robolab.git
Once downloaded, apriltagsComp can be found in:
~/robocomp/components/robocomp-robolab/components/apriltagsComp
First, read the INSTALL_APRILTAGS_LIB.TXT file and follow instructions thereby. Once the library has been installed in /usr/local, we can proceed to compile the component:
cd ~/robocomp/components/robocomp-robolab/components/apriltagsComp
cmake .
make
We should have a binary now:
~/robocomp/components/robocomp-robolab/components/apriltagsComp/bin/apriltagscomp
##Configuration parameters
As any other component, apriltagsComp needs a config file to start. In
~/robocomp/components/robocomp-robolab/components/apriltagsComp/etc/generic_config
you can find an example of a configuration file. We can find there the following lines:
GetAprilTagsComp.Endpoints=tcp -p 12210 //Port where GetAprilTags iface is served
CommonBehavior.Endpoints=tcp -p 11258 //Not of use for the user now
CameraProxy = camera:tcp -h localhost -p 10001 //Port where a camera is located
RGBDProxy = rgbd:tcp -h localhost -p 10096 //Port where a RGBD camera is located
RGBDBusProxy = rgbdbus:tcp -h localhost -p 10239 //Port where a bus of RGBDs is located
AprilTagsProxy = apriltags:tcp -h localhost -p 10261 //Not of use for the user
TopicManager.Proxy=IceStorm/TopicManager:default -p 9999 //Port where STROM broker is located
InnerModelPath=/home/robocomp/robocomp/files/innermodel/simpleworld.xml
InputInterface = RGBD //Current input iface to be used
AprilTagsFamily = tagCodes36h11 //Tags family. See AprilTags paper
AprilTagsSize = 0.17 //Tag default real size in meters
ID:0-10 = 0.17 #tag size in meters //Tags numbers 1-10 real size in meters
ID:11-20 = 0.17 #tag size in meters //Tags numbers 11-20 real size in meters
ID:21-30 = 0.17 #tag size in meters //Tags numbers 21-30 real size in meters
AprilTagsFamily is a set of tags, There are different families like 36h10,25h9,16h5 however tagCodes36h11 is recommended. Each tag has an ID that is printed inside the surrounding square using Hamming code. Instructions to print tags and other tag families can be found here. The algorithm needs the real size of the tag to estimate its position and orientation in space. We can give the component tags of different sizes, As long as they correspond to different ranges of IDs, as specified in the configuration file above.
##Starting the component
To start the component we need a real camera connected to the cameraV4lComp component or the RCIS simulator started with a file that includes virtual tags, such as simpleworld.xml, Tutorial can be found here. Once RCIS is up and running, It will provide the RGBD.idsl interface (not Camera.idsl for now) at port 10096, which is what the configuration file states. To avoid changing the generic_config file in the repository, We can copy it to the component’s home directory, So changes will remain untouched by future git pulls:
cp ~/robocomp/components/robocomp-robolab/components/apriltagsComp
cp /etc/generic_config config
So, to begin we type:
cd ~/robocomp/components/robocomp-robolab/components/apriltagsComp
bin/apriltagscomp --Ice.Config=config
If the robot’s camera is pointing towards one of the tags, You should see in the terminal lines showing the ID and pose of each visible tag.