I thought I'd start a project page for this thing. I'm having a lot of fun - it's nice to finally write an application for the Propeller instead of just a library.
Propeller running PropWare
-based code does a few things: 1) reads from the gyroscope (L3GD20) and accelerometer (ADXL345), 3) computes tilt angle, 4) runs PID algorithm, 5) drives the motors, 6) logs data to SD card (might get cut due to code size restraints) 7) receive directional commands
ESP8266 Huzzah running Micropython relays directional commands from WiFi to Propeller. Might be capable of relaying logging information (such as current tilt angle) back to the controlling device
UDP socket over WiFi
Android phone application can set the trim (to compensate for unbalanced chassis or poorly mounted accelerometer) and send directional commands via a virtual joystick
Propeller code is here: https://github.com/DavidZemon/MiniSegway
ESP8266 code is yet to written
Android code will be posted soon
Propeller Software Architecture
I'll describe the software architecture by cog. At the time of this writing, the following cogs are running:
Loop at 250Hz, reading a single value from each of the gyroscope and accelerometer. Scale the accelerometer to floating point number with its units being g's. Scale the gyroscope to a floating point number with its value being in degrees per second. A global boolean is set high at the end of each loop.
Wait on the global boolean from the sensor reader to go high. Clear the boolean, then compute the robot's current tilt angle based on the previous angle and the current sensor data. Taking into account the trim, compare the current angle with the maximum allowed angle and throw an error if the angle is too great.
Run an I2C bus as a slave, waiting for incoming messages from the ESP8266. Save the messages to a global variable and set a global boolean high.
For a received message, then clear the global boolean for message received. Determine if the message sets trim or requests movement. If trim, adjust the trim in memory, save the updated trim to EEPROM. If movement, adjust the ideal tilt angle and turn power.
PID Loop/Motor Controller
Status: In progress
*NOTE: This may get absorbed into the angle computer cog.
Run the PID loop against the trimmed tilt angle. Use the PID output to compute the necessary power for balance, then adjust the value for each wheel based on the turn power. Set motor direction pins for each motor. Save each motors' power to a global variable.
Run two PWM waves at 20 kHz. Read the motor power variables from the motor controller cog and update the PWM duty cycle.
Print various tidbits of information which are available via global variables over a serial (UART) console for debugging.
Waits patiently for the a global error flag to get set. If an error is thrown, the parent cog shuts down all other cogs and blinks a WS2812 LED with a unique color depending on the error.