Clara Keng / Mbed 2 deprecated FreeFlyerROS_clarakhl

Dependencies:   mbed ros_lib_kinetic

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers debug.h Source File

debug.h

00001 #ifndef DEBUG_H
00002 #define DEBUG_H
00003 
00004 #include "FreeFlyerHardware.h"
00005 
00006 void testWheelEncoder(Serial &pc)
00007 {
00008     pc.printf("Hello World!\n");
00009     QEI wheel_encoder(PIN_WENCA, PIN_WENCB, NC, NCREV, SPEED_COUNTS, QEI::X4_ENCODING);
00010     Timer t_QEI;
00011     t_QEI.reset();
00012     t_QEI.start();
00013     while (true) {
00014         if (t_QEI.read_ms() >= 500) {    
00015             t_QEI.reset();
00016             pc.printf("Current number of counts: %d\n", wheel_encoder.getPulses());
00017             pc.printf("Measured wheel speed: %f\n", -wheel_encoder.getSpeed()*COUNTS2SHAFT);    // Shaft direction convention opposite of wheel direction convention
00018         }
00019     }
00020 }
00021 
00022 void searchForI2C(Serial &pc, I2C &i2c)
00023 {
00024     pc.printf("I2C Searching!\n\n");
00025     pc.printf("Starting....\n\n");    
00026     while (true) {
00027         int count = 0;
00028         for (int address=0; address<256; address+=2) {
00029             if (!i2c.write(address, NULL, 0)) { // 0 returned is ok                
00030                 pc.printf("I2C address 0x%02X\n", address);
00031                 count++;
00032             }
00033         }        
00034         pc.printf("%d devices found\n\n\n", count);
00035         wait(0.000001);       
00036     }
00037 }
00038 
00039 void testBitMasking(Serial &pc)
00040 {
00041     char cmd;
00042     while (true) {
00043         cmd = 0x00;
00044         cmd |= (1UL << (0x02-2));
00045         utils::printBits(cmd, pc);
00046         pc.printf("\n");
00047         wait(1.0);
00048     }
00049 }
00050 
00051 void RGBLEDTesting(Serial &pc, I2C &i2c, DigitalOut &led_inv_out_en)
00052 {
00053     char cmd[19];
00054     led_inv_out_en = 0;
00055     
00056     while (true) {
00057         
00058         wait(0.5);
00059         
00060         cmd[0] = 0x80;  // Send control register: start with register 00, autoincrement
00061         cmd[1] = 0x80;  // MODE1 (default value, in normal power mode)
00062         cmd[2] = 0x09;  // MODE2 (default value, but with invert off, outputs change on ack, open-drain)    
00063         cmd[3] = 0x00;  // PWM0 (B2)
00064         cmd[4] = 0x00;  // PWM1 (W2 - ignore)
00065         cmd[5] = 0x00;  // PWM2 (G2)
00066         cmd[6] = 0x00;  // PWM3 (R2)
00067         cmd[7] = 0x00;  // PWM4  (B1)
00068         cmd[8] = 0x00;  // PWM5 (W1 - ignore)
00069         cmd[9] = 0x00;  // PWM6 (G1)
00070         cmd[10] = 0x00;  // PWM7 (R1)
00071         cmd[11] = 0xff;  // GRPPWM (default value)
00072         cmd[12] = 0x00;  // GRPFREQ (default value)
00073         cmd[13] = 0x55;  // LEDOUT0 (0x55: all fully on)
00074         cmd[14] = 0x55;  // LEDOUT1 (0x55: all fully on)
00075         cmd[13] = 0x00;  // LEDOUT0 (0x55: all fully off)
00076         cmd[14] = 0x00;  // LEDOUT1 (0x55: all fully off)
00077         cmd[15] = 0x00;  // SUBADR1
00078         cmd[16] = 0x00;  // SUBADR2
00079         cmd[17] = 0x00;  // SUBADR3
00080         cmd[18] = 0x00;  // ALLCALLADR
00081         
00082         i2c.write(ADDR_RGB, cmd, 19);
00083         
00084         //cmd[0] = 0x8d;  // Send control register: start with register 12, autoincrement
00085         //cmd[1] = 0x55;  // LEDOUT0 (0x55: all fully on)
00086         //cmd[2] = 0x55;  // LEDOUT1 (0x55: all fully on)
00087         //cmd[1] = 0x00;  // LEDOUT0 (0x55: all fully off)
00088         //cmd[2] = 0x00;  // LEDOUT1 (0x55: all fully off)
00089         
00090         //mbed::i2c.write(ADDR_RGB, cmd, 3);
00091         //mbed::i2c.write(mbed::addr, cmd, 3);
00092         
00093         cmd[0] = 0x80;
00094         i2c.write(ADDR_RGB, cmd, 1);
00095         for (int i = 0; i < 18; i++)
00096             cmd[i] = 0;
00097         
00098         i2c.read(ADDR_RGB, cmd, 18);
00099         
00100         for (int i = 0; i < 18; i++) {
00101             utils::printBits(cmd[i], pc);
00102             pc.printf("\n");
00103         }
00104         pc.printf("\n");
00105     }
00106 }
00107 
00108 #endif