Code for our FYDP -only one IMU works right now -RTOS is working

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers robot.cpp Source File

robot.cpp

00001 #include "robot.h"
00002 #include "bot08_cal.h"
00003 
00004 /**Note: Initialize ALL UNUSED ANALOG IN pins as digital out to reduce noise on analog reads*//////
00005 
00006 DigitalOut      led(LED_PIN);
00007 
00008 HC05            bt(TX_BT,RX_BT,EN_BT);
00009 
00010 AnalogIn irL(IR_L);
00011 AnalogIn irC(IR_C);
00012 AnalogIn irR(IR_R);
00013 DigitalOut irBack(IR_B);
00014 AnalogIn voltage_sensor(VOLTAGESENSOR_PIN);
00015 
00016 ACS712          current_sensor;
00017 ADNS5090        opt_flow_L(MOSI_MOUSE,MISO_MOUSE,SCLK_MOUSE,NCS_MOUSE_L,L_MOUSE_PX_PER_MM);
00018 ADNS5090        opt_flow_R(MOSI_MOUSE,MISO_MOUSE,SCLK_MOUSE,NCS_MOUSE_R,R_MOUSE_PX_PER_MM);
00019 Reckon          reckon(opt_flow_L, opt_flow_R, MOUSE_DISTANCE);
00020 
00021 MPU6050 mpu;
00022 MPU6051 mpu2;
00023 DigitalOut imuSwitch(IMU_POWER_PIN);
00024 DigitalOut imu2Switch(IMU2_POWER_PIN);
00025 IMU_DATA imu_data;
00026 IMU_DATA imu2_data;
00027 
00028 TB6612 MotorA(MOT_PWMA_PIN, MOT_AIN1_PIN, MOT_AIN2_PIN);
00029 TB6612 MotorB(MOT_PWMB_PIN, MOT_BIN1_PIN, MOT_BIN2_PIN);
00030 Motors motors( &MotorA, &MotorB, MOT_STBY_PIN);
00031 
00032 nRF24L01P rf(PTD2, PTD3, PTD1, PTD0, PTC17, PTD4);    // mosi, miso, sck, csn, ce, irq //CSN has been changed from PTD5 to PTC17
00033 
00034 
00035 bool send_flag; //indicates when robot should send all data
00036 bool obstacle_flag; //indicates an obstacle - robot should stop
00037 bool fwd_flag;
00038 bool calibrate_flag;
00039 bool calibrate_optFlow_flag;
00040 
00041 unsigned long long long_time = 0;
00042 Timer t;
00043 
00044 float getTime()
00045 {   return (float)(long_time + t.read_us())/1000000 ;   }
00046 
00047 void initRobot()
00048 {   
00049     LED_OFF
00050     
00051     MotorA.scale = R_MOTOR_SCALE;
00052     MotorB.scale = L_MOTOR_SCALE;    
00053     
00054     current_sensor.calibrate();
00055     
00056     LED_ON
00057     
00058     bt.start(); //this turns on the bluetooth switch
00059     rf.powerUp();   //turn on RF comm
00060     send_flag = 0;
00061     obstacle_flag = 0;
00062     
00063     wait_ms(60);
00064     opt_flow_L.setDPI();
00065     opt_flow_R.setDPI();
00066     bt.baud(BT_BAUD_RATE);
00067     motors.flip();
00068     
00069     
00070     LED_OFF //good to go
00071     t.start();      //start timer
00072 }
00073