XOMiCar1 - OMiLAB Robotic Car Experiment 1

Keywords: modelling

Use Case

Performing a "Slalom" with a Makeblock Robot car using the line following and distance sensors controlled by ADOxx

Use Case Description: Performing a Slalom
The makeblock robot car called mbot should follow a black line on the floor till an obstacle appears in front of the car. The car should stop and avoid the obstacle. Afterwards it should continue following the line till the next obstacle appears and so on.

 

Problem Statement:

  • How can we communicate with the car?
  • How can we make the car following the line?
  • How does the car notice an obstacle in front of it?
  • How can we manage the avoid routine?
  • How do we implement the control mechanism in ADOxx?

 

Overview:
The major challenge of this use case is to understand how to communicate with the car. Once we got this, it will be necessary to learn about the car's sensors and how do we get useful information out of them. The next step will be the management of the obstackle avoiding. After all this, the final task will be the integration in ADOxx.

Experiment

Experiment Description

Communicate with the mbot

First of all we had to connect the car with our device via bluetooth. Therfore we installed the mblock software for pairing the device. Within this software it was also possible to update the firmware of the mbot.


Once the car was paired and connected with our device we downloaded an already existing implementation of the mbot from gitlab: https://gitlab.dke.univie.ac.at/OMiROB/MBotJava/blob/master/src/main/java/org/omilab/o mirob/ mbot/Main.java

After that, we had to find out the right Bluetooth port that is used to communicate with the mbot and enter it in the implementation as value for "comPortName".

Finally the connection with the mbot was set up and we could start with realizing our use case.

 

Sensors of the mbot

For our line following and obstacle avoiding car we used two sensors of the mbot - the line following sensors and the distance sensor - called UltraSonic Sensor within the java implementation. To understand how these sensors work, we needed to test their behavior and output when they are in use.

 

a)    line following sensors

Source: http://robotics.stackexchange.com/questions/9728/how-to-check-for-a-sharp-angle-with-a-line-follower

Basically the sensor is able to return 4 different states:

1.    Both sensors are on the line, sensors return value 0
2.    The left sensor is on the line, the right one not, sensors return value 1
3.    The right sensor is on the line, the left one not, sensors return value 2
4.    Both sensors are off the line, sensors return value 3

Which meant for us that if one of the sensors is getting off the line, we have to tell the car to drive back on the line. This could be done by give different power to the two motors of the car. For example if the left sensor is off the line, we have to tell the car to drive to the right. Therfore the left motor has to get more power than the right one and vice versa.

With this information we could write a simple line following method in java.

 

Since we got our mbot following a line, we needed to teach it how to avoid an obstacle. For this we took usage of the UltraSonic distance sensor.

 

b) UltraSonic Distance Sensor

As we discovered which sensor is the distance sensor the next challenge was to learn how it works.  Therefor we printed the output of the sensor within an endless loop and tried to interpret the values. It works quite simple, the return value is as high as the distance measured to the next obstacle in reach.

Source: http://www.makeblock.com/image/cache/catalog/h/837/7  78263-500x500.jpg

The first if-statement in our follow line method contains a variable "ds" which represents the return value of the distance sensor. If this value gets under 10, the mbot stops and awaits for further commands.

 

Avoiding Obstacles

We got our car following a line itself till an obstacle appears in front of him, but what should it do in such case? After several experimental tries we decided to take the choice if it should go left or right on ourselves, expecting this would be easier to implement in ADOxx later. So we went on and implemented two methods avoidObstacleLeft() and avoidObstacleRight(), shown in Fig. 6, which tell the mbot to go left or right . At this point the difficulty was to bring the mbot back on the line after the avoiding routine. After hours of testing we got the right timing.

 

Implementation in ADOxx

In order to control the car, three buttons in Adoxx are needed: “Start”, “Right” and “Left”. Furthermore, we planned to create an icon “Stop” which should turn from gray to red when the car is on a stopping position. This gives the indication to the user, that an obstacle is found and he should choose in which direction the car should turn to avoid it. Pressing the button “Right” or “Left” the car will avoid the obstacle and will positionate itself on the black line again. Pressing the button “Start”, the car will follow the line until the next obstacle. Each button should be linked to an executable jar which was previously created with Eclipse.

To archieve this, we expanded the experimentation library in Adoxx with new classes and shaped the needed icons using the GraphRep attribute.

 

After the icons have been shaped, a link to the corresponding jars is needed so that by clicking the button, the jar can be run in the background. First, AdoScripts were created and imported into the library together with the jars. The AdoScript calls the jar when executed:

CC "AdoScript" GET_TEMP_FILENAME SETL sJARFilePath:(filename + ".jar")
CC "AdoScript" FILE_COPY from: ("db:\\FollowLine.jar") to: (sJARFilePath) SET pathToJar:("\"" + sJARFilePath + "\"")
SYSTEM ("cmd /c java -jar " + pathToJar+" || pause") with-console-window result:rc
CC "AdoScript" INFOBOX (rc)

 

In order to execute the AdoScript when the button is clicked, a new attribute must be added to the class as “programm call”. An example is shown in the next image. The script is called inserting the following lines into the “Facets” menu point of the attribute: 

ITEM "follow_line"
CC "AdoScript" FREAD file:"db:\\adoScript_follow.asc" IF (text = "") {
CC "AdoScript" INFOBOX ("No Script.") EXIT
}

 

 

Finally, in the GraphRep attribute of the class insert (at the bottom of the code) the line below was added to make the button clickable:

HOTSPOT "follow_line" text:"Execute" x:-1cm y:-1cm w:2cm h:2cm

 

To make the colour of the buttons change according to the current status of the car (Stopped or started), a new attribute of integer type was created as shown in the next image.

 

The standard value was set to 2 and changed to 1 after the button has been clicked. To allow this, the following lines were added to the script:

CC "Modeling" GET_ACT_MODEL SET actModelID:(modelid)
#id von startclasse auslesen
CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid:(actModelID) classname:("start")
SET asIDs:(objids) FOR i in:(asIDs) {
CC "Core" SET_ATTR_VAL objid:(VAL(i)) attrname:("started") val:(1)
}


Furtheron, the rule for changing the colour of the icon according to the value was added to the GraphRep:

AVAL started:"started" IF (started !="2")
FILL color:lightgray ENDIF

 

 

Concept of Knowledge Engineering

We implemented the line following and obstacle avoiding implementation for the mbot in java and visualized it in ADOxx from where the use case can be controlled and managed.

 

Validation Environment

We used an existing protocol implementation for the mbot and extended it with the functionallity we needed. Therefor we used eclipse as IDE.

 

 

Results