Quark 2016 – BITS Pilani, K.K. Birla Goa Campus

Quark 2016 – BITS Pilani, K.K. Birla Goa Campus

Quark 2016 – A Cosmic Odyssey

Days of festival: 5th, 6th & 7th February 2016

I participated in Line Following, Roborace and, for the first time, Open Showcase!

RoboRace

Objective: Design & build a remote controlled all-terrain racer that can traverse any given path with obstacles like rocks, sand, slopes, uneven ground, mud, etc.

Dates of competition: 5th & 6th

Venue: Uneven grounds outside B-Dome

Home test report: Excellent traction, thanks to the custom-made wheels (each wheel was actually a pulley with a track belt bound tightly over it) Gains speed very quickly and can even climb out of a small car tyre.

Results:

5th Feb, Round 1 – The bot completed the track without stopping, and clocked a very good timing, however, the high traction wheels turned out to be a massive hindrance while making spot turns. This factor slowed it down, but it made up for that on the straight paths.

The bot qualified for Round 2, which was to be held on Day 2, but unfortunately, due to a last minute shorting onboard the wireless module, the bot was unable to participate.

Quark_2016_RoboRace_participation_certificate

Open Showcase

Objective: Present an innovative idea that solves a problem.

Dates of competition: Day 2

Venue: CC lobby

My Idea (for the EEE category): CUA (Computer Usage Alert) is a plug-n-play USB device that alerts you to get up and stretch at 20 minute intervals. It has an ATtiny85 micro controller with a program that sends a signal to a buzzer to beep every 20 minutes, thereby alerting you to get up. This process continues until it is unplugged or the computer/laptop to which it is plugged is shut down.

The judging criteria was as follows:

  • Innovation
  • Feasibility and Sustainability
  • Cost Effectiveness
  • Social Viability
  • Discipline
  • Project Report

Quark_2016_Open_Showcase_participation_certificate

Line Following

Objective: Design, build & program a line following robot (LFR) which can traverse a black track on a white background with obstacles like acute angle, obtuse angles, right angles, dashed lines, curves and reach the finish line in shortest possible time. The track width will be 2cm to 3cm. (As per the rules mentioned online)

Screen Shot 2016-02-16 at 8.28.51 pm

Dates of competition: 6th & 7th

Venue: C-306

Home test report: Running very well. I’d say that is has an 80% chance of making a new record.

Competition day: “Holy mackerel! The track width is 4cm!“. I asked the organiser about it. He measured the track width and calmly told me that extra calibration time would be given. And as if to put salt on that wound, the track had 4 places where there were curved, dashed lines with acute turns onto more curved lines!

Results:

6th Feb, Trial 1 – The LFR started out well and then went completely cuckoo. Though it has a PID algorithm in it, the LFR seems to be in its own world. (Thanks to the extra centimetre in the width)

6th Feb, Trial 2 – I managed to fix a few turns, but the PID algorithm still seems to be completely inactive.

(Fortunately, everyone had problems running on the first day, so everyone qualified for the next round on day 2. That night, I sat coding till 1:00 A.M. and finally managed to fix it.)

7th Feb, Trial 1 – The new code is working and the PID is perfect, but a few changes still need to be made in the acute turns. Overall, it’s running well.

7th Feb, Trial 2 – This run went very well, except for the fact that it went off the track 5 times (which means that 25 seconds will be added to my total time of 38 seconds, as a penalty)

I finished my turn just after lunchtime, so I had the rest of the day to go around the campus and watch the final rounds of the other competitions.

At around 4 o’clock I received a phone call from the organiser, telling me that I had won the 2nd place.

IMG_20160207_185732

 

For all you geeks out there, here’s my LFR code. Feel free to tweak and reuse:

#include <QTRSensors.h>
//Code written by Raunak Hede
//https://raunakhede.com
#define Kp 1 // experiment to determine this, start by something small that just makes your bot follow the line at a slow speed
#define Kd 15 // experiment to determine this, slowly increase the speeds and adjust this value. ( Note: Kp < Kd) 
#define rightMaxSpeed 180 // max speed of the robot
#define leftMaxSpeed 180 // max speed of the robot
#define rightBaseSpeed 50 // this is the speed at which the motors should spin when the robot is perfectly on the line
#define leftBaseSpeed 50  // this is the speed at which the motors should spin when the robot is perfectly on the line
#define NUM_SENSORS  8     // number of sensors used
#define TIMEOUT      2500  // waits for 2500 us for sensor outputs to go low
#define EMITTER_PIN  12     // emitter is controlled by digital pin 2

#define rightMotor1 4
#define rightMotor2 11
#define rightMotorPWM 5
#define leftMotor1 3
#define leftMotor2 6
#define leftMotorPWM 10

int P, D;
int leftMotorSpeed = 50;
int rightMotorSpeed = 50;
int turn = 100;

QTRSensorsRC qtrrc((unsigned char[]) {14, 15, 16, 17, 18, 19, 7, 8}, NUM_SENSORS, TIMEOUT, EMITTER_PIN);//sensor connected
unsigned int sensorValues[NUM_SENSORS];
void setup()
{
  pinMode(rightMotor1, OUTPUT);
  pinMode(rightMotor2, OUTPUT);
  pinMode(rightMotorPWM, OUTPUT);
  pinMode(leftMotor1, OUTPUT);
  pinMode(leftMotor2, OUTPUT);
  pinMode(leftMotorPWM, OUTPUT);
  
  #define rup digitalWrite(rightMotor1, HIGH);digitalWrite(rightMotor2, LOW);
  #define lup digitalWrite(leftMotor1, HIGH);digitalWrite(leftMotor2, LOW);
  #define rdown digitalWrite(rightMotor1, LOW);digitalWrite(rightMotor2, HIGH);
  #define ldown digitalWrite(leftMotor1, LOW);digitalWrite(leftMotor2, HIGH);
  
  #define f lup;analogWrite(leftMotorPWM, 80); rup;analogWrite(rightMotorPWM, 80);
  #define l ldown;analogWrite(leftMotorPWM, turn);  rup;analogWrite(rightMotorPWM, turn);
  #define r lup;analogWrite(leftMotorPWM, turn);  rdown;analogWrite(rightMotorPWM, turn+50);
  #define b ldown;analogWrite(leftMotorPWM, 80); rdown;analogWrite(rightMotorPWM, 80);
  #define s analogWrite(leftMotorPWM, 0);  analogWrite(rightMotorPWM, 0);

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
  for (int i = 0; i < 500; i++)  // make the calibration take about 10 seconds
  {
    qtrrc.calibrate();       // reads all sensors 10 times at 2500 us per read (i.e. ~25 ms per call)
  }
  digitalWrite(13, LOW);// turn off Arduino's LED to indicate we are through with calibration
 
  //print the calibration minimum values measured when emitters were on
  Serial.begin(9600);
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(qtrrc.calibratedMinimumOn[i]);
    Serial.print(' ');
  }
  Serial.println();
  
  // print the calibration maximum values measured when emitters were on
  for (int i = 0; i < NUM_SENSORS; i++)
  {
    Serial.print(qtrrc.calibratedMaximumOn[i]);
    Serial.print(' ');
  }
  Serial.println();
  Serial.println();
  delay(500);
}
int lastError = 0;

void loop()
{
  unsigned int position = qtrrc.readLine(sensorValues);
  if (sensorValues[7] < 900 && sensorValues[6] < 900 && sensorValues[5] > 900 && sensorValues[4] > 900 && sensorValues[3] > 900 && sensorValues[2] > 900 && sensorValues[1] > 900 && sensorValues[0] > 900)
  {//right
      s;delay(50);  r;delay(300); s;delay(50);
  }
  else if (sensorValues[7] > 900 && sensorValues[6] > 900 && sensorValues[5] > 900 && sensorValues[4] > 900 && sensorValues[3] > 900 && sensorValues[2] > 900 && sensorValues[1] < 900 && sensorValues[0] < 900)
  {//left
      s;delay(50);  l;delay(300); s;delay(50);
  }
  
  else if (sensorValues[7] < 900 && sensorValues[6] > 900 && sensorValues[5] > 900 && sensorValues[4] > 900 && sensorValues[3] > 900 && sensorValues[2] > 900 && sensorValues[1] > 900 && sensorValues[0] > 900)
  {//right
      s;delay(50);  r;delay(280); s;delay(50);
  }
  else if (sensorValues[7] > 900 && sensorValues[6] > 900 && sensorValues[5] > 900 && sensorValues[4] > 900 && sensorValues[3] > 900 && sensorValues[2] > 900 && sensorValues[1] > 900 && sensorValues[0] < 900)
  {//left
      s;delay(50);  l;delay(280); s;delay(50);
  }
  
  else if (sensorValues[7] < 900 && sensorValues[6] < 900 && sensorValues[5] < 900 && sensorValues[4] < 900 && sensorValues[3] < 900 && sensorValues[2] < 900 && sensorValues[1] < 900 && sensorValues[0] < 900)
  {//acute right
    f;
  }
  
  else
  {//Execute the PID algorithm
    unsigned int sensors[8];
    int position = qtrrc.readLine(sensors);//get calibrated readings along with the line position
    int error = position-3500;
    
    P = Kp * error;
    D = Kd * (error - lastError);
    
    int motorSpeed = P + D;
    lastError = error;
    
    int rightMotorSpeed = rightBaseSpeed + motorSpeed;
    int leftMotorSpeed = leftBaseSpeed - motorSpeed;
  
    if (rightMotorSpeed > rightMaxSpeed ) rightMotorSpeed = rightMaxSpeed; // prevent the motor from going beyond max speed
    if (leftMotorSpeed > leftMaxSpeed ) leftMotorSpeed = leftMaxSpeed; // prevent the motor from going beyond max speed
    if (rightMotorSpeed < 0) rightMotorSpeed = 0; // keep the motor speed positive
    if (leftMotorSpeed < 0) leftMotorSpeed = 0; // keep the motor speed positive
  
    //move forward with appropriate speeds
    digitalWrite(rightMotor1, HIGH);
    digitalWrite(rightMotor2, LOW);
    analogWrite(rightMotorPWM, rightMotorSpeed);
    digitalWrite(leftMotor1, HIGH);
    digitalWrite(leftMotor2, LOW);
    analogWrite(leftMotorPWM, leftMotorSpeed);
  }
}