# Task #2 – basic robot programming

Objective 1: Get the robot two move two meters straight
Calculations & measurements:
1 inch  =  2.54cm
100cm = 1 m
1m = 100cm
2m = 200cm
Wheel diameter: 5.5cm
2 x (22/7) x r = 17.27875959 radians/sec
Total distance to cover = 200cm; therefore:
->    200 / 17.27875959
Therefore total number of revolutions:
->    11.57490495 x 360 radians/sec

Program 1: using the Lego NXT Mindstorms Software
The NXT program was written using the number of revolutions as one the key parameters for the objective. Below are some of the results obtained after the robot was tested using 11 and 12 revolutions:

Program 2: using Robot C

I tested the NXT program with both 11 and 12 revolutions because the actual figure ascertained from the calculation was 11.57490495 which is approximately 12. However, after testing, that seemed to be a little too much. Testing the program on a smoother surface provided more accurate results whereas the tests on uneven and rough terrain yielded inaccurate results. One observation I made was that the NXT program produced far more reliable results on the rougher surface than the Robot C program; of which I credit to the inbuilt control mechanisms.
One problem I faced with the Robot C for this particular objective was that, the robot always veered towards the right after a few seconds. I reassembled the tyre over and over again, thinking it was a problem to do with the physical alignment of the wheels. However, after the employing the ‘syncedMotor’ properties to my program improved the situation by far. Another problem I faced was that, I tested my robot so many times and I did not charge it before my final demo. The low battery I believe had a slight effect on the reliability of my program.

Objective 2: Get the robot to move in an enclosed shape.
I decided to have my robot move in a polygon shape. Initially for both programs my robot was not ending exactly at where it started. However, I fixed that after I realised what exactly was causing it: The problem resulted from some distance which I left unaccounted for when my robot took certain turns in the polygon. To solve this, I decreased the power at the turns of the Robot C program and added a few more milliseconds to the wait function, as well as added a little code block, that would re-align the robot after returning to the target destination [With the NXT program, I rather increased the power of the motors for each turn I made] and that did the trick.

Objective 3: Use two sensors in a program in any language/tool of your choice
(I wrote both programs in Robot C)
Program 1: Using the sonar sensor
This program was supposed to move in a straight line but was to decrease its speed whenever it sensed an object 40 cm (or closer) to it. This program run perfectly; I was so in love with it!

Program 2:  Using the touch sensor
This program was supposed to move in a straight line and turn only when it bumped an object. The problem I had with this was, some spare parts needed to fit the touch sensor at the position specified in the manual were not available, and thus forcing me to fix the touch sensor a little higher than I preferred. The positioning of my touch sensor did not allow the robot to “bump” most natural objects in its way (i.e. except from the walls, most of the objects in the robot world were extremely short).That only meant I had to change the robot world or introduce some either get some artificial objects within the touch sensors range; I did the latter.  Also, I tested this particular program when the battery was really low, and what I realised was that I had to hit the touch sensor a little harder than I expected, in order to get the desired result.

*A general problem I observed was that, very little objects could even disturb the free movement of the robot tyres (both indoor and outdoor). Objects such as the different tile lines and very small stones were big enough obstacles to veer the tyre off into another direction.