Initial Commit

Committer:
Throwbot
Date:
Tue Oct 21 21:29:54 2014 +0000
Revision:
5:a95a6243c118
Parent:
4:0eeea5f05e28
Initial (Test) Commit

Who changed what in which revision?

UserRevisionLine numberNew 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 1:282467cbebb3 7 #include "MPU6050.h"
Throwbot 1:282467cbebb3 8 #include "I2Cdev.h"
Throwbot 4:0eeea5f05e28 9
Throwbot 4:0eeea5f05e28 10 #include "motors.h"
Throwbot 0:b74b6d70347d 11 //#include "MPU6050.h"
Throwbot 0:b74b6d70347d 12 //#include "HC05.h"
Throwbot 0:b74b6d70347d 13 //#include "ACS712.h"
Throwbot 0:b74b6d70347d 14 //#include "MPU6050_6Axis_MotionApps20.h"
Throwbot 0:b74b6d70347d 15 //#include "DMP.h"
Throwbot 0:b74b6d70347d 16 //#include "IMUDATA.h"
Throwbot 0:b74b6d70347d 17 //#include "ADNS5090.h"
Throwbot 0:b74b6d70347d 18 #define BaudRate_bt 115200 //Baud rate of 9600
Throwbot 0:b74b6d70347d 19 #define tx_bt PTA2 //Bluetooth connection pins
Throwbot 0:b74b6d70347d 20 #define rx_bt PTA1 //Bluetooth connection pins
Throwbot 0:b74b6d70347d 21 #define EN_BT PTA4 //Bluetooth connection pins
Throwbot 0:b74b6d70347d 22 //#define tx_mpu PTE0 //MPU connection pins
Throwbot 0:b74b6d70347d 23 //#define rx_mpu PTE1 //MPU connection pins
Throwbot 0:b74b6d70347d 24 //#define mpu_bandwidth MPU6050_BW_20 //set the MPU low pass filter bandwidth to 20hz
Throwbot 0:b74b6d70347d 25
Throwbot 0:b74b6d70347d 26 #define myledd PTB8 //status LED pin
Throwbot 0:b74b6d70347d 27 #define CURRENTSENSOR_PIN PTB3
Throwbot 0:b74b6d70347d 28 #define VOLTAGESENSOR_PIN PTB0
Throwbot 0:b74b6d70347d 29
Throwbot 0:b74b6d70347d 30 #define CURRENT_R1 180 //160.0 //values of the current sensor opamp resistors
Throwbot 0:b74b6d70347d 31 #define CURRENT_R2 10
Throwbot 0:b74b6d70347d 32 #define CURRENT_R3 80
Throwbot 0:b74b6d70347d 33 #define CURRENT_R4 84.7
Throwbot 0:b74b6d70347d 34 #define VREF3_3 3.3 //digital logic voltage
Throwbot 0:b74b6d70347d 35 #define VREF5 5.0 //5v voltage //NOTE: 5v voltage is consistent when using new batts, but not using old blue batts
Throwbot 0:b74b6d70347d 36
Throwbot 0:b74b6d70347d 37
Throwbot 0:b74b6d70347d 38 //#define irL PTB1
Throwbot 0:b74b6d70347d 39 //#define irC PTB3
Throwbot 0:b74b6d70347d 40 //#define irR PTB2
Throwbot 0:b74b6d70347d 41
Throwbot 0:b74b6d70347d 42 #define LDR1 PTB1
Throwbot 0:b74b6d70347d 43 #define LDR2 PTB2
Throwbot 0:b74b6d70347d 44 #define buzz PTC8
Throwbot 0:b74b6d70347d 45
Throwbot 0:b74b6d70347d 46 #define MOT_PWMA_PIN PTA5 //Motor control pins
Throwbot 0:b74b6d70347d 47 #define MOT_PWMB_PIN PTA12
Throwbot 0:b74b6d70347d 48 #define MOT_STBY_PIN PTE31
Throwbot 0:b74b6d70347d 49 #define MOT_AIN1_PIN PTE30
Throwbot 0:b74b6d70347d 50 #define MOT_AIN2_PIN PTE29
Throwbot 0:b74b6d70347d 51 #define MOT_BIN1_PIN PTE24
Throwbot 0:b74b6d70347d 52 #define MOT_BIN2_PIN PTE25
Throwbot 0:b74b6d70347d 53
Throwbot 0:b74b6d70347d 54 #define M_PI 3.14159265359 //PI
Throwbot 0:b74b6d70347d 55 #define gyroCorrect 3720 //divide raw gyro data by this to get result in RAD/SECOND (if gyroRange is 500 rad/s)
Throwbot 0:b74b6d70347d 56
Throwbot 0:b74b6d70347d 57 //Correct direction of motors. If number = 1, forward. If number = 0, backwards (for if motors are wired backwards)
Throwbot 0:b74b6d70347d 58 #define MOTOR_R_DIRECTION 1
Throwbot 0:b74b6d70347d 59 #define MOTOR_L_DIRECTION 1
Throwbot 4:0eeea5f05e28 60 #define L_MOTOR_SCALE 1
Throwbot 4:0eeea5f05e28 61 #define R_MOTOR_SCALE 1
Throwbot 0:b74b6d70347d 62 #define MOTOR_INTERVAL 20 //defines the interval (in milliseconds) between when motor can be set
Throwbot 0:b74b6d70347d 63 //NOTE: Can't make this less than 20ms, because that is the PWM frequency
Throwbot 0:b74b6d70347d 64
Throwbot 0:b74b6d70347d 65 //Key bindings for remote control robot - for the future try to use arrow keys instead of 'asdw'
Throwbot 0:b74b6d70347d 66 #define ctrl_forward 'i' //forward
Throwbot 0:b74b6d70347d 67 #define ctrl_backward 'k' //back
Throwbot 0:b74b6d70347d 68 #define ctrl_left 'j' //turn left
Throwbot 0:b74b6d70347d 69 #define ctrl_right 'l' //turn right
Throwbot 0:b74b6d70347d 70 #define ctrl_calibrate 'c' //re-calibrate the accelerometer and gyro
Throwbot 0:b74b6d70347d 71 #define ctrl_turn_angle_cw 'o' // turn angle
Throwbot 0:b74b6d70347d 72 #define ctrl_turn_angle_ccw 'p'
Throwbot 0:b74b6d70347d 73 // The nRF24L01+ supports transfers from 1 to 32 bytes, but Sparkfun's
Throwbot 0:b74b6d70347d 74 // "Nordic Serial Interface Board" (http://www.sparkfun.com/products/9019)
Throwbot 0:b74b6d70347d 75 // only handles 4 byte transfers in the ATMega code.
Throwbot 0:b74b6d70347d 76 #define TRANSFER_SIZE 4
Throwbot 1:282467cbebb3 77 #define ulrL PTD6
Throwbot 1:282467cbebb3 78 #define ulL PTD5
Throwbot 1:282467cbebb3 79 #define ulF PTD1
Throwbot 1:282467cbebb3 80 #define ulR PTC2
Throwbot 1:282467cbebb3 81 #define ulrR PTC1
Throwbot 1:282467cbebb3 82 #define ulB PTC0
Throwbot 1:282467cbebb3 83
Throwbot 1:282467cbebb3 84
Throwbot 4:0eeea5f05e28 85 extern Motors motors;
Throwbot 0:b74b6d70347d 86 extern HC05 bt; //bluetooth connection
Throwbot 0:b74b6d70347d 87 //extern Serial bt;
Throwbot 0:b74b6d70347d 88 //extern QEI wheel;
Throwbot 0:b74b6d70347d 89 extern QEI left;
Throwbot 0:b74b6d70347d 90 extern QEI right;
Throwbot 0:b74b6d70347d 91 //extern MPU6050 mpu; //MPU connection
Throwbot 0:b74b6d70347d 92 extern DigitalOut myled; //(PTE3) Processor LED (1 = off, 0 = on)
Throwbot 0:b74b6d70347d 93 //extern DigitalOut btSwitch;
Throwbot 0:b74b6d70347d 94 //extern AnalogIn currentSensor;
Throwbot 0:b74b6d70347d 95 extern DigitalOut buzzer;
Throwbot 1:282467cbebb3 96 extern DigitalOut key;\
Throwbot 0:b74b6d70347d 97 //extern PwmOut buzzer;
Throwbot 0:b74b6d70347d 98 extern AnalogIn LDRsensor1;
Throwbot 0:b74b6d70347d 99 extern AnalogIn LDRsensor2;
Throwbot 0:b74b6d70347d 100 //extern AnalogIn voltageSensor;
Throwbot 0:b74b6d70347d 101 /////////// Motor control variables ///////////
Throwbot 0:b74b6d70347d 102 extern PwmOut PWMA;//(MOT_PWMA_PIN);
Throwbot 0:b74b6d70347d 103 extern PwmOut PWMB;//(MOT_PWMB_PIN);
Throwbot 0:b74b6d70347d 104 extern DigitalOut AIN1;//(MOT_AIN1_PIN);
Throwbot 0:b74b6d70347d 105 extern DigitalOut AIN2;//(MOT_AIN2_PIN);
Throwbot 0:b74b6d70347d 106 extern DigitalOut BIN1;//(MOT_BIN1_PIN);
Throwbot 0:b74b6d70347d 107 extern DigitalOut BIN2;//(MOT_BIN2_PIN);
Throwbot 0:b74b6d70347d 108 extern DigitalOut STBY;//(MOT_STBY_PIN);
Throwbot 1:282467cbebb3 109
Throwbot 1:282467cbebb3 110 extern DigitalOut SRX;
Throwbot 1:282467cbebb3 111
Throwbot 1:282467cbebb3 112 extern AnalogIn uL;
Throwbot 1:282467cbebb3 113 extern AnalogIn uF;
Throwbot 1:282467cbebb3 114 extern AnalogIn uR;
Throwbot 1:282467cbebb3 115 extern AnalogIn urR;
Throwbot 1:282467cbebb3 116 extern AnalogIn urL;
Throwbot 1:282467cbebb3 117 extern AnalogIn uB;
Throwbot 1:282467cbebb3 118 extern int dy;
Throwbot 1:282467cbebb3 119 extern int dx;
Throwbot 3:3e3314102e56 120 extern int Rmotor_speed;
Throwbot 3:3e3314102e56 121 extern int Lmotor_speed;
Throwbot 1:282467cbebb3 122 int r_time ();
Throwbot 0:b74b6d70347d 123 void motor_control(int Lspeed, int Rspeed); //Input speed for motors. Integer between 0 and 100
Throwbot 0:b74b6d70347d 124 void stop(); //stop motors
Throwbot 0:b74b6d70347d 125 void set_direction(double angle); //set angle for the robot to face (from origin)
Throwbot 0:b74b6d70347d 126 void set_direction_deg(double angle);
Throwbot 0:b74b6d70347d 127 void set_speed(int Speed ); //set speed for robot to travel at
Throwbot 0:b74b6d70347d 128 void auto_enable(bool x);
Throwbot 0:b74b6d70347d 129 /**
Throwbot 0:b74b6d70347d 130 * MPU CONTROLS
Throwbot 0:b74b6d70347d 131 */
Throwbot 0:b74b6d70347d 132 // calibrate the gyro and accelerometer //
Throwbot 0:b74b6d70347d 133 void calibrate();
Throwbot 0:b74b6d70347d 134 /**
Throwbot 0:b74b6d70347d 135 * Status: find the distance, orientation, battery values, etc of the robot
Throwbot 0:b74b6d70347d 136 */
Throwbot 0:b74b6d70347d 137 //void distanceTravelled(double x[3])
Throwbot 0:b74b6d70347d 138 //void orientation(something quaternion? on xy plane?)
Throwbot 0:b74b6d70347d 139 double getCurrent(); //Get the current drawn by the robot
Throwbot 0:b74b6d70347d 140 double getCurrent(int n); //get the current, averaged over n samples
Throwbot 0:b74b6d70347d 141 double getVoltage(); //get the battery voltage (ask connor for completed function)
Throwbot 0:b74b6d70347d 142 double ldrread1();
Throwbot 0:b74b6d70347d 143 double ldrread2();
Throwbot 0:b74b6d70347d 144 void Led_on();
Throwbot 0:b74b6d70347d 145 void Led_off();
Throwbot 0:b74b6d70347d 146 void initRobot();
Throwbot 0:b74b6d70347d 147 extern double pl_buzzer();
Throwbot 4:0eeea5f05e28 148 extern void pl_buzzer(int freq, int f_time);
Throwbot 1:282467cbebb3 149 extern void Imu_yaw(void const *args);
Throwbot 1:282467cbebb3 150 extern void encoder_thread(void const *args);
Throwbot 0:b74b6d70347d 151 extern int freq;
Throwbot 0:b74b6d70347d 152 extern int rMotor;
Throwbot 0:b74b6d70347d 153 extern int lMotor ;
Throwbot 0:b74b6d70347d 154 extern int m_speed;
Throwbot 0:b74b6d70347d 155 extern Mutex stdio_mutex;
Throwbot 1:282467cbebb3 156 extern MPU6050 accelgyro;
Throwbot 1:282467cbebb3 157 extern int16_t ax, ay, az;
Throwbot 1:282467cbebb3 158 extern int16_t gx, gy, gz;
Throwbot 1:282467cbebb3 159 extern int heading;
Throwbot 2:37a19a9e5f2c 160 extern int software_interuupt;
Throwbot 4:0eeea5f05e28 161 extern int Encoder_x;
Throwbot 4:0eeea5f05e28 162 extern int Encoder_y;
Throwbot 4:0eeea5f05e28 163 extern char Selected_robot;
Throwbot 4:0eeea5f05e28 164 extern bool bt_connected;
Throwbot 0:b74b6d70347d 165 //Wireless connections
Throwbot 0:b74b6d70347d 166
Throwbot 0:b74b6d70347d 167 #endif