Skip to content

Commit

Permalink
improved examples
Browse files Browse the repository at this point in the history
still under construction
  • Loading branch information
MadTooler authored Oct 23, 2018
1 parent 906ddc5 commit fce8125
Show file tree
Hide file tree
Showing 20 changed files with 2,806 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);

}
57 changes: 57 additions & 0 deletions examples/ScoutBotics/Level_2/GLC_GetIRcodes/GLC_GetIRcodes.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* 10/22/2018
This program uses the IRremote library to find IR codes with the
Gobbit robot wired and configured for use by the GLC_IRcontrol examples.
Upload this program then use the serial monitor to test and capture IR codes.
Make sure the baud in the serial monitor is set to 9600
This is a small mod of the original example:
IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
An IR detector/demodulator must be connected to the input RECV_PIN.
Version 0.1 July, 2009
Copyright 2009 Ken Shirriff
http://arcfn.com
*/

#include <IRremote.h>


// Here we are using an IO pin to supply the IR receiver with +5v.
// This is a shortcut for low mAmp power where you may have available IO pins and
// where the +5v is already used and you do not have a breadboard or splitter.
// Comment out this next line if you do not want to use an IO pin as supply.
#define IR_POWER_PIN A0 // declare pin number used for IR receiver power

int RECV_PIN = A1; // declare pin number connected to signal pin of IR receiver


IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{

// 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

Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what's going on.
Serial.println("Enabling IRin");
irrecv.enableIRIn(); // Start the receiver
Serial.println("Enabled IRin");
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}
53 changes: 53 additions & 0 deletions examples/ScoutBotics/Level_2/GLC_IRcontrol_Mode5c/Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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 9

// 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 A5 // analog pin your voltage divider is connected
#define CUTOFF 9 // cut off voltage... for example, for a 3 cell lithium, set 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

// set these values ONLY if using the gripper
// to disable and conserve memory, comment out #define GRIPPER_PIN
//#define GRIPPER_PIN A5
#define GRIPPER_OPEN 180 // degree of gripper servo where gripper is open
#define GRIPPER_CLOSED 75 // degree of gripper servo where gripper is closed
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/* 10/22/2018
**** fix mode 5 notes
confirm pid good for scoutbotics
compile or rename tabs
add note of where modes are, m1,m2 etc
/
general cleanup of variables and function names
add better instructions
remove clutter
create extra folder in examples with other remote IRcode only examples
wiring diagrams
This program will setup the Gobbit robot to be controlled and programmable by an infrared (IR) remote.
See videos and project directions : http://www.primalengineering.com/robots/irprogram.html
** See the Config.h tab for hardware and other settings **
(the tabs are at the top of this text area)
"IRremote" library is also needed. Make sure it is installed through the Library Manager
The Gobbit robot needs an arduino Uno, motor driver, line sensor, infrared receiver, and piezo beeper (element).
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. This is also
known as "Dead Reckoning."
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.
4) This mode is a minor mode of mode 1&2. It is only used for "trimming" the motors (full forward and
backward directions only) if needed for Mode 1&2 to function better.
5) Tiled line solving mode. This receives IR number commands only which call, in the ordere entered,
the matching functions in the &&&&& tab to navigate the tiled path, regardless of which end of the
tiles the robot enters first.
Use the example program to find the IR codes from your remote:
GobbitLineCommand->ScoutBotics->Level_2->GLC_GetIRcodes
In GLC_IRgetCodes, Make sure to set your RECV_PIN and your IR_POWER_PIN if used.
Update the #define IR button values here in the tab "IRcodes.h" to match your remote's buttons
(the tabs are at the top of this text area)
There are examples of some IR remote control codes in the variious tabs of the example
GobbitLineCommand->ScoutBotics->Level_2->GLC_SampleIRcodes
For GobbitLineCommand function definitions, see the GobbitLineCommand "GLC_Functions" example sketch.
** See comments within the code and modes (m1-5 tabs) for further details **
*/

#include "Config.h"
#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() {

#ifdef GRIPPER_PIN
MyBot.setGripPinOpenClosed(GRIPPER_PIN, GRIPPER_OPEN, GRIPPER_CLOSED);
#endif

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 timing 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 9v is 0.2, 0.001, 3.4
MyBot.setPIDfineRange(0.6); // default at 9v is 0.04
#endif

MyBot.setBatteryVolts(BATTERY_VOLTS);

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

#ifdef GRIPPER_PIN
MyBot.gripOpen();
#endif

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;

case 5: // Start Tile Mode
modeStartedBeep();
modeFive();
break;
}
}
}











Loading

0 comments on commit fce8125

Please sign in to comment.