Autonomous Tugboat - Final project for Fundamentals of Robotics class, Fall 2018
Read this if you just want to know how to get Lesley up and running.
You need to do everything listed here only once
- Set up the EasyTransfer library on your laptop. READ THE README IN THIS LINK -> https://github.com/EverardoG/Arduino-EasyTransfer and it will walk you through installation
- Get the XBee software up and running on your laptop. It's the primary mode of communication between the boat and the laptop. Here's a link. Just go through the "Computer Side" section -> https://github.com/olinrobotics/main/wiki/XBee-Radios
- Unplug all Arduinos from one another. Upload Tugboat_Arduino_1.ino to Arduino 1, Tugboat_Arduino_2.ino to Arduino 2, Tugboat_Arduino_3 to Arduino 3. Arduino 1 is the pixy-cam Arduino, Arduino 2 is the low level sensing Arduino, and Arduino 3 is the THNK/ACT arduino. NOTE: There's a "Serial Select" switch on Arduino 2's motor shield. Switch to "SW_SER" to upload code. Switch back to "HW_SER" once code is uploaded.
- Connect all Arduinos together to set up the wired data pipeline. Arduino 1 Tx -> Arduino 2 Rx Arduino 2 Tx -> Arduino 3 Rx
- Verify that the XBee is indeed plugged into Arduino 3.
- Flip the Arduino switch to "On". Make sure that all the Arduino "On" lights are nice and bright.
- To play with the motors, toggle the motor ESTOP so the Hippocampus LED is blinking.
- Connect the OCU XBee to your laptop via the adaptor board.
- Open up the XCTU.desktop software. Remember, you need to navigate to where the software is installed and use
sudo XCTU ./XCTU.desktop
to make it work. - Click "Add a Radio Module" in the upper left hand corner. Add the OCU XBee. It should show up with "OCU" as its name.
- In the upper right, there's a gear icon. Next to it is a computer/ terminal icon. Click it.
- Now you'll see three icons above the "Console Log". Click "Open". This makes it so that your laptop XBee is now listening to the boat XBee. You can also type into the "Console Log" to send commands to the boat!
- Optional: For offshore debugging, you can plug in the Arduino-Laptop USB cable so that you can read Serial printouts on your laptop. Fear not! For this will not interfere with XBee or Arduino comms so long as you don't try to send Lesley any information via Serial.
void init()
- initializes an IR sensor, sets pin modevoid update()
- updates IR data and saves it into data attributevoid print()
- prints the data
int pin
- analog in pin IR is plugged intoint x_offset
- not yet implementedint y_offset
- not yet implementedint heading
- not yet implementedint data
- IR reading in cm
- not yet implemented
void init()
- initializes an sonar sensor, sets pin modevoid update()
- updates sonar data and saves it into data attributevoid print()
- prints the data
int pin
- PWM pin sonar is plugged intoint x_offset
- not yet implementedint y_offset
- not yet implementedint heading
- not yet implementedint data
- IR reading in cm
This object contains all the sensors and pin values for our specific tugboat configuration. This was made to streamline the sensor data flows from the sensors to the tugboat, especially when sensors get put on different arduinos. All pin values for sensors are stored in Sensors.h
void init()
- initializes all sensors, sets all pin modesvoid update()
- updates sonar data and saves it into data attributevoid print()
- prints the data
IR ir_0
- IR object 0- ...
IR ir_5
- IR object 5Sonar sonar_0
- Sonar object 0- ...
Sonar sonar_2
- Sonar object 2Pixycam pixycam
- Pixycam object
void init()
- initializes a boat, also calls init function for sensorsvoid update()
- calls update function for all sensorsvoid move()
- moves the boat based on headingvoid print()
- not yet implementedvoid stateController()
- sets the state for the boat and calls appropriate functionvoid stop()
void idle()
void avoid()
void lwall()
void rwall()
void lcircle()
void rcircle()
void chase()
void search()
void setPropSpeed(int speedPercentage)
void setHeading(int degHeading)
Sensors sensors
int heading
- Heading value in degreesint velocity
- Velocity value between -100 and 100int state = 0
- Integer representing state- State 1: stop
- State 2: idle
- State 3: avoid - use all sensor data to move to a safer position
- State 4: lwall - follow wall on left of boat
- State 5: rwall - follow wall on right of boat
- State 6: lcircle - circumnavigate an object on left of boat
- State 7: rcircle - circumnavigate an object on right of boat
- State 8: chase
- State 9: search
- State Other: stop
We're using the EasyTransfer library for inter-Arduino communications. A link to getting this library set up is here -> https://github.com/EverardoG/Arduino-EasyTransfer.
Arduino 1 passes the pixydata
object to Arduino 2. Arduino 2 packs the data from pixydata
and the information collected by its low level sensor suite into sensedata
. Arduino 2 sends 'sensedata' to Arduino 3. This is all done using the Tx and Rx pins on the Arduinos. This means it uses the same serial channel that you use for the Arduino Serial Monitor. The THINK/ ACT Arduino can print to Serial, but sending it anything through the Serial monitor will confuse it.
unsigned long timestamp1
- millisecond timestamp from Arduino 1 when it sentpixydata
(This was just to test functionality)
We will add more to this once we figure out exactly what pieces of data we want from the pixycam.
-
unsigned long timestamp1
- millisecond timestamp from Arduino 1 when it sentpixydata
(This was just to test functionality) -
unsigned long timestamp2
- millisecond timestamp from Arduino 2 when it sentsensedata
(This was just to test functionality) -
int ir_0_data
- meters measured by IR 0 -
int ir_1_data
- meters measured by IR 1 -
int ir_2_data
- meters measured by IR 2 -
int ir_3_data
- meters measured by IR 3 -
int ir_4_data
- meters measured by IR 4 -
int ir_5_data
- meters measured by IR 5 -
sonar_0_data
- meters measured by sonar 0 -
sonar_1_data
- meters measured by sonar 1 -
sonar_2_data
- meters measured by sonar 2
There will be more here once we integrate actual values from the pixycam.
We can now communicate with our boat remotely! It's awesome! We use an Xbee
object on Arduino 3 to communicate via XBee.
For it to work, you need to install the XBee software on your laptop first. Here's a really great walkthrough on that -> https://github.com/olinrobotics/main/wiki/XBee-Radios. Once you have that set up, here's the step-by-step guide to setting up comms.
void begin(int baudrate)
- sets the data baudrate for XBee transmissionvoid write(char array)
- the boat will send out this char array to the XBee channelint available()
- returns the number of bytes avaiable to read from XBee channelchar read()
- returns the character read on the XBee channel (Someone should double check this, but for our purposes, this captures everything that matters)
- write behavior functions
- put sensor object functions in separate folder when complete
- determine if PWM signals alone would be good enough for sonars (will need other pins if sensors have conflict issues) and update code to reflect that
- determine how Pixycam data is processed