Group 6 – Ramanujan

Ramanujan

Authors
Yash Kumar Verneet Singh

This robot is based on the project in Operating System. The aim of the project is to complete the race successfully by finishing laps that contains other robots and fixed obstacles.
The race consists of:

  • Race against time: robot compete alone in the stadium.
  • Race against a distant opponent: two robots compete but do not start at the same location.
  • Race against a proximate opponent: two robots compete and start next to each other.

Our proposal

Mechanical design

The robot consists of 3 components majorly :

  1. SENSORS – we are using 2 sensors in general – Sonar & Gyroscope and one more i.e. color sensor to detect the baricading present in the middle of the arena. The uses of each sensors are defined below:
    (a) Gyroscope
    To make turns.
    To escape obstacles. `ev3_search_sensor(LEGO_EV3_GYRO, &sn_gyro, 0)` (b) Sonar
    To measure distance between obstacle and the robot. Just like a RADAR~ `ev3_search_sensor(LEGO_EV3_US, &sn_sonar, 0)` ( c ) Color
    To sense the color of the obstacle present.
    Specifically, in our project, we are using color sensor to detect the baricading(RED).
    ev3_search_sensor( LEGO_EV3_COLOR, &sn_color, 0 ) To sense the RED color, we are using RGB mode that seems to be more accurate then sensing the colors normally. `set_sensor_mode_inx(sn_color,LEGO_EV3_COLOR_RGB_RAW)` *emphasized text*
  2. Actuators – we are using 2 types of actuators or motors. (a) Servo Motor
    To throw a piece of obstacle after a certain period of time. (b) Tacho Motors
    To make the robot move.
  3. ev3 Brick – This is the main CPU of the robot. We have flashed a debian linux on a 2gb memory card.
    Connecting to the Robot:
    a. Switch On the robot with the power button.
    b. Connect the robot with the wifi network.
    c. Using SSH, connect to the wifi from your laptop. Hostname- ev3dev Username- robot Password- maker

Compiling the Code

From the GITLAB repo, clone the repository(1) and install the required libraries for compiling ev3 source files(2).

  1. git clone https://gitlab.eurecom.fr/Aryabhatta/ramanujan.git
  2. GIT_SSL_NO_VERIFY=true git clone https://github.com/in4lio/ev3dev-c.git

To compile the source code simply run the make command.
To run the executable: $./final

Source Code Analysis

The source code is programmed in C programming language. The ev3 library has been used to program the sensors and actuators.

Servo Motor Movement:

The use of servo motor is to throw the obstacle to block the way for other robots to make the race little more competitive. In our proposal, the servo motor rotates for 500 units of time first in clockwise direction and then in anticlockwise direction to reset its position by itself.
The clockwise and anti-clockwise direction have been decided by taking a parameter servo_dir in the motorservo(int dir) function of servo.h header file.
set_tacho_speed_sp(sn_servo,max_speedD*1/5*servo_dir);
set_tacho_time_sp(sn_servo, 500);

To throw the object, first the function motorservo(int) is called with dir = -1 and then with dir = 1.
servo_dir = -1;
motorservo(servo_dir);
servo_dir = 1;
motorservo(servo_dir);

RC Tacho Motor Movement:

The motors are running using threads for synchronization.
pthread_create(&thread1, NULL, move_motorA, dir);
pthread_create(&thread2, NULL, move_motorB, dir);

A separate function is defined for a motor along with a direction giving parameter(-1 : Backward; 1 : Forward).
int move_motorA(int dir)
int move_motorB(int dir)

The functions used for moving the motors are:
set_tacho_stop_action_inx(sn1, TACHO_COAST);
set_tacho_speed_sp(sn1,dir*max_speedA);
set_tacho_time_sp(sn1, 2000);
set_tacho_ramp_up_sp(sn1, 2000);
set_tacho_ramp_down_sp(sn1, 2000);
set_tacho_command_inx(sn1, TACHO_RUN_TIMED);

We have defined the time as 2000 units. However, the functions are called in an infinite loop making it run infinitely until the reading of sonar sensor comes in a range.
Additionally,
We are using a variable: final_speed = max_speedA;that will be used in the main function to calculate the distance both the motors has travelled.

Distance Travelled:
The total distance travelled by the robot is calculated by timespeed*.
First the time difference is calculated before and after moving the motors(robot) in straight direction and then the time is multiplied by the speed with which the robot moved.

time(&time1);
move_function(dir); //returning the final_speed
time(&time2);
time_duration += difftime(time2, time1);
distance_ += (final_speed*time_duration)/10000;

This distance travelled will be used in multiple places like to know whether we have completed certain number of laps or when to throw the obstacle.

Sensors:

Color Sensor:

The color sensor uses the IR rays to detect the color by the wavelength it received in its receiver.
We are using the color sensor to escape from the RED colored middle barricading. It is used for the condition if a robot comes in front of our robot and on the left side we have the RED wall.
Hence, to sense the RED color, We are using RGB mode of sensor that compares the values of RED, GREEN, BLUE color inputs and gives whether the object is of which color.

set_sensor_mode_inx(sn_color,LEGO_EV3_COLOR_RGB_RAW);

if (value_r > value_g + value_b)
The object is red colored if the above condition is true. Its a comparison to make sure a range of value is covered.

Usage:
In our model, The color sensor is used to take right turns as soon as it senses the red color. This is because the partition of the arena is red in color and if a condition arises when the robot hits the red barricading, the robot should take a right turn of 90 degrees.
The algorithm for the right turn using color sensor red reading is:
if(red != 1){
red = red_obstacle();
}
if(sense_sonar() <= 150.00 && red==1) {
turn_robo(angle, -1); //right turn
Sleep(1000);
}
else if (sense_sonar() <= 150.00 ){
turn_robo(angle, 1); //Left turn
Since, the color sensor has a short range, we have changed the range of sonar sensor. For example, if the color sensor reads that the object is red in color and the sonar sensor also reads that the object in within 150 units of range, the robot will make a right turn.

Sonar Sensor:

The sonar sensor has two faces one for sending the sound waves and the other for receiving the waves. The distance is calculated by dividing the timetoreturn*speedofsound by 2 as it considers the time to return as well.

In our proposal, we are using the sonar sensor in an infinite loop to continuously sense the object in front of the robot so that the robot can be turned to moved back from the obstacle.

The value of sonar sensor is returned by :
get_sensor_value0(sn_sonar, &value)

This value is used in our main program as:

if(sonar_value < 200){
//body
}
The above code snippet means the object is under 200 units of distance and now the robot needs to turn around of move back.

Gyroscope Sensor:

The gyroscope sensor measures the angular velocity of an object.
In our proposal, the gyro sensor measures the angle by which the robot has made its turn.
get_sensor_value0(sn_gyro, &gyro_value)
The gyro_value returns the current value of the gyroscopic readings.

The problem we faced initially was, with the starting position, there was already some gyro values returned by our function. This problem was solved by using a single liner function to calibrate the gyro in the starting so that the starting angle value returned by the gyroscope is 0.

sensor_set_mode(0x1L, LEGO_EV3_GYRO_GYRO_CAL)

Usage:
(1) In our model, the gyroscope was used to make TURNs of the robot with more precision.
The turn algorithm is:

arr[a] = [50,10,1,1,1,1,.....1];
for(i < length(arr[a]){
gyro_reading_difference = 90//or 89 for different floors
a = 1;
if(a == gyro_reading_difference){
degrees -> 5
turn(degrees*arr[i])
//More conditions
}
}
Mostly, we are taking turns in packets of 90 degrees. To make a turn, first the robot turns immediately by 50 degrees and then it rotates by 10 degrees and then 1 degrees each until the a becomes 90 i.e. the robot turns by 90 degrees.
The values like 50 and 10 are statically taken into account taking the floor condition into account.

(2)
In our model, the gyroscope sensor is also used to calibrate the robot to move in a straight direction.
It was found that while moving straight, the robot was slightly turning its face by 5-10 degrees, an error due to the motors and tyres.
To move the robot in straight direction, we are using the below algorithm:

temp = gyro();
if(temp ==arr_angle[i]){
move_straight(moving_direction, sp);
}
else if(temp > arr_angle[i]){
move_straight_syn2(moving_direction);
}
else {
move_straight_syn(moving_direction);
}
[move_straight_syn2(moving_direction) – Moves right motor with constant speed and slows down left motor.
move_straight_syn(moving_direction) – Moves left motor with constant speed and slows down right motor. ]

If the above algorithm , The robot is moving in a straight line. As soon as there is a difference in the values of current gyro reading(temp) and the previously set gyro value, it detects the difference and makes call to respect move_straight_syn or move_straight_syn2 functions. Thus, keeping the robot in most possible straight direction.

Leave a Reply

Your email address will not be published. Required fields are marked *