new text document (2)

Download New Text Document (2)

If you can't read please download the document

Upload: gin220

Post on 02-Oct-2015

2 views

Category:

Documents


0 download

DESCRIPTION

dos

TRANSCRIPT

/* Command codes for the various commands that the firebird can accept*/2#define BUZZER_ON 65#define BUZZER_OFF 66#define MOVE_FORWARD 67#define MOVE_BACKWARD 68#define MOVE_RIGHT 69#define MOVE_LEFT 70#define STOP 71#define WHITELINE_FOLLOW_START 74#define WHITELINE_FOLLOW_END 75#define WHITELINE_STOP_INTERSECTION 76#define ACC_START 77#define ACC_STOP 78#define ACC_CHECK 79#define ACC_MODIFIED 80#define PRINT_STATE 90#define DISCONNECT 120#define LCD_SET_STRING 32#define SET_PORT 33#define GET_SENSOR_VALUE 34#define GET_PORT 35#define SET_VELOCITY 36#define MOVE_BY 37#define TURN_LEFT_BY 38#define TURN_RIGHT_BY 39#define MOVE_BACK_BY 40//! velocity control /*! Function for setting velocities of both wheels. pulse width modulation */void velocity (unsigned char left_motor, unsigned char right_motor){OCR5AL = (unsigned char)left_motor;OCR5BL = (unsigned char)right_motor;leftVel=left_motor;rightVel=right_motor;}//! setting motor's direction /*! Function used for setting motor's direction */void motion_set (unsigned char Direction){ unsigned char PortARestore = 0; Direction &= 0x0F; // removing upper nibbel for the protection PortARestore = PORTA; // reading the PORTA original status PortARestore &= 0xF0; // making lower direction nibbel to 0 PortARestore |= Direction; // adding lower nibbel for forward command and restoring the PORTA status PORTA = PortARestore; // executing the command}//! setting motor's forward /*! Function used for setting motor's direction forward */void forward (void) { motion_set (0x06);}//! setting motor's direction back /*! Function used for setting motor's direction back */void back (void) //both wheels backward{ motion_set(0x09);}//! setting motor's direction left /*! Function used for setting motor's direction left */void left (void) //Left wheel backward, Right wheel forward{ motion_set(0x05);}//! setting motor's direction right /*! Function used for setting motor's direction right */void right (void) //Left wheel forward, Right wheel backward{ motion_set(0x0A);}//! setting motor's direction soft left /*! Function used for setting motor's direction soft left */void soft_left (void) //Left wheel stationary, Right wheel forward{ motion_set(0x04);}//! setting motor's direction soft right /*! Function used for setting motor's direction soft right Left wheel forward, Right wheel is stationary */void soft_right (void) //Left wheel forward, Right wheel is stationary{ motion_set(0x02);}//! setting motor's direction soft left /*! Function used for setting motor's direction soft left Left wheel backward, right wheel stationary */void soft_left_2 (void) //Left wheel backward, right wheel stationary{ motion_set(0x01);}//! setting motor's direction soft right /*! Function used for setting motor's direction Left wheel stationary, Right wheel backward */void soft_right_2 (void) //Left wheel stationary, Right wheel backward{ motion_set(0x08);}//! stop the bot /*! Function used for stoping the bot. */void stop (void){ motion_set (0x00);}//Function to split and send an integer over the communication channelvoid send_int (int i) {if (USE_BLUETOOTH) {unsigned char c = (i >> 24) & 0xFF;send_data_bt (c);c = (i >> 16) & 0xFF;send_data_bt (c);c = (i >> 8) & 0xFF;send_data_bt (c);c = i & 0xFF;send_data_bt (c);}else {char str[10];itoa(i,str,10);serial_sendString(str);}}