MicroTrac Controller v17.10/Code: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 14: | Line 14: | ||
***is this too jerky | ***is this too jerky | ||
**determine turn radius at specified duty cycles | **determine turn radius at specified duty cycles | ||
= Usage Notes = | |||
when uploading new arduino sketches while the xbee radio is attached to the mega board, make sure that the switch on the xbee shield is in the "USB" position. | |||
=Terms, Pins and Variables= | =Terms, Pins and Variables= | ||
Line 27: | Line 31: | ||
:G - Bucket Up | :G - Bucket Up | ||
:H - Bucket Down | :H - Bucket Down | ||
==AT Commands== | ==AT Commands== |
Revision as of 21:32, 29 October 2017
Goals
- Establish serial communication over xbee radio
- Transmit commands from the "remote controller" box to "onboard controller" box.
- Attempt to run identical arduino control software on both boxes.
- Will run in onboard mode if jumper set between defined pins.
- When in onboard mode, transmit GPS location.
- Boxes will ping each other and will shut down if connection lost.
- Store radio information in EEPROM. Update on startup.
- Create a program to define the EEPROM
- Operate relay switches when "HAND" switch is on
- Test different turning methods.
- stop and turn
- fether on/off to turn on a curve
- is this too jerky
- determine turn radius at specified duty cycles
Usage Notes
when uploading new arduino sketches while the xbee radio is attached to the mega board, make sure that the switch on the xbee shield is in the "USB" position.
Terms, Pins and Variables
Each Solenoid and corresponding relay switch will be defined by a single alphabet letter.
- A - Left Track Forward
- B - Left Track Backward
- C - Right Track Forward
- D - Right Track Backward
- E - Arms Up
- F - Arms Down
- G - Bucket Up
- H - Bucket Down
AT Commands
- ATIDXXXX - set radio network ID
- ATWR - save settings to long term memory
Code Theory
When a switch is thrown, its letter followed by a 1 or 0 will be transmitted over serial.
- example: "E1" will engage the solenoid to raise the arms. "E0" will turn off the solenoid and will stop raising the arms.
- While "F1" will lower the arms and "F0" will stop lowering the arms.
If vehicle is stopped, gather and transmit position and orientation data. otherwise briefly stop vehicle every X minutes.
- might try sending commands all together like "abCdefgh". then after read, flush all serial available to get a fresh serial data set
Code
Controller Box
void setup() { //SET PINS AS INPUT FROM TOGGLE SWITCHES pinMode(39,INPUT_PULLUP); //LF pinMode(41,INPUT_PULLUP); //LB pinMode(43,INPUT_PULLUP); //RF pinMode(45,INPUT_PULLUP); //RB pinMode(47,INPUT_PULLUP); //AU pinMode(49,INPUT_PULLUP); //AD pinMode(51,INPUT_PULLUP); //BU pinMode(53,INPUT_PULLUP); //BD int sLF = digitalRead(39); //left track forward int sLB = digitalRead(41); //left track backward int sRF = digitalRead(43); //right track forward int sRB = digitalRead(45); //right track backward int sAU = digitalRead(47); //arms up int sAD = digitalRead(49); //arms down int sBU = digitalRead(51); //bucket up int sBD = digitalRead(53); //bucket down //SET PINS AS OUTPUT TO RELAY MODULE pinMode(38, OUTPUT); pinMode(40, OUTPUT); pinMode(42, OUTPUT); pinMode(44, OUTPUT); pinMode(46, OUTPUT); pinMode(48, OUTPUT); pinMode(50, OUTPUT); pinMode(52, OUTPUT); //START COMMUNICATING WITH XBEE Serial.begin(9600); } void loop() { int sLF = digitalRead(39); if (sLF == LOW) { Serial.print('A'); } else { Serial.print('a'); } if (sLF == LOW) { digitalWrite(38, HIGH); } else { digitalWrite(38, LOW); } int sLB = digitalRead(41); if (sLB == LOW) { Serial.print('B'); } else { Serial.print('b'); } if (sLB == LOW) { digitalWrite(40, HIGH); } else { digitalWrite(40, LOW); } int sRF = digitalRead(43); if (sRF == LOW) { Serial.print('C'); } else { Serial.print('c'); } if (sRF == LOW) { digitalWrite(42, HIGH); } else { digitalWrite(42, LOW); } int sRB = digitalRead(45); if (sRB == LOW) { Serial.print('D'); } else { Serial.print('d'); } if (sRB == LOW) { digitalWrite(44, HIGH); } else { digitalWrite(44, LOW); } int sAU = digitalRead(47); if (sAU == LOW) { Serial.print('E'); } else { Serial.print('e'); } if (sAU == LOW) { digitalWrite(46, HIGH); } else { digitalWrite(46, LOW); } int sAD = digitalRead(49); if (sAD == LOW) { Serial.print('F'); } else { Serial.print('f'); } if (sAD == LOW) { digitalWrite(48, HIGH); } else { digitalWrite(48, LOW); } int sBU = digitalRead(51); if (sBU == LOW) { Serial.print('G'); } else { Serial.print('g'); } if (sBU == LOW) { digitalWrite(50, HIGH); } else { digitalWrite(50, LOW); } int sBD = digitalRead(53); if (sBD == LOW) { Serial.print('H'); } else { Serial.print('h'); } if (sBD == LOW) { digitalWrite(52, HIGH); } else { digitalWrite(52, LOW); } }
Onboard Box
void setup() { //SET PINS AS OUTPUT TO RELAY MODULE pinMode(38, OUTPUT); pinMode(40, OUTPUT); pinMode(42, OUTPUT); pinMode(44, OUTPUT); pinMode(46, OUTPUT); pinMode(48, OUTPUT); pinMode(50, OUTPUT); pinMode(52, OUTPUT); //START COMMUNICATING WITH XBEE Serial.begin(9600); } void loop() { while (Serial.available()>0){ char RXbyte = char(Serial.read()); if (RXbyte == 'A') { digitalWrite(38, HIGH); } if (RXbyte == 'a') { digitalWrite(38, LOW); } if (RXbyte == 'B') { digitalWrite(40, HIGH); } if (RXbyte == 'b') { digitalWrite(40, LOW); } if (RXbyte == 'C') { digitalWrite(42, HIGH); } if (RXbyte == 'c') { digitalWrite(42, LOW); } if (RXbyte == 'D') { digitalWrite(44, HIGH); } if (RXbyte == 'd') { digitalWrite(44, LOW); } if (RXbyte == 'E') { digitalWrite(46, HIGH); } if (RXbyte == 'e') { digitalWrite(46, LOW); } if (RXbyte == 'F') { digitalWrite(48, HIGH); } if (RXbyte == 'f') { digitalWrite(48, LOW); } if (RXbyte == 'G') { digitalWrite(50, HIGH); } if (RXbyte == 'g') { digitalWrite(50, LOW); } if (RXbyte == 'H') { digitalWrite(52, HIGH); } if (RXbyte == 'h') { digitalWrite(52, LOW); } } }