### Author Topic: 50\$ robot - code question  (Read 498 times)

0 Members and 1 Guest are viewing this topic.

#### garriwilson

• Supreme Robot
• Posts: 345
##### 50\$ robot - code question
« on: December 24, 2013, 04:10:14 PM »
So this is part of the main code for the 50\$ robot:

Code: [Select]
`while(1) { //store sensor data sensor_left=a2dConvert8bit(5); sensor_right=a2dConvert8bit(4); //detects more light on left side of robot if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold) {//go left servo_left(44); servo_right(44); } //detects more light on right side of robot else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold) {//go right servo_left(25); servo_right(25); } //light is about equal on both sides else {//go straight servo_left(25); servo_right(44); }`
I don't understand the servo speeds. For going straight, shouldn't they be equal? And for going right or left, they should be not equal? Here for going straight the settings are servo_left(25) and servo_right(44), and for going left or right the speeds are equal. How does this work?

#### garriwilson

• Supreme Robot
• Posts: 345
##### Re: 50\$ robot - code question
« Reply #1 on: December 25, 2013, 01:28:33 PM »
For reference, these are the servo_left and servo_right functions:

Code: [Select]
`void servo_left(signed long int speed) { PORT_ON(PORTD, 0); delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off delay_cycles(200); }void servo_right(signed long int speed) { PORT_ON(PORTD, 1); delay_cycles(speed); PORT_OFF(PORTD, 1);//keep off delay_cycles(200); }`

#### garriwilson

• Supreme Robot
• Posts: 345