Browse Source

Update v1.2

master
cs161079 5 years ago
parent
commit
5fb8fd1fd3
  1. 77
      autonomousCar/autonomousCar.ino

77
autonomousCar/autonomousCar.ino

@ -51,6 +51,9 @@
*/ */
#define SERVOPIN 6 #define SERVOPIN 6
/*Definition for turn time*/
#define TURN_TIME 500
/* /*
* ------------------------------------------------------- * -------------------------------------------------------
* Define Servo Data Struct * Define Servo Data Struct
@ -72,6 +75,7 @@ int pos, dir;
/* /*
* Turn Servo using custom Speed * Turn Servo using custom Speed
*/ */
/*Function that takes as arguments from->first position and deg->next position */
void turnServo(int from, int deg){ void turnServo(int from, int deg){
int d; int d;
if (from > deg){ if (from > deg){
@ -251,29 +255,64 @@ void moveCar(){
} }
} }
void park() {
turnRight(255);
forward();
delay(TURN_TIME);
motor_stop();
forward();
delay(400);
}
String inString;
void Serial_Input()
{
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char and add it to the string:
inString += (char)inChar;
}
// if you get a newline, print the string, then the string's value:
if (inChar == '\n') {
Serial.print("Value:");
Serial.println(inString.toInt());
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
}
}
}
void loop() { void loop() {
// Calculating the distance // Calculating the distance
distance= getDistance(); //distance= getDistance();
// Prints the distance on the Serial Monitor // Prints the distance on the Serial Monitor
//Serial.print("Distance: "); //Serial.print("Distance: ");
//Serial.println(distance); //Serial.println(distance);
// Read serial input:
if (distance <15) { Serial_Input();
// Change direction to motors //park();
turn(225); //delay(1000);
} else if (distance <13){ // if (distance <15) {
turn(200); // // Change direction to motors
} else { // turn(225);
// Change direction to motors // } else if (distance <13){
turn(MAX_WHEEL_SPEED); // turn(200);
} // } else {
if (distance < 6){ // // Change direction to motors
motor_stop(); // turn(MAX_WHEEL_SPEED);
// Set Ultrasonic to next step // }
next_step(); // if (distance < 6){
// Move car // motor_stop();
moveCar(); // // Set Ultrasonic to next step
} // next_step();
delay(100); // // Move car
// moveCar();
// }
// delay(100);
} }

Loading…
Cancel
Save