Changeset c9a4851 in robotics for car/firmware/car/car.ino


Ignore:
Timestamp:
06/16/14 16:31:47 (8 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master
Children:
784ff02
Parents:
3a28fb6
Message:
  • direction controls added
File:
1 edited

Legend:

Unmodified
Added
Removed
  • car/firmware/car/car.ino

    r3a28fb6 rc9a4851  
    3636#define SERVO_PIN_TURN 9 
    3737 
     38#define POSITION_BRAKE_STOP 150 
     39#define POSITION_BRAKE_GO 30 
     40 
     41#define POSITION_DIRECTION_LEFT 30 
     42#define POSITION_DIRECTION_STRAIGHT 90 
     43#define POSITION_DIRECTION_RIGHT 150 
     44 
     45#define POSITION_TURN_STOP 150 
     46#define POSITION_TURN_GO 30 
     47 
     48#define TIME_DRIVE_FORWARD 2000 // Drive forward for two seconds per detection 
     49#define TIME_TURN 1000 // Turn wheel for one second per detection 
     50#define TIME_TURN_DRIVE 2000 // Drive forward to two seconds while turning 
     51 
    3852Servo servoBrake; 
    3953Servo servoDirection; 
     
    5771  servoDirection.attach(SERVO_PIN_DIRECTION); 
    5872  servoTurn.attach(SERVO_PIN_TURN); 
     73   
     74  servoBrake.write(POSITION_BRAKE_STOP); 
     75  servoDirection.write(POSITION_DIRECTION_STRAIGHT); 
     76  servoTurn.write(POSITION_TURN_STOP); 
     77   
    5978 
    6079} // setup 
     
    163182  #endif 
    164183   
     184  servoBrake.write(POSITION_BRAKE_GO); 
     185   
     186  delay(TIME_DRIVE_FORWARD); 
     187   
     188  servoBrake.write(POSITION_BRAKE_STOP); 
     189   
    165190} 
    166191 
     
    173198  #endif 
    174199   
     200  servoBrake.write(POSITION_BRAKE_STOP); 
     201   
    175202} 
    176203 
     
    183210  #endif 
    184211   
     212  // Select direction 
     213  servoDirection.write(POSITION_DIRECTION_LEFT); 
     214   
     215  // Turn wheel 
     216  servoTurn.write(POSITION_TURN_GO); 
     217  delay(TIME_TURN); 
     218  servoTurn.write(POSITION_TURN_STOP); 
     219   
     220  // Release brake 
     221  servoBrake.write(POSITION_BRAKE_GO); 
     222   
     223  // Drive while turning 
     224  delay(TIME_TURN_DRIVE); 
     225   
     226  // Apply brake 
     227  servoBrake.write(POSITION_BRAKE_STOP); 
     228   
     229  // Reset wheel 
     230  servoDirection.write(POSITION_DIRECTION_RIGHT); 
     231  servoTurn.write(POSITION_TURN_GO); 
     232  delay(TIME_TURN); 
     233  servoTurn.write(POSITION_TURN_STOP); 
     234   
     235  // Reset direction 
     236  servoDirection.write(POSITION_DIRECTION_STRAIGHT); 
     237   
    185238} 
    186239 
     
    193246  #endif 
    194247   
    195 } 
    196  
    197 // ################################################################ 
     248  // Select direction 
     249  servoDirection.write(POSITION_DIRECTION_RIGHT); 
     250   
     251  // Turn wheel 
     252  servoTurn.write(POSITION_TURN_GO); 
     253  delay(TIME_TURN); 
     254  servoTurn.write(POSITION_TURN_STOP); 
     255   
     256  // Release brake 
     257  servoBrake.write(POSITION_BRAKE_GO); 
     258   
     259  // Drive while turning 
     260  delay(TIME_TURN_DRIVE); 
     261   
     262  // Apply brake 
     263  servoBrake.write(POSITION_BRAKE_STOP); 
     264   
     265  // Reset wheel 
     266  servoDirection.write(POSITION_DIRECTION_LEFT); 
     267  servoTurn.write(POSITION_TURN_GO); 
     268  delay(TIME_TURN); 
     269  servoTurn.write(POSITION_TURN_STOP); 
     270   
     271  // Reset direction 
     272  servoDirection.write(POSITION_DIRECTION_STRAIGHT); 
     273   
     274} 
     275 
     276// ################################################################ 
Note: See TracChangeset for help on using the changeset viewer.