First import from throwbot
robot.h@0:b74b6d70347d, 2014-10-05 (annotated)
- Committer:
- Throwbot
- Date:
- Sun Oct 05 12:21:03 2014 +0000
- Revision:
- 0:b74b6d70347d
Ebot Robot Code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Throwbot | 0:b74b6d70347d | 1 | #ifndef ROBOT_H |
Throwbot | 0:b74b6d70347d | 2 | #define ROBOT_H |
Throwbot | 0:b74b6d70347d | 3 | #include "QEI.h" |
Throwbot | 0:b74b6d70347d | 4 | #include "mbed.h" |
Throwbot | 0:b74b6d70347d | 5 | #include "rtos.h" |
Throwbot | 0:b74b6d70347d | 6 | #include "HC05.h" |
Throwbot | 0:b74b6d70347d | 7 | //#include "MPU6050.h" |
Throwbot | 0:b74b6d70347d | 8 | //#include "HC05.h" |
Throwbot | 0:b74b6d70347d | 9 | //#include "ACS712.h" |
Throwbot | 0:b74b6d70347d | 10 | //#include "MPU6050_6Axis_MotionApps20.h" |
Throwbot | 0:b74b6d70347d | 11 | //#include "DMP.h" |
Throwbot | 0:b74b6d70347d | 12 | //#include "IMUDATA.h" |
Throwbot | 0:b74b6d70347d | 13 | //#include "ADNS5090.h" |
Throwbot | 0:b74b6d70347d | 14 | #define BaudRate_bt 115200 //Baud rate of 9600 |
Throwbot | 0:b74b6d70347d | 15 | #define tx_bt PTA2 //Bluetooth connection pins |
Throwbot | 0:b74b6d70347d | 16 | #define rx_bt PTA1 //Bluetooth connection pins |
Throwbot | 0:b74b6d70347d | 17 | #define EN_BT PTA4 //Bluetooth connection pins |
Throwbot | 0:b74b6d70347d | 18 | //#define tx_mpu PTE0 //MPU connection pins |
Throwbot | 0:b74b6d70347d | 19 | //#define rx_mpu PTE1 //MPU connection pins |
Throwbot | 0:b74b6d70347d | 20 | //#define mpu_bandwidth MPU6050_BW_20 //set the MPU low pass filter bandwidth to 20hz |
Throwbot | 0:b74b6d70347d | 21 | |
Throwbot | 0:b74b6d70347d | 22 | #define myledd PTB8 //status LED pin |
Throwbot | 0:b74b6d70347d | 23 | #define CURRENTSENSOR_PIN PTB3 |
Throwbot | 0:b74b6d70347d | 24 | #define VOLTAGESENSOR_PIN PTB0 |
Throwbot | 0:b74b6d70347d | 25 | |
Throwbot | 0:b74b6d70347d | 26 | #define CURRENT_R1 180 //160.0 //values of the current sensor opamp resistors |
Throwbot | 0:b74b6d70347d | 27 | #define CURRENT_R2 10 |
Throwbot | 0:b74b6d70347d | 28 | #define CURRENT_R3 80 |
Throwbot | 0:b74b6d70347d | 29 | #define CURRENT_R4 84.7 |
Throwbot | 0:b74b6d70347d | 30 | #define VREF3_3 3.3 //digital logic voltage |
Throwbot | 0:b74b6d70347d | 31 | #define VREF5 5.0 //5v voltage //NOTE: 5v voltage is consistent when using new batts, but not using old blue batts |
Throwbot | 0:b74b6d70347d | 32 | |
Throwbot | 0:b74b6d70347d | 33 | |
Throwbot | 0:b74b6d70347d | 34 | //#define irL PTB1 |
Throwbot | 0:b74b6d70347d | 35 | //#define irC PTB3 |
Throwbot | 0:b74b6d70347d | 36 | //#define irR PTB2 |
Throwbot | 0:b74b6d70347d | 37 | |
Throwbot | 0:b74b6d70347d | 38 | #define LDR1 PTB1 |
Throwbot | 0:b74b6d70347d | 39 | #define LDR2 PTB2 |
Throwbot | 0:b74b6d70347d | 40 | #define buzz PTC8 |
Throwbot | 0:b74b6d70347d | 41 | |
Throwbot | 0:b74b6d70347d | 42 | #define MOT_PWMA_PIN PTA5 //Motor control pins |
Throwbot | 0:b74b6d70347d | 43 | #define MOT_PWMB_PIN PTA12 |
Throwbot | 0:b74b6d70347d | 44 | #define MOT_STBY_PIN PTE31 |
Throwbot | 0:b74b6d70347d | 45 | #define MOT_AIN1_PIN PTE30 |
Throwbot | 0:b74b6d70347d | 46 | #define MOT_AIN2_PIN PTE29 |
Throwbot | 0:b74b6d70347d | 47 | #define MOT_BIN1_PIN PTE24 |
Throwbot | 0:b74b6d70347d | 48 | #define MOT_BIN2_PIN PTE25 |
Throwbot | 0:b74b6d70347d | 49 | |
Throwbot | 0:b74b6d70347d | 50 | #define M_PI 3.14159265359 //PI |
Throwbot | 0:b74b6d70347d | 51 | #define gyroCorrect 3720 //divide raw gyro data by this to get result in RAD/SECOND (if gyroRange is 500 rad/s) |
Throwbot | 0:b74b6d70347d | 52 | |
Throwbot | 0:b74b6d70347d | 53 | //Correct direction of motors. If number = 1, forward. If number = 0, backwards (for if motors are wired backwards) |
Throwbot | 0:b74b6d70347d | 54 | #define MOTOR_R_DIRECTION 1 |
Throwbot | 0:b74b6d70347d | 55 | #define MOTOR_L_DIRECTION 1 |
Throwbot | 0:b74b6d70347d | 56 | |
Throwbot | 0:b74b6d70347d | 57 | #define MOTOR_INTERVAL 20 //defines the interval (in milliseconds) between when motor can be set |
Throwbot | 0:b74b6d70347d | 58 | //NOTE: Can't make this less than 20ms, because that is the PWM frequency |
Throwbot | 0:b74b6d70347d | 59 | |
Throwbot | 0:b74b6d70347d | 60 | //Key bindings for remote control robot - for the future try to use arrow keys instead of 'asdw' |
Throwbot | 0:b74b6d70347d | 61 | #define ctrl_forward 'i' //forward |
Throwbot | 0:b74b6d70347d | 62 | #define ctrl_backward 'k' //back |
Throwbot | 0:b74b6d70347d | 63 | #define ctrl_left 'j' //turn left |
Throwbot | 0:b74b6d70347d | 64 | #define ctrl_right 'l' //turn right |
Throwbot | 0:b74b6d70347d | 65 | #define ctrl_calibrate 'c' //re-calibrate the accelerometer and gyro |
Throwbot | 0:b74b6d70347d | 66 | #define ctrl_turn_angle_cw 'o' // turn angle |
Throwbot | 0:b74b6d70347d | 67 | #define ctrl_turn_angle_ccw 'p' |
Throwbot | 0:b74b6d70347d | 68 | // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's |
Throwbot | 0:b74b6d70347d | 69 | // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019) |
Throwbot | 0:b74b6d70347d | 70 | // only handles 4 byte transfers in the ATMega code. |
Throwbot | 0:b74b6d70347d | 71 | #define TRANSFER_SIZE 4 |
Throwbot | 0:b74b6d70347d | 72 | |
Throwbot | 0:b74b6d70347d | 73 | extern HC05 bt; //bluetooth connection |
Throwbot | 0:b74b6d70347d | 74 | //extern Serial bt; |
Throwbot | 0:b74b6d70347d | 75 | //extern QEI wheel; |
Throwbot | 0:b74b6d70347d | 76 | extern QEI left; |
Throwbot | 0:b74b6d70347d | 77 | extern QEI right; |
Throwbot | 0:b74b6d70347d | 78 | //extern MPU6050 mpu; //MPU connection |
Throwbot | 0:b74b6d70347d | 79 | extern DigitalOut myled; //(PTE3) Processor LED (1 = off, 0 = on) |
Throwbot | 0:b74b6d70347d | 80 | //extern DigitalOut btSwitch; |
Throwbot | 0:b74b6d70347d | 81 | //extern AnalogIn currentSensor; |
Throwbot | 0:b74b6d70347d | 82 | extern DigitalOut buzzer; |
Throwbot | 0:b74b6d70347d | 83 | extern DigitalOut key; |
Throwbot | 0:b74b6d70347d | 84 | //extern PwmOut buzzer; |
Throwbot | 0:b74b6d70347d | 85 | extern AnalogIn LDRsensor1; |
Throwbot | 0:b74b6d70347d | 86 | extern AnalogIn LDRsensor2; |
Throwbot | 0:b74b6d70347d | 87 | //extern AnalogIn voltageSensor; |
Throwbot | 0:b74b6d70347d | 88 | /////////// Motor control variables /////////// |
Throwbot | 0:b74b6d70347d | 89 | extern PwmOut PWMA;//(MOT_PWMA_PIN); |
Throwbot | 0:b74b6d70347d | 90 | extern PwmOut PWMB;//(MOT_PWMB_PIN); |
Throwbot | 0:b74b6d70347d | 91 | extern DigitalOut AIN1;//(MOT_AIN1_PIN); |
Throwbot | 0:b74b6d70347d | 92 | extern DigitalOut AIN2;//(MOT_AIN2_PIN); |
Throwbot | 0:b74b6d70347d | 93 | extern DigitalOut BIN1;//(MOT_BIN1_PIN); |
Throwbot | 0:b74b6d70347d | 94 | extern DigitalOut BIN2;//(MOT_BIN2_PIN); |
Throwbot | 0:b74b6d70347d | 95 | extern DigitalOut STBY;//(MOT_STBY_PIN); |
Throwbot | 0:b74b6d70347d | 96 | void motor_control(int Lspeed, int Rspeed); //Input speed for motors. Integer between 0 and 100 |
Throwbot | 0:b74b6d70347d | 97 | void stop(); //stop motors |
Throwbot | 0:b74b6d70347d | 98 | void set_direction(double angle); //set angle for the robot to face (from origin) |
Throwbot | 0:b74b6d70347d | 99 | void set_direction_deg(double angle); |
Throwbot | 0:b74b6d70347d | 100 | void set_speed(int Speed ); //set speed for robot to travel at |
Throwbot | 0:b74b6d70347d | 101 | void auto_enable(bool x); |
Throwbot | 0:b74b6d70347d | 102 | /** |
Throwbot | 0:b74b6d70347d | 103 | * MPU CONTROLS |
Throwbot | 0:b74b6d70347d | 104 | */ |
Throwbot | 0:b74b6d70347d | 105 | // calibrate the gyro and accelerometer // |
Throwbot | 0:b74b6d70347d | 106 | void calibrate(); |
Throwbot | 0:b74b6d70347d | 107 | /** |
Throwbot | 0:b74b6d70347d | 108 | * Status: find the distance, orientation, battery values, etc of the robot |
Throwbot | 0:b74b6d70347d | 109 | */ |
Throwbot | 0:b74b6d70347d | 110 | //void distanceTravelled(double x[3]) |
Throwbot | 0:b74b6d70347d | 111 | //void orientation(something quaternion? on xy plane?) |
Throwbot | 0:b74b6d70347d | 112 | double getCurrent(); //Get the current drawn by the robot |
Throwbot | 0:b74b6d70347d | 113 | double getCurrent(int n); //get the current, averaged over n samples |
Throwbot | 0:b74b6d70347d | 114 | double getVoltage(); //get the battery voltage (ask connor for completed function) |
Throwbot | 0:b74b6d70347d | 115 | void getIMU(float *adata, float *gdata); |
Throwbot | 0:b74b6d70347d | 116 | double ldrread1(); |
Throwbot | 0:b74b6d70347d | 117 | double ldrread2(); |
Throwbot | 0:b74b6d70347d | 118 | //void pl_buzzer1(); |
Throwbot | 0:b74b6d70347d | 119 | void Led_on(); |
Throwbot | 0:b74b6d70347d | 120 | void Led_off(); |
Throwbot | 0:b74b6d70347d | 121 | double return_rotation(); |
Throwbot | 0:b74b6d70347d | 122 | int isMPU(); |
Throwbot | 0:b74b6d70347d | 123 | void initRobot(); |
Throwbot | 0:b74b6d70347d | 124 | extern double pl_buzzer(); |
Throwbot | 0:b74b6d70347d | 125 | extern void pl_buzzer(void const *args); |
Throwbot | 0:b74b6d70347d | 126 | extern int freq; |
Throwbot | 0:b74b6d70347d | 127 | extern int rMotor; |
Throwbot | 0:b74b6d70347d | 128 | extern int lMotor ; |
Throwbot | 0:b74b6d70347d | 129 | extern int m_speed; |
Throwbot | 0:b74b6d70347d | 130 | extern Mutex stdio_mutex; |
Throwbot | 0:b74b6d70347d | 131 | |
Throwbot | 0:b74b6d70347d | 132 | |
Throwbot | 0:b74b6d70347d | 133 | //Wireless connections |
Throwbot | 0:b74b6d70347d | 134 | |
Throwbot | 0:b74b6d70347d | 135 | #endif |