ItR Mini Project 1: Painting Robot
Brief pics
Building Procedure
At the very beginning, all the materials we got is the Cherokey 4WD kit. Our initial idea is to build the robot following the Cherokey Instruction Manual provided by the manufacturer.
After finishing the installation of the motors and the Arduino board, we installed the server onto the robot.
Then we wanted to make the robot have the ability to detect the environment using its supersonic sensor. However, we can’t install the necessary library mentioned in the manual to control the supersonic sensor. Although we’ve already able to control the server.
We ask our instructor Rudi for help. He gave us another infrared sensor which is much easier to use and control. So we removed the server, supersonic sensor, and the top board. After installing the infrared sensor, the prototype of our robot has been made.
After finishing the basic assembling of the robot, we started working with the code. We copied the test code from the manufacturer’s website and the robot worked well. After that, we manage to code the action on our own. At this time, we found that the control function has some problems. The “advance” function written by the manufacturer led our robot to turn left. Also, the “back” function led our robot to turn right. After checking the correctness of our cables and wires, we still have no idea about this. So we change the function on our own (by changing the “LOW” & “HIGH” index in the code to let turn left become advance, let advance become turn left… etc) and it worked finally.
Afterward, we write a code for obstacle avoidance. It can utilize the sensor to detect the obstacles in front of it. When there are obstacles, it will move back and forth at the former position.
As for the pattern we intended to draw, at first we want to draw a feather or leaf. We failed many times due to the unstable friction on the ground and canvas. In this case, we decided to draw the letter B as the symbolization of BOT. We asked Rudi for some paper to simulate the friction on the canvas and tried many times.
The code is as follows:
int speedPin_M1 = 5; //M1 Speed Control
int speedPin_M2 = 6; //M2 Speed Control
int directionPin_M1 = 4; //M1 Direction Control
int directionPin_M2 = 7; //M1 Direction Control
int sensor = 2; //Sensor Control
void setup(){
pinMode(2, INPUT);
int i;
for (i = 4; i <= 7; i++)
pinMode(i, OUTPUT);
}
void loop(){
int sensorState = digitalRead(sensor);
if (sensorState == 1){
carAdvance(250,250);
delay(3000);
carTurnRight(250,100);
delay(7500);
carTurnRight(250,250);
delay(2500);
carAdvance(250,0);
delay(8000);
carTurnRight(250,250);
delay(1300);
carStop();
delay(1000000);
// for (int j = 0; j <= 100; j ++){
// carBack(250,250);
// delay(100);
// }
}
// }else{
// for (int j = 0; j <= 10; j ++){
// carBack(250,250);
// }
// }
}
void carStop(){ // Motor Stop
digitalWrite(speedPin_M2,0);
digitalWrite(directionPin_M1,LOW);
digitalWrite(speedPin_M1,0);
digitalWrite(directionPin_M2,LOW);
}
void carTurnLeft(int leftSpeed,int rightSpeed){ //Move backward
analogWrite (speedPin_M2,leftSpeed); //PWM Speed Control
digitalWrite(directionPin_M1,HIGH);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,HIGH);
}
void carTurnRight(int leftSpeed,int rightSpeed){ //Move forward
analogWrite (speedPin_M2,leftSpeed);
digitalWrite(directionPin_M1,LOW);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,LOW);
}
void carBack(int leftSpeed,int rightSpeed){ //Turn Left
analogWrite (speedPin_M2,leftSpeed);
digitalWrite(directionPin_M1,LOW);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,HIGH);
}
void carAdvance(int leftSpeed,int rightSpeed){ //Turn Right
analogWrite (speedPin_M2,leftSpeed);
digitalWrite(directionPin_M1,HIGH);
analogWrite (speedPin_M1,rightSpeed);
digitalWrite(directionPin_M2,LOW);
}