Programming

 

Aim of the software

The aim of the robot is to detect obstacles such as holes, stairs or any obstacles which it probably meets on the way to the destination. Additionally, it can interact with people on the street by using light, sound and a small piece of paper mentioning the destination.

 

Procedure

After the system is initialized (set up I/O pins, robot stops …), all sensors are checked by reading the analog voltages from six sensors (four in the front and two in the bottom). In order to detect the current situation of the robot, we analyze all sensor signals and put them into three four situations.

 

  • First, if only the sensor in the front-bottom is on (case HOLE), it means there is a hole or stair in the front. In this situation, robot stops running forward. LEDs blinks and buzzer makes “beep” sound to attractive people.
  • Second, similarly, if at least one of the four front sensors is on and two bottom sensors are off (case OBSTACLE), robot also stops running and makes warning signal to indicate obstacle(s) in front of it.
  • Third, if two bottom sensors are on, the situation is that somebody is lifting it over the road surface (case PEOPLE). To interact with people, LEDs blinks and buzzer makes “beep” sound to show that robot is happy because it will be put in the correct way to its destination.
  • Forth, if none of the sensors is on (case NO_OBSTACLE), robot runs forward.

 

This procedure loops forever. In this project, robot can not notice whether it is at the correct destination or not. Therefore, at the time it reaches the destination, the power is switched off to stop the procedure.

 

The main loop

 

 

Subfunctions

 

 

Read sensors
/* @fn      read_sensors
* @brief   Read 6 sensors
* @param   void
* @return  byte: NO_OBSTACLE, HOLE, PEOPLE, OBSTACLE
*/


We use the AnalogRead function of Arduino. In fact, the default sampling time is long, the prescale should be changed to increase the sampling time by modifying some configuration (can be found in the source code).
Moreover, to avoid noise, we need to put some delays and re-read the values to ensure that the signals from sensors are stable.

 

Speed
/* @fn         speed
* @brief     Control speed of 2 motors
* @param   int l_speed: 0% - 100% speed of left motor
int r_speed: 0% - 100% speed of right motor
* @return  void


We use AnalogWrite function of Arduino to control speed of two motors. To be easy for programming the mainloop, the functions to control each motor are written separately. On each of them, the 8-bit PWM values are converted to the percentages of maximum speed. For example: speed (speed (-50,80) means the left motor runs backward at 50% of the max speed and the right motor runs forward at 80% of the max speed.

 

Warning
In the project, we use LEDs and Buzzer to interact with people with two modes: attracting people if there is hole or obstacle (“beep beep” sound) and expressing the happiness when being hold (“Pika Pika” sound).