Alison Bartsch / Mbed 2 deprecated FreeFlyerROS

Dependencies:   mbed ros_lib_kinetic

Committer:
ambyld
Date:
Fri Jun 29 17:49:40 2018 +0000
Revision:
5:864709d3eb76
Moved isolated debug scripts to separate header file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ambyld 5:864709d3eb76 1 #ifndef DEBUG_H
ambyld 5:864709d3eb76 2 #define DEBUG_H
ambyld 5:864709d3eb76 3
ambyld 5:864709d3eb76 4 #include "FreeFlyerHardware.h"
ambyld 5:864709d3eb76 5
ambyld 5:864709d3eb76 6 void testWheelEncoder(Serial &pc)
ambyld 5:864709d3eb76 7 {
ambyld 5:864709d3eb76 8 pc.printf("Hello World!\n");
ambyld 5:864709d3eb76 9 QEI wheel_encoder(PIN_WENCA, PIN_WENCB, NC, NCREV, SPEED_COUNTS, QEI::X4_ENCODING);
ambyld 5:864709d3eb76 10 Timer t_QEI;
ambyld 5:864709d3eb76 11 t_QEI.reset();
ambyld 5:864709d3eb76 12 t_QEI.start();
ambyld 5:864709d3eb76 13 while (true) {
ambyld 5:864709d3eb76 14 if (t_QEI.read_ms() >= 500) {
ambyld 5:864709d3eb76 15 t_QEI.reset();
ambyld 5:864709d3eb76 16 pc.printf("Current number of counts: %d\n", wheel_encoder.getPulses());
ambyld 5:864709d3eb76 17 pc.printf("Measured wheel speed: %f\n", -wheel_encoder.getSpeed()*COUNTS2SHAFT); // Shaft direction convention opposite of wheel direction convention
ambyld 5:864709d3eb76 18 }
ambyld 5:864709d3eb76 19 }
ambyld 5:864709d3eb76 20 }
ambyld 5:864709d3eb76 21
ambyld 5:864709d3eb76 22 void searchForI2C(Serial &pc, I2C &i2c)
ambyld 5:864709d3eb76 23 {
ambyld 5:864709d3eb76 24 pc.printf("I2C Searching!\n\n");
ambyld 5:864709d3eb76 25 pc.printf("Starting....\n\n");
ambyld 5:864709d3eb76 26 while (true) {
ambyld 5:864709d3eb76 27 int count = 0;
ambyld 5:864709d3eb76 28 for (int address=0; address<256; address+=2) {
ambyld 5:864709d3eb76 29 if (!i2c.write(address, NULL, 0)) { // 0 returned is ok
ambyld 5:864709d3eb76 30 pc.printf("I2C address 0x%02X\n", address);
ambyld 5:864709d3eb76 31 count++;
ambyld 5:864709d3eb76 32 }
ambyld 5:864709d3eb76 33 }
ambyld 5:864709d3eb76 34 pc.printf("%d devices found\n\n\n", count);
ambyld 5:864709d3eb76 35 wait(0.000001);
ambyld 5:864709d3eb76 36 }
ambyld 5:864709d3eb76 37 }
ambyld 5:864709d3eb76 38
ambyld 5:864709d3eb76 39 void testBitMasking(Serial &pc)
ambyld 5:864709d3eb76 40 {
ambyld 5:864709d3eb76 41 char cmd;
ambyld 5:864709d3eb76 42 while (true) {
ambyld 5:864709d3eb76 43 cmd = 0x00;
ambyld 5:864709d3eb76 44 cmd |= (1UL << (0x02-2));
ambyld 5:864709d3eb76 45 utils::printBits(cmd, pc);
ambyld 5:864709d3eb76 46 pc.printf("\n");
ambyld 5:864709d3eb76 47 wait(1.0);
ambyld 5:864709d3eb76 48 }
ambyld 5:864709d3eb76 49 }
ambyld 5:864709d3eb76 50
ambyld 5:864709d3eb76 51 void RGBLEDTesting(Serial &pc, I2C &i2c, DigitalOut &led_inv_out_en)
ambyld 5:864709d3eb76 52 {
ambyld 5:864709d3eb76 53 char cmd[19];
ambyld 5:864709d3eb76 54 led_inv_out_en = 0;
ambyld 5:864709d3eb76 55
ambyld 5:864709d3eb76 56 while (true) {
ambyld 5:864709d3eb76 57
ambyld 5:864709d3eb76 58 wait(0.5);
ambyld 5:864709d3eb76 59
ambyld 5:864709d3eb76 60 cmd[0] = 0x80; // Send control register: start with register 00, autoincrement
ambyld 5:864709d3eb76 61 cmd[1] = 0x80; // MODE1 (default value, in normal power mode)
ambyld 5:864709d3eb76 62 cmd[2] = 0x09; // MODE2 (default value, but with invert off, outputs change on ack, open-drain)
ambyld 5:864709d3eb76 63 cmd[3] = 0x00; // PWM0 (B2)
ambyld 5:864709d3eb76 64 cmd[4] = 0x00; // PWM1 (W2 - ignore)
ambyld 5:864709d3eb76 65 cmd[5] = 0x00; // PWM2 (G2)
ambyld 5:864709d3eb76 66 cmd[6] = 0x00; // PWM3 (R2)
ambyld 5:864709d3eb76 67 cmd[7] = 0x00; // PWM4 (B1)
ambyld 5:864709d3eb76 68 cmd[8] = 0x00; // PWM5 (W1 - ignore)
ambyld 5:864709d3eb76 69 cmd[9] = 0x00; // PWM6 (G1)
ambyld 5:864709d3eb76 70 cmd[10] = 0x00; // PWM7 (R1)
ambyld 5:864709d3eb76 71 cmd[11] = 0xff; // GRPPWM (default value)
ambyld 5:864709d3eb76 72 cmd[12] = 0x00; // GRPFREQ (default value)
ambyld 5:864709d3eb76 73 cmd[13] = 0x55; // LEDOUT0 (0x55: all fully on)
ambyld 5:864709d3eb76 74 cmd[14] = 0x55; // LEDOUT1 (0x55: all fully on)
ambyld 5:864709d3eb76 75 cmd[13] = 0x00; // LEDOUT0 (0x55: all fully off)
ambyld 5:864709d3eb76 76 cmd[14] = 0x00; // LEDOUT1 (0x55: all fully off)
ambyld 5:864709d3eb76 77 cmd[15] = 0x00; // SUBADR1
ambyld 5:864709d3eb76 78 cmd[16] = 0x00; // SUBADR2
ambyld 5:864709d3eb76 79 cmd[17] = 0x00; // SUBADR3
ambyld 5:864709d3eb76 80 cmd[18] = 0x00; // ALLCALLADR
ambyld 5:864709d3eb76 81
ambyld 5:864709d3eb76 82 i2c.write(ADDR_RGB, cmd, 19);
ambyld 5:864709d3eb76 83
ambyld 5:864709d3eb76 84 //cmd[0] = 0x8d; // Send control register: start with register 12, autoincrement
ambyld 5:864709d3eb76 85 //cmd[1] = 0x55; // LEDOUT0 (0x55: all fully on)
ambyld 5:864709d3eb76 86 //cmd[2] = 0x55; // LEDOUT1 (0x55: all fully on)
ambyld 5:864709d3eb76 87 //cmd[1] = 0x00; // LEDOUT0 (0x55: all fully off)
ambyld 5:864709d3eb76 88 //cmd[2] = 0x00; // LEDOUT1 (0x55: all fully off)
ambyld 5:864709d3eb76 89
ambyld 5:864709d3eb76 90 //mbed::i2c.write(ADDR_RGB, cmd, 3);
ambyld 5:864709d3eb76 91 //mbed::i2c.write(mbed::addr, cmd, 3);
ambyld 5:864709d3eb76 92
ambyld 5:864709d3eb76 93 cmd[0] = 0x80;
ambyld 5:864709d3eb76 94 i2c.write(ADDR_RGB, cmd, 1);
ambyld 5:864709d3eb76 95 for (int i = 0; i < 18; i++)
ambyld 5:864709d3eb76 96 cmd[i] = 0;
ambyld 5:864709d3eb76 97
ambyld 5:864709d3eb76 98 i2c.read(ADDR_RGB, cmd, 18);
ambyld 5:864709d3eb76 99
ambyld 5:864709d3eb76 100 for (int i = 0; i < 18; i++) {
ambyld 5:864709d3eb76 101 utils::printBits(cmd[i], pc);
ambyld 5:864709d3eb76 102 pc.printf("\n");
ambyld 5:864709d3eb76 103 }
ambyld 5:864709d3eb76 104 pc.printf("\n");
ambyld 5:864709d3eb76 105 }
ambyld 5:864709d3eb76 106 }
ambyld 5:864709d3eb76 107
ambyld 5:864709d3eb76 108 #endif