Treasure Hunt Task

Task: Treasure Hunt

Group Members:

Flynn Darko

Daniel Botchway

Lecturer: Dr. Ayorkor Korsah


Task 3 Report

Introduction & Objective

Our main goal for this task was to write a program for the robot that would enable it find red and blue colored bottles and place them in their respective color zones (holding stations) with the help of sensors attached to the robot.

Design Concept

First, we had to rebuild our robot from task 2 to enable it grab and transport the bottles to the collection points. Treasures are shown in figure 1.

Bottles wrapped in colored cards

Bottles wrapped in colored cards (treasures)


  • For the robot and its sensors

For our robot we decided on the “Tribot” model of the robot. The sensors we decided to use were two sonar sensors and two color sensors. For the sonar sensors, one was placed at the top and the other placed by the side of the robot. The concept we wanted to implement with these two sensors was to use the top sonar sensor for front obstacle (wall) detection and the side sensor for side obstacle (wall) detection and avoidance.

Also, one color sensor faced downwards while the other was place in front of the robot. With the front color sensor detecting, finding and recording the color of a bottle and its color the downward color sensor would use that data to find the respective collection zone that has the same color as the bottle detected.

  • For our solution concept, the process goes like;
  1. Do random exploration in the environment to find colored bottles while avoiding obstacles.
  2. On finding bottle, save color of the bottle, grab the bottle and move along the wall of the environment.
  3. When the appropriate color zone is detected, drop bottle.
  4. Continue with the random exploration.


Our first step in the implementation stage was building our robot. The robot had to have arms to enable grabbing of the bottles. The arm that was meant to grab the bottles needed a motor to control the opening and closing of the arms. The color sensors were placed in front of the robot in between the arms with one sensor horizontally positioned to detect the color of obstacles in front of the robot. Another color sensor was place vertically, so that it the sensing area pointed down, in order to detect the color of the landing zones.

The next step was programming the robot to use its sonar sensor inputs to do wall-following. This we programmed using the Bang-Bang and P control mechanisms. Though the wall following program worked along a straight wall, it failed in the treasure hunt environment because of the acute angular nature of the boundaries. With that situation, we had to implement a wall avoidance procedure (solution) to enable the robot travel successfully through the environment without bumping into the walls. A solution that would use an extra sonar sensor to prevent head-on collision was implemented and that necessitated the use of two sonar sensors on tribot. The sonar sensors on the robot needed to be positioned at a particular angle to allow both of them to work in synchronization based on the code and logic implemented. A number of tests helped determine the appropriate position for the sonar sensors and appropriate sonar values.

With regard to the Programming algorithm, this is the approach

->reset claw ()

->start exploration task ()

->start avoidance task ()

–>avoid front collision ()

–>avoid side collision ()

–>avoid going outside the assigned environment ()

->while search isn’t ended {

–>if treasure is detected {

—>start grab and Deposit ()



View of our Treasure hunter robot

View of our Treasure hunter robot


One major challenge encountered was with the alternative wall avoidance procedure. This solution did a great job of avoiding obstacles but the robot kept avoiding the treasures also and followed along the same route close to the walls of the environment. There was no randomness in the exploration and just a little section of the total surface area of the environment was being covered. This problem was fixed by programming the robot to turn after every front obstacle detection and hence obstacle avoidance. This introduced some randomness and the robot covered more surface area, however, this did not fix the issue of the robot avoiding the treasures themselves.

The other challenge was with the coverage area of the color sensors that made detecting a treasure quite difficult. The color sensor needs to be very close to the object of interest in order to accurately determine the color of the object. Also, the sensors had a narrow field of view and thus the object of interest needed to be directly in front of the sensor to make a successful detection. This makes the robot pass by and knock down treasures that are in its path but not directly in front of the color sensor. This problem has not being fixed and chance is really the deciding factor in the detection and recognition of a treasure.

The approach used in exploring and searching for treasures was a random one and this came with the problem of time inefficiency. As the number of treasures in the environment decreases the time taken to detect a treasure increases. The exploration bit of the program relied on obstacle avoidance till the robot came on a path that would allow the front color sensor detect a treasure (a bottle). Attempts to fix this problem would demand a major change in the concept of the solution and the structural design of the robot.


Looking at the design concept and its implementation we found iterative testing to be key in making our robot more efficient and reliable. The placement of the sonar sensors was very important since placing them at the wrong position would give unreliable results due to the noisiness that comes with the some sensors such as the sonar sensors.

The whole task taught us a few lessons which were very important in building and programming a robot to perform tasks. One challenge we faced was testing and making sure the robot is reliable in hunting for the treasures (bottles) and that is it could perform the same task over and over again without encountering any problems.

Another challenge was breaking down the whole treasure hunt task into small problem units and testing them to make sure each “sub-task” such as wall-following was working very well before moving on to say, treasure (bottle) detection. Overall, the task taught us the essence of first breaking down the whole task into smaller task and solving them unit by unit.


Relevance to Problem Solving in Ghana

This treasure hunt concept can be implemented in areas of accidents where victims cannot be located or reached to offer help to them. For example during the recent collapse of the  one Melcom shop branch in the country, health and security personnel were not able to find or locate victims due to their inability to enter the rubble.

Robots can be programmed with the proper sensors such as a camera to help detect where victims are located in an accident. This would not only hasten the work of security and health personal but saves lives as well.


Task 3: Treasure hunt



16TH OCTOBER, 2012

Our Experience

The task was interesting because of its seeming complexity and thought required to accomplish it. Initially it sounded very abstract and almost impossible to perfectly program but as we reasoned through it logically, we were able to break it down into very basic tasks. These included object detection using the sonar, wall following, collision prevention as well as grabbing and dropping the bottle. We began by designing small modules to accomplish specific tasks and testing them individually before gradually putting them together into a complete program.We modified the program continually and even redesigned the robot a number of times as we researched and found new insight.

Lessons learnt

The main lessons we learnt from this task were how to use the compass sensor, sensor fusion (in our case, using the sonar with the color sensor for object detection) and ways of reducing sensor noise. We also gained a better understanding on how to manage separate tasks using the signals from the sensors.

Challenges faced

The first challenge we faced was getting all the required sensors to work together. We noticed that on several occasions we had different sensors causing the robot to perform conflicting actions and in effect producing very awkward results. Also, we were not able to make good use of the multiplexer due to its complexity even though it would have been helpful at some point. This caused a change in our design. In the end, we stuck to using four sensors and managed to have them coordinate to produce similar results as would have been possible with a few more sensors.

Another challenge worth mentioning was the difficulty in planning a reliable motion path for the robot in order to accomplish its task. For the greater part of the task, we stuck with using random motion which was unreliable and greatly increased the time it took to accomplish the task.

Problem Solving with sensors

  1. Fixing Potholes:

Many roads in Ghana are covered with potholes and other forms of damages which often cause deadly accidents especially in the rainy season. An important aspect of solving this problem is data collection. Data collected about the current condition of the road will help make estimates for either considering repairs or a complete reconstruction as well as providing useful information to road users on avoiding certain sections of roads.

Measuring every hole and crack on the road manually would cost a lot of money and time. With the help of sensor and additional image recognition software, we could create a system which recognizes the damages on a road and estimates the cost of fixing it. Sensors which can be used may include a camera to capture images to be analysed and an accelerometer to collect data about how bumpy the road is. These sensors may be simple accelerometers and cameras available on phones or could come as part of more advanced equipment. Over time, as more roads are traversed a very reliable database could be established with enough information to help with more efficient means of repairing damaged roads.

  1. Flood Prevention:

Many communities in Ghana suffer from floods every year. Floods are usually caused by the overflow of rivers during the rainy season and often cause massive loss of property and sometimes loss of lives. Because of the lack of alarm mechanisms, affected communities don’t normally have enough time to prepare to leave or move their properties.

A mechanism which could help to reduce the loss in life and property could be built using sensors which could measure change in water levels in rivers. The level of water in the river could be measured using a level sensor. Some level sensors which can be used for this purpose may include ultrasonic level sensors, capacitive sensor, and mechanical diaphragm. With these sensors being constantly monitored, meteorological agencies and disaster prevention organisations would have enough time to warn communities and also be well prepared to deal with floods if they could not be prevented.


Task 3 – Treasure Hunt

Emmanuel Nkansah

Selase Attah Kwamuar


The task is to have a robot locate “treasures” in an environment set-up in the lab, and deposit them in the appropriate color-coded holding station. The robot will use its sensors to find the treasures in its environment and make its way to the holding stations. The robot may be guided in any way that does not involve physical human contact. For example, a flashlight may be used to guide a robot with its light sensors but the robot may not be pulled along with a string. There will be 6 treasures in the environment, and the robot has a time limit of 3 minutes to find and sort as many treasures as possible.

Design Concept:

Learn About various Sensors: We started by learning how to use various sensors. Some of the sensors that we tried are the magnetic compass, the color sensor, and the ultrasonic sensor. We were able to use the magnetic compass sensor to get the magnetic fields of the earth. With that we were able to cause the robot detect the North Pole and the South Pole of the earth. We were also able to use the color sensors to detect different colors. While using the color sensor, we realized that the default color for the environment is black. With the help of the ultrasonic sensor we were able to detect and avoid obstacles. This process of learning about the sensors helped us to decide on a strategy to adopt.

Driving along a Wall: In order to implement wall following, we observed or recalled the concept of line following: reading or collecting data from the sensors and adjusting the power of the motors when necessary to ensure the wall is followed accurately. The bang-bang control implementation involved constantly checking the distance of the robot from the wall and adjusting the current distance away from the wall by moving one of the two wheels, usually one after the other. However, the P control took a more calculated or careful approach and involved turning the robot by the amount of the error. We discovered that overall this was a better approach to wall following. However, to achieve a smooth translation from error to motor power or output we had to employ or use a low gain kp. We found this kp by experimenting. We learnt a lot from our experience. Specifically, it helped to understand p control, a concept that wasn’t quite clear before the task.

Writing code in block methods: The wall following exercise required little code and hence did not merit block methodology or modular programming. Nonetheless, in the subsequent exercise (treasure hunt), we disintegrated the code into methods in order to effectively tackle the various steps involved. For instance, right, forward, left and reverse functionality was written in method form and called when necessary.  The modular or block nature of the methods helped us with our thought process and was implemented after drawing a flow chart of our algorithm.


Subsequently, we fused the code from the two programs to enable us successfully grab and sort the various treasures. However, with our implementation we discovered the limitation associated with using the sensors provided in the Lego kit; noise. This was especially evident in the distance measurement readings we obtained from the ultrasonic sensor. These values disrupted the logic of our program and interfered with the treasure-hunting task. The accuracy of this sensor was mostly needed to initiate a wall following process after grabbing treasure. However, the noise led to the wall following process being started a few centimeters before the wall. This problem was solved by implementing a method to obtain and find the average of several distance readings to allow the robot calculate a more precise distance. We learnt about the importance of planning or creating diagrammatical representations of the task at hand before implementing to ensure the process was tackled in a piece wise manner.


From the carefully outlined paragraphs above, it can be stated that sensors are as trust worthy as their error margin. Hence, in order to achieve maximum efficiency in their use, several measurements or readings have to be taken and the most appropriate or efficient reading picked and used in decision making. In the African and Ghanaian context, sensors play major roles in industry and problem solving scenarios. Some of these scenarios include water-monitoring system, such as the one implemented by the iStep Programme. This system could use an ultrasonic sensor that checks the distance from the top of the tank to the water level and calculates the water depth by preforming calculations. Other scenarios include beverage manufacturing plants or distilleries that use thermometers to monitor the temperature of chemicals at different stages of the mixing process. Sensors used in these environments require attention, as their reading could “make or break” a company’s performance on the market in terms of quality control.

Task 3 – Treasure Hunt



The semester is still running and robotics as well. And we have had the privilege to work with the NXT and Lego mindstorm kit to perform fascinating tasks. In my last report, I described the tasks that we were engaged in. These tasks always improved, in terms of logic application and testing. Task 3 was a great field of an adventure that blew our minds and strength, however, it was an interesting experience in the world of robotics.


In task 3, we were asked to perform two major sub-tasks, which was to implement wall following using any two control principles that we studied in class, and rebuild our robot if necessary, to go treasure hunting in a sample world. Edem and I implemented the bang-bang and the P control for wall following, and we are going to discuss it in detail.


This task was very interesting and exciting in the sense that we programmed our robot to follow a given wall. Bang-bang was the simplest since the robot only had to follow the wall, given a distance away from the wall. Whenever the robot was closer to the wall than the given distance, it moved away and whenever the robot was far from the given distance from the wall, it moved closer. Here is a pseudocode for the wall following:

if (robot is close to wall) {

move away from wall;



move close to wall;




The robot moved in a zig-zag motion provided the conditions given it were satisfied. There was one interesting aspect of the wall following that we experienced. The robot was able to follow the wall whenever it was parallel to the wall. However, when it approached a curve, it struggled making a turn. It either crushed into that angle or it kept spinning in circles. Then we had to figure out a way to prevent this problem of collision and spinning. The two main instruments that helped us implement the wall following was the ultrasonic sensor in the mindstorm kit and the motors. The ultrasonic sensor helped the robot keep a certain distance from the wall while the motors moved the robot at a given speed. Therefore we had to make changes with respect to these two instruments.

With the motors, we wanted to maintain a slow pace, since we realized that when the robot moved very fast, negotiating a curve with the current algorithm will not be effective. So we programmed the motors within a range between 20 and 30, to get the required speed for the robot. In addition we had to change values for the ultrasonic sensor which was also in a range between 8cm and 12cm. So to make it work, we tried different values.


This task was the most involving among the two main tasks. Our robots were supposed to locate treasures (bottles covered with colored paper) and deposit them to their respective color goals. With the sensors provided in the mindstorm kit, this task seemed involving but easy to implement until we had to bring our ideas into reality.


Communicating with your robot to perform specific tasks has to deal with breaking down the problem into modules, so that the given task could be achievable. This makes it even easy for the programmer to understand and view the results that the robot gives after a specific task. Locate colored treasures and place them at their respective drop-off zone was the task, and as easy as it sounded, we were amazed the number of modules we came up with when we put our thoughts together. The functions we came up were: openArm(), closeArm(), locateBottle(), locateObstacle(), moveForward(), rightTurn(), moveBack(), explore(), stayInArena() and dropBottle(). These modules had definite tasks to perform as their names suggest and that is how we implemented them. This was our idea of how the robot was going to complete the task given the different modules stated before:

  • The robot explores the given world.
  • When it locates a treasure, it stops and picks up the treasure.
  • It uses wall following to locate the particular goal area.
  • Returns to do the exploration and runs these steps till it’s done.

This task gave us a real sense of the world in many ways. We had assumed how the world in which the robot was going to operate would be and how it was going to accomplish the task but we realized that there were more real issues to deal with, like when the bottles fell through the maneuvering of the robot, how was the robot going to locate that particular treasure with respect to the position of the RBG sensor, and place it at its destination. Another interesting task we realized was how we could make certain modules more accurate and effective. For instance, with the wall following, the robot had to move in accuracy so that it could deposit the treasure at the specified goal.

We had different modules working separately but as in a unit, the robot couldn’t complete its mission. We are still working to put all modules together and work effectively. This task also emphasized the fact that testing is a very essential part in robotics.


Traffic coordination: Due to the increasing rate of the population in the city, many cars are found in most busy areas in Accra. For example, the Tetteh Quarshie interchange is one area whereby people use to move from one point to another most often. Sometimes traffic could be so severe that it could be compared to an auction sale. Even though this project was to ease traffic in the area, it seems the purpose of this project is redundant. What could be done in this area to make the purpose of the interchange more effective is with the help of traffic lights. Traffic lights help ease traffic in an area, and we can include cameras to monitor the size of traffic at given times to determine the flow of traffic in a given time of the day. For instance, the Tetteh Quarshie interchange really gets choked during the morning hours and evening and so we can use the cameras to find out how many cars are present in a given time of the day and use it to determine how long a traffic light to stay on and off. This will make the traffic lights more dynamic in terms of functionality and not static.


Some areas in Ghana are close to water bodies and whenever it rains heavily, these places get flooded, causing so many problems like loss of lives and property. One way we can monitor floods in an area is the use of an ultrasonic sensor. The sensor can determine the normal depth of a river or water body and also have a high peak that whenever the level of a water body approaches that level, an alarm could be sent out to the organization that is monitoring the levels in water bodies and perhaps the people in the area. With this, an area can know how they are faring in terms of the water level and take measures to reduce the damage that flood causes.