WYSIWYG Web Builder
Programming
The controlling program of the robot can be split in 3 major parts :
Image processing
Communication between Arduino and the PC
Main program
The high language Python was used. The image processing has been integrated with the open source image libraries Opencv.
Image processing
The targets will be coloured rectangles in the area of the robot. Therefore, the first task will be to take a picture of the front of the robot
and, if there is one, recognise the targets in the picture. This is done by the following code :
This involves a function of opencv that is called inRange which only shows a mask for the image. Afterwards with an other opencv
function, findContours, the rectangles are searched in this mask. All possible targets of a minimum length are then stored in the
variable targets and a red box is drawn around all targets.
Analyze function:
This function acomplishes the search of the closest target. When this target is close enough so that the robot can fire on it, a green
box is drawn around the target. If some movement is still needed, a blue box is drawn. In both cases a command and a number is
returned, which will be needed latter on.
A possible example can be seen here above. In this case, the targets are paper sheets. Left picture: normal view of the webcam;
Central picture: the mask can be seen; Right picture: Results of the Analyze function.
Because a lot of environment influences can interfere with the targets colour, or at least the perception of the targets colour to the
webcam, it is best to set the value of this colour every time you start the robot. (This also allows the use of differently coloured targets)
This is done by the function TargetColor:
Communication between the arduino and the computer
While all the commands sent to the Arduino are there to drive the servo motors, they need to have a specified value of the change that
needs to be applied and which motor is concerned. Because of this the command sent to the Arduino is given as a string beginning
with 'B' and following with a A,B or C depending on the considered motor.
This is then followed by a number telling the new state of the motor and the string most always ends with an f.

This command is built in the Command function:
While in the Arduino, the main loop is given by the following code:
The first while loop checks if the character is an f. The second while checks if a character is available. If non is available, the check
function is run, this one checks all the other functions, e.g: Lives.
If the character is an f then first while stops and 3 different cases can be seen. The different function they trigger or the movements of
the servos.
In order to get feedback from the Arduino, the latter returns letters for every different cases. They are tabled here below :
While the PC-program regularly checks for possible feedback using the Read function:
This function reads out of the Arduino and act according to it.
Main program
First, this main program initialize the communication with the Arduino and the targets colour. The loop begins with the Read function,
where the Arduino is read as long as certain conditions are met. A function is also initialized to break the loop, for example if the robot
is dead.
Afterwards, there is a subroutine to check the consequences of a shot. (Hit, missed, ...)

Finally, the image processing part comes into action resulting in giving a command to the Arduino.
The full codes for the computer and the Arduino can be found here.
Dart Vader Mechatronics Project
Massimo Di Perri, Yuri Durodiť, Jeremy Duvigneaud,Younes El Bouchttaoui
Copyright © 2014 by The Dart Vader team  ∑  All Rights reserved