Last active
August 29, 2015 14:27
-
-
Save Technicus/7f8ce48366b7e8df937f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /usr/share/arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/standard /tmp/build4729959347070805526.tmp/Roomba_Nerf_03.cpp -o /tmp/build4729959347070805526.tmp/Roomba_Nerf_03.cpp.o | |
| In file included from Roomba_Nerf_03.ino:7: | |
| include.h:1:28: warning: SoftwareSerial.h: No such file or directory | |
| include.h:2:19: warning: SPI.h: No such file or directory | |
| include.h:3:18: warning: Pixy.h: No such file or directory | |
| Roomba_Nerf_03:37: error: ‘Pixy’ does not name a type | |
| Roomba_Nerf_03:40: error: ‘SoftwareSerial’ does not name a type | |
| Roomba_Nerf_03.ino: In function ‘void setup()’: | |
| Roomba_Nerf_03:81: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03:91: error: ‘pixy’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void motorsTest_01()’: | |
| Roomba_Nerf_03:185: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void pixyTest_02()’: | |
| Roomba_Nerf_03:228: error: ‘pixy’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void pixyTest_01()’: | |
| Roomba_Nerf_03:276: error: ‘pixy’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void pixyTest_00()’: | |
| Roomba_Nerf_03:301: error: ‘pixy’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void directDrive(short int, short int)’: | |
| Roomba_Nerf_03:314: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void startMode(short int)’: | |
| Roomba_Nerf_03:342: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘void cleaningMotors(short int, short int)’: | |
| Roomba_Nerf_03:384: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino: In function ‘int checkSensor(byte, byte, byte*)’: | |
| Roomba_Nerf_03:572: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino:568: warning: unused variable ‘bufferPos’ | |
| Roomba_Nerf_03.ino: In function ‘void brushMotorCurrentTest_00()’: | |
| Roomba_Nerf_03:602: error: ‘roombaSerial’ was not declared in this scope | |
| Roomba_Nerf_03.ino:594: warning: unused variable ‘incomingByte’ | |
| Roomba_Nerf_03.ino:596: warning: unused variable ‘timeOut’ | |
| Roomba_Nerf_03.ino:597: warning: unused variable ‘bufferPos’ | |
| Roomba_Nerf_03.ino:598: warning: unused variable ‘howManyBytes’ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| . | |
| ├── directory.tree | |
| ├── include.h | |
| └── Roomba_Nerf_03.ino | |
| 0 directories, 3 files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <SoftwareSerial.h> | |
| #include <SPI.h> | |
| #include <Pixy.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Currently working on code to turn on and of brush and vacuum motors. | |
| #include "include.h" | |
| #define rxPin 10 | |
| #define txPin 9 | |
| #define start 128 | |
| #define reset 7 | |
| #define stop 173 | |
| #define safe 131 | |
| #define full 132 | |
| #define bumpRight 1 << 0 | |
| #define bumpLeft 1 << 1 | |
| #define dropRight 1 << 2 | |
| #define dropLeft 1 << 3 | |
| #define primary 0 | |
| #define secondary 1 | |
| #define dump 2 | |
| // set pin numbers: | |
| const int buttonPin_5 = 5; // the number of the pushbutton pin | |
| const int buttonPin_6 = 6; // the number of the pushbutton pin | |
| int buttonState_5 = 0; // variable for reading the pushbutton status | |
| int buttonState_6 = 0; // variable for reading the pushbutton status | |
| // byte response[16]; | |
| // setup pixy | |
| Pixy pixy; | |
| // set up a new software serial port | |
| SoftwareSerial roombaSerial = SoftwareSerial(rxPin, txPin); | |
| // pin assignments | |
| int statusLED = 4; | |
| // pixy variables | |
| int deadZone = 15; | |
| int turning = 0; | |
| // motor variables | |
| signed short mainBrush = 0; | |
| signed short sideBrush = 0; | |
| signed short vacuum = 0; | |
| int16_t brushCurrent = 0; | |
| // interrupt variables | |
| int action_0=0; | |
| int action_1=0; | |
| volatile int state_0 = LOW; | |
| volatile int state_1 = LOW; | |
| long debouncing_time = 40; //Debouncing Time in Milliseconds | |
| volatile unsigned long last_micros; | |
| int brushSpeed = 0; | |
| int dumpSpeed = 0; | |
| int lowSpeed = -30; | |
| int midSpeed = -70; | |
| int highSpeed = -100; | |
| void setup() { | |
| // attach interrupt buttons: | |
| attachInterrupt(0, interrupt_0, RISING); // RISING FALLING CHANGING | |
| attachInterrupt(1, interrupt_1, RISING); | |
| // define pin modes for status led and direct device/baud: | |
| pinMode(statusLED, OUTPUT); | |
| // set the data rate for the SoftwareSerial port, this is the | |
| // iRobot's default rate of 115200 baud: | |
| roombaSerial.begin(115200); | |
| // start hardware serial port | |
| Serial.begin(115200); | |
| // define pin modes for software tx, rx pins: | |
| pinMode(rxPin, INPUT); | |
| pinMode(txPin, OUTPUT); | |
| // initalize the pixy | |
| pixy.init(); | |
| Serial.println("PIXY GO START!"); | |
| pinMode(buttonPin_5, INPUT); | |
| pinMode(buttonPin_6, INPUT); | |
| // begin roomba mode | |
| // startMode(safe); | |
| startMode(full); | |
| } | |
| void loop() { | |
| // pixyTest_01(); | |
| // pixyTest_02(); | |
| // motorsTest_00(); | |
| // motorsTest_01(); | |
| // dartCollectorTest(); | |
| // brushMotorCurrentTest_00(); | |
| // read the state of the pushbutton value: | |
| buttonState_5 = digitalRead(buttonPin_5); | |
| buttonState_6 = digitalRead(buttonPin_6); | |
| // check if the pushbutton is pressed. | |
| // if it is, the buttonState is HIGH: | |
| if (buttonState_6 == HIGH) { | |
| // turn LED on: | |
| //cleaningMotors(primary, 30); | |
| brushSpeed = midSpeed; | |
| //dumpSpeed = 127; | |
| dumpSpeed = 0; | |
| } | |
| if (buttonState_5 == HIGH) { | |
| // turn LED on: | |
| //cleaningMotors(primary, 70); | |
| brushSpeed = highSpeed; | |
| //dumpSpeed = 127; | |
| dumpSpeed = 0; | |
| } | |
| cleaningMotors(primary, brushSpeed); | |
| //cleaningMotors(dump, dumpSpeed); | |
| } | |
| void dartCollectorTest() { | |
| // move forward with brush test | |
| // cleaningMotors(primary, 30); | |
| // | |
| // directDrive(250, 250); | |
| // delay(3000); | |
| // directDrive(0, 0); | |
| // delay(2000); | |
| // upside down with brushes test | |
| cleaningMotors(primary, 100); | |
| // delay(2000); | |
| // directDrive(-250, -250); | |
| // delay(2000); | |
| // directDrive(0, 0); | |
| // delay(2000); | |
| } | |
| void motorsTest_01() { | |
| cleaningMotors(primary, 30); | |
| delay(500); | |
| cleaningMotors(primary, 0); | |
| delay(500); | |
| cleaningMotors(primary, -30); | |
| delay(500); | |
| cleaningMotors(primary, 0); | |
| delay(500); | |
| cleaningMotors(secondary, 30); | |
| delay(500); | |
| cleaningMotors(secondary, 0); | |
| delay(500); | |
| cleaningMotors(secondary, -30); | |
| delay(500); | |
| cleaningMotors(secondary, 0); | |
| delay(500); | |
| cleaningMotors(dump, 30); | |
| delay(500); | |
| cleaningMotors(dump, 0); | |
| delay(500); | |
| roombaSerial.write(144); // OI opcode for PWM Motors | |
| roombaSerial.write((int8_t)30); // 30 | |
| //roombaSerial.write(0x1E); // 30 | |
| //roombaSerial.write(0x0064); //100 | |
| roombaSerial.write((byte)0); | |
| roombaSerial.write((byte)0); | |
| delay(500); | |
| roombaSerial.write(144); // OI opcode for PWM Motors | |
| roombaSerial.write((byte)0); | |
| roombaSerial.write((byte)0); | |
| roombaSerial.write((byte)0); | |
| delay(500); | |
| roombaSerial.write(144); // OI opcode for PWM Motors | |
| roombaSerial.write((int8_t)-30); // -30 | |
| //roombaSerial.write(0xFFE2); // -30 | |
| //roombaSerial.write(0xFF9C); //-100 | |
| roombaSerial.write((byte)0); | |
| roombaSerial.write((byte)0); | |
| delay(500); | |
| } | |
| void motorsTest_00() { | |
| cleaningMotors(primary, 31); | |
| delay(2000); | |
| cleaningMotors(primary, 0); | |
| delay(1000); | |
| cleaningMotors(primary, -31); | |
| delay(2000); | |
| cleaningMotors(primary, 0); | |
| cleaningMotors(secondary, 31); | |
| delay(2000); | |
| cleaningMotors(secondary, 0); | |
| delay(1000); | |
| cleaningMotors(secondary, -31); | |
| delay(1000); | |
| cleaningMotors(secondary, 0); | |
| cleaningMotors(dump, 31); | |
| delay(2000); | |
| cleaningMotors(dump, 0); | |
| } | |
| void pixyTest_02() { | |
| if (pixy.getBlocks()) { | |
| int xx = pixy.blocks[0].x; | |
| if (xx < (160 - deadZone)) { | |
| if (turning != 1) { | |
| turning = 1; | |
| Serial.print("\tLeft"); | |
| Serial.print("\t"); | |
| Serial.print(turning); | |
| Serial.print("\n"); | |
| left(100); | |
| } | |
| } | |
| if (xx > (160 + deadZone)) { | |
| if (turning != 2) { | |
| turning = 2; | |
| Serial.print("\tRight"); | |
| Serial.print("\t"); | |
| Serial.print(turning); | |
| Serial.print("\n"); | |
| right(100); | |
| } | |
| } | |
| if (xx > (159 - deadZone) and xx < (161 + deadZone)) { | |
| if (turning != 0) { | |
| turning = 0; | |
| Serial.print("\tHalt"); | |
| Serial.print("\t"); | |
| Serial.print(turning); | |
| Serial.print("\n"); | |
| halt(); | |
| } | |
| } | |
| else { | |
| if (turning == 0) { | |
| Serial.print("\t--H"); | |
| Serial.print("\t"); | |
| Serial.print(turning); | |
| Serial.print("\n"); | |
| } | |
| } | |
| } | |
| } | |
| void pixyTest_01() { | |
| if (pixy.getBlocks()) { | |
| if (pixy.blocks[0].signature == 1) { | |
| int xx = pixy.blocks[0].x; | |
| if (xx < (160 - deadZone)) { | |
| Serial.print("\tLeft\n"); | |
| } | |
| if (xx > (160 + deadZone)) { | |
| Serial.print("\tRight\n"); | |
| } | |
| if (xx > (159 - deadZone) and xx < (161 + deadZone)) { | |
| Serial.print("\tHalt\n"); | |
| } | |
| } | |
| else { | |
| Serial.print("\tHalt\n"); | |
| } | |
| } | |
| } | |
| void pixyTest_00() { | |
| if (pixy.getBlocks()) | |
| { | |
| if (pixy.blocks[0].signature == 1); { | |
| Serial.print("\t"); | |
| Serial.print(pixy.blocks[0].x); | |
| Serial.print("\t\t"); | |
| Serial.println(pixy.blocks[0].y); | |
| } | |
| } | |
| } | |
| void directDrive(signed short leftV, signed short rightV) { | |
| roombaSerial.write(145); // Opcode number for DIRECT DRIVE | |
| roombaSerial.write(rightV >> 8); | |
| roombaSerial.write(rightV & 0xFF); | |
| roombaSerial.write(leftV >> 8); | |
| roombaSerial.write(leftV & 0xFF); | |
| } | |
| void halt() { | |
| directDrive(0,0); | |
| } | |
| void left(signed short velocity) { | |
| directDrive(0-velocity,velocity); | |
| } | |
| void right(signed short velocity) { | |
| directDrive(velocity,0-velocity); | |
| } | |
| void startMode(signed short mode) { | |
| // light up status led | |
| digitalWrite(statusLED, HIGH); | |
| // this instruction starts the OI, roomba must | |
| // always recieve the Start instruction before | |
| // it will acknowladge any other operations | |
| roombaSerial.write(start); // Start the roomba OI | |
| roombaSerial.write(mode); | |
| blinkLED(); | |
| } | |
| void blinkLED() { | |
| // blink status LED | |
| digitalWrite(statusLED, HIGH); | |
| delay(100); | |
| digitalWrite(statusLED, LOW); | |
| delay(100); | |
| digitalWrite(statusLED, HIGH); | |
| delay(100); | |
| digitalWrite(statusLED, LOW); | |
| delay(100); | |
| } | |
| void cleaningMotors(signed short motor, signed short pulseWidthModulation) { | |
| // this function takes 2 perameters. | |
| // first is which motor to actuate (primary, secondary, or dump) | |
| // second is for setting the motor rate | |
| // primary -127 to 127 | |
| // secondary -127 to 127 | |
| // dump 0 to 127 | |
| // assign global variables | |
| switch (motor) { | |
| case primary: | |
| mainBrush = pulseWidthModulation; // range from -127 to 127 | |
| break; | |
| case secondary: | |
| sideBrush = pulseWidthModulation; // range from -127 to 127 | |
| break; | |
| case dump: | |
| vacuum = pulseWidthModulation; // range from 0 to 127 | |
| break; | |
| default: | |
| break; | |
| } | |
| // send instructions | |
| roombaSerial.write(144); // OI opcode for PWM Motors | |
| roombaSerial.write((int8_t)mainBrush); | |
| roombaSerial.write((int8_t)sideBrush); | |
| roombaSerial.write((int8_t)vacuum); | |
| } | |
| void interrupt_0() { | |
| // debounce | |
| if((long)(micros() - last_micros) >= debouncing_time * 1000) { | |
| // Do Something | |
| last_micros = micros(); | |
| } | |
| // state_0 = !state_0; | |
| digitalWrite(statusLED, HIGH); | |
| delay(50); | |
| digitalWrite(statusLED, LOW); | |
| delay(50); | |
| // action_0 = 0; | |
| // Do Something | |
| //startMode(full); | |
| brushSpeed = 0; | |
| dumpSpeed = 0; | |
| startMode(stop); | |
| //dartCollectorTest(); | |
| } | |
| void interrupt_1() { | |
| // debounce | |
| if((long)(micros() - last_micros) >= debouncing_time * 1000) { | |
| // Do Something | |
| last_micros = micros(); | |
| } | |
| // state_1 = !state_1; | |
| digitalWrite(statusLED, HIGH); | |
| delay(50); | |
| digitalWrite(statusLED, LOW); | |
| delay(50); | |
| // dartCollectorTest(); | |
| startMode(start); | |
| startMode(full); | |
| // dartCollectorTest(); | |
| // cleaningMotors(primary, 100); | |
| brushSpeed = lowSpeed; | |
| //dumpSpeed = 127; | |
| dumpSpeed = 0; | |
| // if (action_0 == 0){ | |
| // action_0 = 1; | |
| // cleaningMotors(primary, 100); | |
| // } | |
| // else { | |
| // action_0 = 0; | |
| // cleaningMotors(primary, 30); | |
| // } | |
| // if (action_0 < 7){ | |
| // action_0++; | |
| // } | |
| // else { | |
| // action_0 = 1; | |
| // } | |
| //startMode(safe); | |
| } | |
| // int checkSensors(byte whichSensor, byte howManyBytes){ | |
| // | |
| // int timeOut = 40; | |
| // | |
| // roombaSerial.write(149); | |
| // roombaSerial.write((byte)howManyBytes); | |
| // | |
| // for (int x = 0; x < howManyBytes ; x++) { | |
| // | |
| // roombaSerial.write((byte)whichSensor++); | |
| // | |
| // } | |
| // | |
| // int bufferPos = 0; | |
| // | |
| // while(howManyBytes) { | |
| // | |
| // while (roombaSerial.available() == 0) { | |
| // delayMicroseconds(1); | |
| // } | |
| // | |
| // response[bufferPos++] = roombaSerial.read(); | |
| // | |
| // howManyBytes -= 1; | |
| // | |
| // } | |
| // | |
| // } | |
| // byte response[16]; | |
| // int checkSensor(byte whichSensor, byte howManyBytes) { | |
| // | |
| // int timeOut = 40; | |
| // int bufferPos = 0; | |
| // | |
| // roombaSerial.write(142); | |
| // roombaSerial.write((byte)whichSensor); | |
| // | |
| // while(howManyBytes and timeOut) { | |
| // | |
| // while (roombaSerial.available() == 0 and timeOut) { | |
| // timeOut -= 1; | |
| // delayMicroseconds(1); | |
| // } | |
| // | |
| // response[bufferPos++] = roombaSerial.read(); | |
| // | |
| // howManyBytes -= 1; | |
| // | |
| // } | |
| // | |
| // if (timeOut) { | |
| // return 1; | |
| // } | |
| // | |
| // } | |
| // int checkSensors(byte whichSensor, byte howManyBytes){ | |
| // | |
| // int timeOut = 40; | |
| // | |
| // roombaSerial.write(149); | |
| // roombaSerial.write((byte)howManyBytes); | |
| // | |
| // for (int x = 0; x < howManyBytes ; x++) { | |
| // | |
| // roombaSerial.write((byte)whichSensor++); | |
| // | |
| // } | |
| // | |
| // int bufferPos = 0; | |
| // | |
| // while(howManyBytes) { | |
| // | |
| // while (roombaSerial.available() == 0) { | |
| // delayMicroseconds(1); | |
| // } | |
| // | |
| // response[bufferPos++] = roombaSerial.read(); | |
| // | |
| // howManyBytes -= 1; | |
| // | |
| // } | |
| // | |
| // } | |
| // void brushMotorCurrentTest_00(){ | |
| // | |
| // // int current = word(byte[0], byte[1]) | |
| // // short int16 = (short)(((bytes[0] & 0xFF) << 8) | (bytes[1] & 0xFF)); | |
| // | |
| // cleaningMotors(primary, 30); | |
| // checkSensors(56, 16); | |
| // /* for (i=0; i=16; i++){ | |
| // Serial.println(response[i]); | |
| // } */ | |
| // //int16_t s = (int16_t) (((response[0] & 0xFF) << 8) | (response[1] & 0xFF)); | |
| // brushCurrent = (((uint16_t)response[0]) << 8) | response[1]; | |
| // | |
| // Serial.print("Current: "); | |
| // Serial.println(brushCurrent); | |
| // | |
| // } | |
| int checkSensor(byte whichSensor, byte howManyBytes, byte* response) { | |
| // This function will return the value of a sensor | |
| // The first perameter inidcates the sensor code to querry | |
| // The second paremeter is for keeping track of the number of bytes that the querry will return | |
| // The third paremeter is a pointer, so it can copy the data into the buffer pointed to by that pointer | |
| int timeOut = 40; | |
| int bufferPos = 0; | |
| if(!response) return 0; | |
| roombaSerial.write(142); // instruction to prompt roomba for sensor data | |
| roombaSerial.write((int8_t)whichSensor); // send sensor code to roomba for data querry | |
| for(unsigned bufferPos=0; bufferPos < howManyBytes && timeOut; bufferPos++) { // get the data or timeout | |
| while (roombaSerial.available() == 0 and timeOut) { | |
| timeOut -= 1; | |
| delayMicroseconds(1); | |
| } | |
| response[bufferPos] = roombaSerial.read(); | |
| bufferPos += 1; | |
| howManyBytes -= 1; | |
| } | |
| if (timeOut) { // timeout if no response | |
| return 1; | |
| } | |
| } | |
| void brushMotorCurrentTest_00(){ | |
| byte response[16]; | |
| int incomingByte = 0; // for incoming serial data | |
| int timeOut = 40; | |
| int bufferPos = 0; | |
| byte howManyBytes = 2; | |
| cleaningMotors(primary, 30); // spin the primary motor | |
| roombaSerial.write(142); // ask for sensor data | |
| roombaSerial.write((int8_t)56); // ask for primary motor current, return 2 signed data bytes high byte first, -32768 to 32767 mA | |
| // I think I need to wait until I am sure that data is avliable | |
| while (roombaSerial.available() < 2) { | |
| // delayMicroseconds(1); | |
| } | |
| // if (roombaSerial.available() > 0) { | |
| // // read the incoming byte: | |
| // incomingByte = roombaSerial.read(); | |
| // } | |
| response[0] = roombaSerial.read(); | |
| response[1] = roombaSerial.read(); | |
| Serial.print("Brush Motor Current: \t"); | |
| Serial.print((signed int)response[0]); | |
| Serial.print(" "); | |
| Serial.print((signed int)response[1]); | |
| Serial.print("\t - - - check two bytes\n"); | |
| delay(2000); | |
| // code I tried that did not work | |
| // | |
| // checkSensor(56, 16, response); | |
| // for (unsigned i=0; i=16; i++){ | |
| // //Serial.print(response[i]); | |
| // Serial.print("Now What?"); | |
| // } | |
| // Serial.print("\n"); | |
| // Serial.print("Now What?"); | |
| // for(unsigned bufferPos=0; bufferPos < howManyBytes; bufferPos++) { // get the data | |
| // delayMicroseconds(1); | |
| // response[bufferPos] = roombaSerial.read(); | |
| // howManyBytes -= 1; | |
| // } | |
| //send data only when you receive data: | |
| // if (roombaSerial.available() > 0) { | |
| // // read the incoming byte: | |
| // incomingByte = roombaSerial.read(); | |
| // } | |
| //Serial.print(roombaSerial.read()); | |
| //Serial.print(incomingByte); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment