The purpose of this post is to link to the final Goliath code and explain the overall structure for future use. Secondly, to explain how the code needs to be updated and calibrated to a particular Goliath chassis. Overall, getting the Goliath code to work for this mission involved the creation of 16 files and over 1300 of lines of code. Most of the code is integrated with EE 444 and then layered with new content required to save and control the maze data. Combined the code takes 82% of the available memory space on the 3Dot board. Note: using the Goliath code involves modifying 2 files in the 3Dot library.
Code Layout – General
By Mark Huffman (Project Manager)
Goliath_Code.ino – The main code file, contains setup(), loop(), line following, sensor readings, led display control, configures all imported libraries and provides the main calibration.
lineFollower.ino – Handles line following, receives sensor data and controls motor speeds.
maze.h – Contains the actual maze lookup table, direction lookup tables, and all data structures.
obstacle_avoidance.ino – Handles reading the IR sensor for detecting objects and calls actions.
virtual_instr.ino – Updates virtual maze direction and location so that maze position is always known.
WhichWay.ino – Makes decisions at intersections, depending on the mode triggers user input or reads back from saved memory.
EEPROM.ino – Contains the read and write functions to EEPROM, for saving the recorded route and playing it back.
custom_telemetry.ino – Handles translating received custom command data and triggers actions.
Configure.h – Pin configuration and other settings for the 3Dot Library
SparkFun_VL6180X.cpp – The modified library used for the IR rangefinder.
Adafruit_TCS34725.ino – The modified library for the Color Sensors.
Adafruit_LEDBackpackCom.cpp – The modified library for the LED display.
It should contain two folders called “Goilath_Code” and “Library Update”. The files within “Library Update” must be copied into the 3Dot Library Folder. This is typically located under C:\Users\[NAME]\Documents\Arduino\libraries\Robot3DotBoard\src\. Copy and then replace the two included files within the library. Note: Arduino will need to be restarted after this change.
Then simply open any file in the “Goliath_Code” folder and the main code is assessable.
It is then recommended to check out the Goliath User Guide for actually operating the Goliath with code.
Part of the Goliath code includes a calibration section where values controlling turns, speed, timing and color sense can be adjusted. These changes are necessary depending on the Goliath chassis and the maze design/material. Typically the calibration order is as follows:
Adjusting the raw color sensor readings
In Goliath_Code.ino find readSensor()
Uncomment the “part to calibrate for color reading”
Place the Goliath so the color sensors are directly over an intersection
Set this average value for both calibrationValues.colorSensorIntersection1 & calibrationValues.colorSensorIntersection2
Now place Goliath so one of the sensors is near the edge of a straight black line
Set the average value as calibrationValues.colorSensorLine1 & calibrationValues.colorSensorLine2
Note: This can be done independently for each sensor by changing the index value from 1 to 0 and then setting the correct calibration value
3Dot Version Usage
Look for the definition boolean Dot503 = false;
Changing the value to true sets the pin configuration and motor configuration to that of the 5.03 3Dot version.
Leaving the value false sets the configuration to 3Dot version 4.54.
Change if needed
Correcting Motor Directions
If the Goliath moves in a different direction then intended or turns incorrectly or always the motors may be miss-configured.
Try swapping the motor wires A and B
Correct via software
Find the robotMovement() function
commands & commands control motor directions
For each case, correct the directions to the intended method
Secondly, LEDDirection() may need to be corrected if the arrow indicates the wrong direction
Correct it by changing the dir==”” names
If turning isn’t very precise adjust these values as needed
Set calibrationValues.turnStartTime as the time in milliseconds to move past an intersection before turning in place
Set calibrationValues.turnRadians to the radians of a 90-degree turn (Should only be increased if Goliath never fully completes a turn)
Set calibrationValues.turnScanVariance to change the radians for which to begin looking for a line (Adjust down if Goliath overshoots a turn)
Set calibrationValues.turnbackupTime to set a backup time after completing a turn (May not be needed depending on sensor placement)
Line Following Aggressiveness
Set calibrationValues.lineAgressiveness to adjust the corrective action of following a line (May need to be raised or lowered)