Goliath Fall 2017

Goliath Arduino Code & Calibration

Mark Huffman (Project Manager)


By Mark Huffman (Project Manager)

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.

Library’s Required

By Mark Huffman (Project Manager)

3Dot Library (Modification Needed)http://web.csulb.edu/~hill/ee400d/Technical%20Training%20Series/3DoT/Arduino/Robot3DoTBoard.zip

3-Axis Gyro Library: https://github.com/adafruit/Adafruit_L3GD20_U

These libraries need to be installed under your general Arduino library location. For help follow this guide: Arduino Library Install Guide

Code Methodology

By Mark Huffman (Project Manager)


Setup all Libraries

Setup all internal variables to defaults and define any objects

Setup 3Dot Library plus custom commands

Main Loop Structure:

Check-in obstacle avoidance mode

Either wait or execute next route

Check waiting for a new turn instruction

Wait for new turn instruction and then check if it is valid then execute

If no other mode, read color sensors and pass data to lineFollower code

Determines if drifting and corrects motor values

Check if there is an obstacle in the way

Check if an intersection was seen

If seen update virtual maze values then call whichway

Whichway looks at current room type and then returns the turn action

Set the turn action based on request

Update telemetry data

Check if in a turning action

Call readgyro and processTurn to see if the turn action is complete

Code Package & Install

By Mark Huffman (Project Manager)

Download the Code package Here: Final_Goliath_Code_Package.zip

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.

Code Calibration

By Mark Huffman (Project Manager)

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:

  1. Adjusting the raw color sensor readings
    1. In Goliath_Code.ino find readSensor()
    2. Uncomment the “part to calibrate for color reading”
    3. Place the Goliath so the color sensors are directly over an intersection
    4. Set this average value for both calibrationValues.colorSensorIntersection1 & calibrationValues.colorSensorIntersection2
    5. Now place Goliath so one of the sensors is near the edge of a straight black line
    6. Set the average value as calibrationValues.colorSensorLine1 & calibrationValues.colorSensorLine2
    7. 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
  2. 3Dot Version Usage
    1. Look for the definition boolean Dot503 = false;
    2. Changing the value to true sets the pin configuration and motor configuration to that of the 5.03 3Dot version.
    3. Leaving the value false sets the configuration to 3Dot version 4.54.
    4. Change if needed
  3. Correcting Motor Directions
    1. If the Goliath moves in a different direction then intended or turns incorrectly or always the motors may be miss-configured.
      1. Try swapping the motor wires A and B
      2. Correct via software
        1. Find the robotMovement() function
        2. commands[0]  & commands[2]  control motor directions
        3. For each case, correct the directions to the intended method
        4. Secondly, LEDDirection() may need to be corrected if the arrow indicates the wrong direction
        5. Correct it by changing the dir==”” names
  4. Adjusting Turns
    1. If turning isn’t very precise adjust these values as needed
    2. Set calibrationValues.turnStartTime as the time in milliseconds  to move past an intersection before turning in place
    3. Set calibrationValues.turnRadians to the radians of a 90-degree turn (Should only be increased if Goliath never fully completes a turn)
    4. Set calibrationValues.turnScanVariance to change the radians for which to begin looking for a line (Adjust down if Goliath overshoots a turn)
    5. Set calibrationValues.turnbackupTime to set a backup time after completing a turn (May not be needed depending on sensor placement)
  5. Line Following Aggressiveness
    1. Set calibrationValues.lineAgressiveness to adjust the corrective action of following a line (May need to be raised or lowered)