Skip to content

Commit

Permalink
Add ScoutBotics Examples
Browse files Browse the repository at this point in the history
Example programs for the October 27th, 2018 ScoutBotics event.
  • Loading branch information
MadTooler authored Oct 20, 2018
1 parent c061011 commit 74c3288
Show file tree
Hide file tree
Showing 16 changed files with 1,987 additions and 0 deletions.
72 changes: 72 additions & 0 deletions examples/ScoutBotics/Level_1/BSA_Course/BSA_Course.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* 10/20/2018
*
* Using the Gobbit robot with line sensor on the BSA shaped course...
*
* The program will...
*
* 1) Use the drive() function to navigate from the start to the end point.
* 2) Stop at the end and do nothing else.
*
* *** Change the use of the drive() steps to improve your course time. ***
*
* How the drive() function works...
* Calling drive('L/R/F/S/U') will start driving/following the line and continue following until it
* is able to complete the requested direction/turn at the next found intersection
* or end. If it cannot make the requested direction/turn, it will spin around fast
* to indicate it had a problem, and stop the robot.
*
* Turn direction values are ('L')eft, ('R')ight, ('F')orward, ('S')top, or ('U')turn.
*
* To see a video using a similar sketch: https://youtu.be/c2BB-Bc95Ik
*
*/

// Choose your Motor Driver...
// To load default settings for either an Ardumoto version 14 or 20, or an Adafruit v2.3,
// uncomment only the following motor driver define that matches.
// If none are uncommented, Ardumoto v14 values will be used.
//
// DO NOT UNCOMMENT MORE THAN ONE
//#define ARDUMOTO_14
//#define ARDUMOTO_20
//#define ADAFRUIT_MS

#include <GobbitLineCommand.h>

// Give your robot a name.
// I called it "MyBot" here, but you call it whatever you want.
// If you make a new name, make sure to find/replace all of the "MyBot" in the sketch with your new name.
GobbitLineCommand MyBot;

void setup() {

MyBot.setBatteryVolts(9);

MyBot.beginGobbit();

MyBot.calibrateLineSensor();

}

void loop() {

// Use the drive() function to drive from the start to the end of the course
// Note: You could use a for() loop to easily repeat drive() statements.
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');
MyBot.drive('F');

// at the end, stop the robot
MyBot.drive('S');

// We need to tell it to do nothing else forever so it doesn't start the loop() over
while(1);

}
212 changes: 212 additions & 0 deletions examples/ScoutBotics/Level_2/GLC_IRcontrol/GLC_IRcontrol.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/* 05/04/2018
This program will setup the Gobbit robot to be controlled and programmable by an infrared (IR) remote.
The Gobbit robot needs an arduino Uno, motor driver, line sensor, infrared receiver, and piezo beeper.
The IR remote needs a minimum of 17 buttons. Ideally, the buttons include a 10 key number pad with
two extra buttons on either side of the 0 button, and the typical four directional arrows with an additional
button in the middle for a stop button. The robot will then be able to be controlled by the remote
in three primary modes:
1) Simple RC type control where the robot moves while the direction button is held down
2) A direction/speed/time based programming mode where either individual or a series of
direction, speed, and timing commands are entered and executed via the remote.
3) Line following with intersection detection based programming mode where either individual or a series of
direction, speed, and timing commands are entered and executed via the remote.
A lined course is needed for this mode.
There is also one minor mode:
4) This mode is only used for "trimming" the motors (full forward and backward directions only) if needed
for Mode 1&2 to function better.
"IRremote" library is also needed.
Use the IRremote example "IRrecvDemo" to find the IR codes from your remote.
Make sure to set your RECV_PIN and turn on your IR_POWER_PIN if used.
Update the #define IR button values in the tab "IRcodes.h" to match your remote's buttons
(the tab is at the top of this text area)
For GobbitLineCommand function definitions, see the GobbitLineCommand "GLC_Functions" example sketch.
** See comments within the code for further details **
*/

// Choose your Motor Driver...
// To load default settings for either an Ardumoto version 14 or 20, or an Adafruit v2.3,
// uncomment only the following motor driver define that matches.
// If none are uncommented, Ardumoto v14 values will be used.
//
// DO NOT UNCOMMENT MORE THAN ONE
//#define ARDUMOTO_14
//#define ARDUMOTO_20
#define ADAFRUIT_MS

// What voltage is your battery (whole numbers only)
#define BATTERY_VOLTS 11

// If you will use an IO pin to power the IR receiver +5v
// then declare the define to the pin number.
// Otherwise, comment it at out.
// This is a shortcut for low mAmp power where you may have available IO pins and
// where the +5v pin is already used and you do not have a breadboard or splitter on hand.
#define IR_POWER_PIN A0 // comment out to disable

#define RECV_PIN A1 // pin your IR receiver is using

#define PIEZO_PIN A2 // piezo beeper/sensor pin

// veering turn values have stronger turning with larger value, max 99 where 100 is spinning
// Used with Mode 1 and 2 only
#define MINOR_VEER_STRENGTH 30
#define MODERATE_VEER_STRENGTH 60 // used for FORWARD_RIGHT/LEFT turns/veering
#define MAJOR_VEER_STRENGTH 90

#define CALIBRATE_SPEED 0 // speed 0-100 for line follow calibration mode. 0 uses default values.

#define RC_SPINSPEED 45 // speed 0-100 for right/left turn/spin in Mode 1 only.

#define BUTTON_HOLD_DELAY 110 // (was 110) delay for hold down repeat to continue last command to allow for time between IR transmissions

#define DEBOUNCE_DELAY 250 // debounce time to allow finger off of key

#define TRIM_MAX_TIME 4000 // maximumm time in milliseconds in Trim mode (4) to continue the last command without a new command

// set these values ONLY if using battery monitoring
// to disable, comment out the define ANALOG_DIVIDER_PIN
#define ANALOG_DIVIDER_PIN A3 // analog pin your voltage divider is connected
#define CUTOFF 9 // cut off voltage... set here at 3.0v x 3 cells = 9
#define SMALL_RES_KOHMS 33 // K ohm value of your small resistor in the divider
#define LARGE_RES_KOHMS 100 // K ohm value of your small resistor in the divider

#include "IRcodes.h"

#include <IRremote.h>
IRrecv irrecv(RECV_PIN);
decode_results results;

#include <GobbitLineCommand.h>
GobbitLineCommand MyBot;


int mode = 0;
int moving = 0;
int lastButtonValue;
int currentSpeed = 100;
unsigned long previousMillis = 0;
int steerTrimF = 0; // steering trim forward motion
int steerTrimB = 0; // steering trim backward motion


void setup() {

MyBot.setGripPinOpenClosed(10,180,75);


pinMode(PIEZO_PIN, OUTPUT);

// Serial.begin(9600);

// If IR_POWER_PIN was defined, this will set the pin to power the IR receiver,
#ifdef IR_POWER_PIN
pinMode(IR_POWER_PIN, OUTPUT);
digitalWrite(IR_POWER_PIN, HIGH);
#endif


// Due to limited resources and motor shield pin usage, you need to shift some pins around to avoid PWM and timer
// conflicts between IRremote and some motor driver shield pins.
// This also requires using jumpers between the standard driver pins and the locations called here.
// NOTES:
// -More pins can be freed up if the motor shield is removed from the arduino and wired instead of stacked.
// -Since both A4 and A5 are being used, I2C cannot be used in this configuration since an ardumoto style shield is stacked due to wasted pins.
// -TO free up pins, use an I2C based driver like the Adafruit v2.

// ArduMoto v14
#ifdef ARDUMOTO_14
MyBot.setQTRpins(2, 4, 5, 6, 7, 8, A3, A4); // **
MyBot.setLeftMotorPinsDirPWM(12, 9); // on ardumoto v14, these were 12,3; use a jumper from 3 to 9
MyBot.setRightMotorPinsDirPWM(13, 10); // on ardumoto v14, these were 13,11; use a jumper from 11 to 10
#endif

// ArduMoto v20
#ifdef ARDUMOTO_20
MyBot.setQTRpins(5, 6, 7, 8, 12, 13, A3, A4); // **
MyBot.setLeftMotorPinsDirPWM(4, 10); // on ardumoto v20, these were 4,11; use a jumper from 11 to 10
MyBot.setRightMotorPinsDirPWM(2, 9); // on ardumoto v20, these were 2,3; use a jumper from 3 to 9
#endif

// use these for 9v, not above
// PID tunes here vary from the default due to pin changes and larger overhead of processor cycles.
// See the "ArdumotoDefaults.h" or the "AdafruitMSDefaults.h" files in the library "src" folder to view or change the default values.
#if (BATTERY_VOLTS < 10)
// MyBot.setPID(0.25, 0.001, 1); // default at 9v is 0.15, .002, 411.1v is 0.15, 0.002, 4
// MyBot.setPIDcoarse(0.3, 0.001, 4.4); // default at 11.1v is 0.2, 0.001, 4.4
// MyBot.setPIDfineRange(0.6); // default at 11.1v is 0.05 //was .6 start fix
#endif

MyBot.setBatteryVolts(BATTERY_VOLTS);

MyBot.beginGobbit(); // initializes robot with settings

MyBot.gripOpen();

irrecv.enableIRIn(); // Start the IR receiver

#ifdef ANALOG_DIVIDER_PIN
MyBot.checkBattery(ANALOG_DIVIDER_PIN, CUTOFF, SMALL_RES_KOHMS, LARGE_RES_KOHMS);
#endif

}

void loop() {

#ifdef ANALOG_DIVIDER_PIN
MyBot.checkBattery(ANALOG_DIVIDER_PIN, CUTOFF, SMALL_RES_KOHMS, LARGE_RES_KOHMS);
#endif

MyBot.move(0, 0);

// wait for the mode selection to be received
if (buttonDecode()) {
mode = modeSelect();
}

// run in the selected mode
if (mode) {
switch (mode) {

case 1: // Start Simple RC Mode
modeStartedBeep();
modeOne();
break;

case 2: // Start Free Programming Mode
modeStartedBeep();
modeTwo();
break;

case 3: // Start Line Following Programming Mode
modeStartedBeep();
modeThree();
break;

case 4: // Start Trim Mode
modeStartedBeep();
modeFour();
break;
}
}
}











79 changes: 79 additions & 0 deletions examples/ScoutBotics/Level_2/GLC_IRcontrol/IRcodes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

// direct tv

// IR commands... change these to match your buttons/keys
// ** If your remote button only outputs one code when it is pushed multiple times,
// set the XX_BUTTON value to that code with "0x" before it since it is a HEX value
// and leave the XX_BUTTN_ALT value as "0x0" (zero).
// If it toggles between two different codes, as you tap the button,
// set XX_BUTTON value to one code and
// set the XX_BUTTN_ALT value to the other code.

// Basic required 17 remote buttons
#define ZERO_BUTTON 0x1CE300FF
#define ZERO_BUTTN_ALT 0x0
#define ONE_BUTTON 0x1CE3807F
#define ONE_BUTTN_ALT 0x0
#define TWO_BUTTON 0X1CE340BF
#define TWO_BUTTN_ALT 0x0
#define THREE_BUTTON 0x1CE3C03F
#define THREE_BUTTN_ALT 0x0
#define FOUR_BUTTON 0x1CE320DF
#define FOUR_BUTTN_ALT 0x0
#define FIVE_BUTTON 0x1CE3A05F
#define FIVE_BUTTN_ALT 0x0
#define SIX_BUTTON 0x1CE3609F
#define SIX_BUTTN_ALT 0x0
#define SEVEN_BUTTON 0x1CE3E01F
#define SEVEN_BUTTN_ALT 0x0
#define EIGHT_BUTTON 0x1CE310EF
#define EIGHT_BUTTN_ALT 0x0
#define NINE_BUTTON 0x1CE3906F
#define NINE_BUTTN_ALT 0x0
#define ENTER_BUTTON 0x1CE3B04F // button at the bottom right of the number pad
#define ENTER_BUTTN_ALT 0x0
#define BACK_BUTTON 0x1CE3E817 // button at the bottom left of the number pad
#define BACK_BUTTN_ALT 0x0

#define FORWARD_BUTTON 0x1CE350AF // forward/up direction button/arrow
#define FORWARD_BUTTN_ALT 0x0 // alternate forward/up direction button/arrow
#define BACKWARD_BUTTON 0x1CE3D02F // backward/down direction button/arrow
#define BACKWARD_BUTTN_ALT 0x0 // alternate backward/down direction button/arrow
#define RIGHT_BUTTON 0x1CE3708F // right direction button/arrow
#define RIGHT_BUTTN_ALT 0x0 // alternate right direction button/arrow
#define LEFT_BUTTON 0x1CE3F00F // left direction button/arrow
#define LEFT_BUTTN_ALT 0x0 // alternate left direction button/arrow
#define STOP_BUTTON 0x1CE348B7 // stop button in the middle of the direction keys
#define STOP_BUTTN_ALT 0x0 // alternate stop button in the middle of the direction keys

// Optionally set these buttons only if you have available buttons and want to expand
// beyond the number and arrow keys for clarity.
// ** These MUST be left with "0x0" values if they are not used. **
#define FORWARD_RIGHT 0x0
#define FORWARD_RT_ALT 0x0
#define FORWARD_LEFT 0x0
#define FORWARD_LFT_ALT 0x0
#define BACKWARD_RIGHT 0x0
#define BACKWARD_RT_ALT 0x0
#define BACKWARD_LEFT 0x0
#define BACKWARD_LFT_ALT 0x0
#define RC_MODE 0x0
#define RC_MOD_ALT 0x0
#define FREE_PROGRAM_MODE 0x0
#define FREE_PROG_MOD_ALT 0x0
#define LINE_PROGRAM_MODE 0x0
#define LINE_PROG_MOD_ALT 0x0
#define TRIM_MODE 0x0
#define TRIM_MOD_ALT 0x0
#define PLAY_PROGRAM 0x0
#define PLAY_PROG_ALT 0x0
#define STOP_PROGRAM 0x0
#define STOP_PROG_ALT 0x0

// Gripper buttons
#define GRIP_OPEN 0x1CE332CD
#define GRIP_OPN_ALT 0x0
#define GRIP_CLOSE 0x1CE318E7
#define GRIP_CLOS_ALT 0x0

#define REPEAT_CODE 0xFFFFFFFF // this probably does not need any change
Loading

0 comments on commit 74c3288

Please sign in to comment.