Ovaltine's Segway Clone - DIY Electric Car Forums
Go Back  

DIY Electric Car Forums > EV Conversions and Builds > Non Road Going Vehicles

Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 09-25-2013, 04:07 PM
Ovaltineo Ovaltineo is offline
Senior Member
 
Join Date: Jul 2013
Location: Melbourne, Australia
Posts: 697
Ovaltineo is on a distinguished road
Default Ovaltine's Segway Clone

Preamble: Arduino MEGA board is the best board to use - it has more memory, hardware serial ports and general IO ports than an UNO. A Mega clone can be bought on eBay for less than $17, so there is really no reason to get use an UNO unless you already have one.

If you want to use Roboclaw or Sabertooth and bluetooth for the CloneConsole Android application, then you must use the MEGA because two software serial ports cannot operate reliably on the Arduino.

================================================== ================================================== ==================


I have started a new thread to make it easy to find the latest release of my Segway Clone code. I intend to edit this post with each new release. Mizplix' original Segway Clone build thread is here.

This compiles on Arduino IDE v1.0.2 or later. Older versions may not work.

You MUST read the README file for instructions.

Segway Clone for Arduino version history:
v4.0
Fixed a few bugs with communication interface to CloneConsole Android app. Fixed intermittent "Error 11" on I2C bus.
Added new configuration parameters BOARD_OFFSET_DIVIDER and STEER_OFFSET_DIVIDER which specify remote control sensitivity.

v4.1
Fixed compile error when using Bluetooth with non-MEGA boards. Added MOTOR_LR_RATIO (defined in Motors.h) to adjust power output between left and right motors.

v4.2
Disabled alarm if voltage is below 5V (powered by USB). Added INVERT_STEERING option to swap left and right steering. Added FAN_PIN option to turn on fan output when temperature goes above TEMP_FAN_ON.

v4.3
Added support for PWM dual-channel motor shield from Elechouse - select #define PWM_SHIELD_CONTROLLER in SegwayClone.h

v4.4
Changed to inverse PWM for PWM_SHIELD_CONTROLLER. Added LOCKED_BY_DEFAULT option - unlock using CloneConsole Android app.

v4.5
Fixed LOCK bug. Added ALARM_LOCKED beeper indicator.

v4.6
Fixed FAN output bug. Added ROBOCLAW_ENCODER_CONTROLLER to support a Roboclaw with quadrature encoders.

v4.7
Fixed compile error and multiplied Pf & Df by 10 when using ROBOCLAW_ENCODER_CONTROLLER.

v4.8
Fixed compile error when BLUETOOTH is defined but not TEMPERATURE_SENSORS.

v4.9
Fixed compile error when MIN_BATTERY_4 is decimal.

v5.0
Added alarm for I2C error - long beep, short beep, long beep.
"Calibrate" via CloneConsole is now allowed regardless of motor speed when using USB power only (must have voltage sensor).
Fixed compile error when using ROBOCLAW_CONTROLLER or SABERTOOTH_CONTROLLER.

v5.1
Changed serial baud rate from 38400 to 9600 for SABERTOOTH_CONTROLLER.

v5.2
Bluetooth module is now supported with UNO + PWM controllers - connect bluetooth HC-06 TX to pin 5 and RX to pin 6. You can't enable VOLTAGE_LED with this configuration.

v5.3
Added support for RIDER_SENSOR. Define the RIDER_SENSOR digital input pin, KP_OFF and KD_OFF for your controller in SegwayClone.h. Define MOTOR_MAX_OFF for your controller in Motors.h. Sensor must pull RIDER_SENSOR pin HIGH when rider is ON and pull it LOW when the rider is OFF.

v5.4
Added support for low power L298N motor controller - select #define L298N_CONTROLLER in SegwayClone.h
Added option for INVERT_RIDER_SENSOR. This inverts the logic of the RIDER_SENSOR pin.

v5.5
Fixed L298N motor controller code by removing "setPwmFrequency(HZ_3906)" during initialization.

v5.6
Changed bluetooth baud rate to 19200 for non-Mega boards. Non-Mega users must first switch to CALIBRATE_MODE to re-program the HC-06 module.

v5.7
Added software low-pass filter for voltage sensor.
Added support for HX711 weight sensor.
Added RIDER_SENSOR to telemetry sent to CloneConsole.
Added baud rate detection with bluetooth module.

v5.8
Added internal pull-up of RIDER_SENSOR pin. This has the effect of inverting the RIDER_SENSOR logic.
Sensor must now pull pin to GND if rider is ON and leave it open or HIGH if rider is OFF.
Added internal pull-up of RX3 pin on MEGA board when using bluetooth module.

v5.9
Fixed MAX_MOTOR for Roboclaw with encoder. Added support for forward/backward tilt control by defining POT_TILT_PIN.

v6.0
Added center adjustment for POT_STEERING.

v7.0
Added voltage and temperature sensing through Roboclaw serial commands.
Replaced standard blocking Wire library with non-blocking I2C module. Hopefully, this fixes locking of the Arduino!!!
Added timeout when waiting for data from Bluetooth interface.
Added support for WTV020 Voice module on Serial port #2.


v7.1
Gyro and accelerometer are now both used to compute steering angle (more stable at high speed).
Added SUBTRACT_BANK_ANGLE option to compensate for terrain banking (available only if using MPU6050_X2_STEERING).

v7.2
Fixed inverted steering angle gyro and bank angle gyro.
Added support for OSMC (Open Source Motor Controller) without MOB (Modular OSMC Brain) - #define OSMC_CONTROLLER.
Added option for exponential steering response - #define EXPONENTIAL_STEER_DIVIDER


Get the latest SegwayClone source from Github:
https://github.com/ovaltineo/SegwayClone



Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle.

First schematic is for the Mega with 2 X BTN7960 controllers and 2 X MPU6050. Second schematic is for the UNO with Roboclaw and 2 X MPU6050.


CloneConsole for Android version history:
v1.0
Original release.

v1.1
Improved GUI appearance.

v1.2
Changed tilt and steer indicator to aircraft-style attitude indicator.

v1.3
Added remote control option. Press the option menu to switch between "telemetry" and "remote control" screens.

v1.4
Added "*" buton to swap between "telemetry" and "remote control" screens because option menu doesn't work as expected on some phones.

v1.5
Fixed bug where P and D values can become negative. Increased P and D range by using exponential range, however, resolution decreases exponentially too.

v1.6
Added scaling to fit the screen size.

v1.7
Fixed scaling of remote control view.

v1.8
Added Calibrate view. Fixed saving of P and D. Revamped remote control for more resolution and configurable sensitivity. Added "ACK"s to improve synch between Android and Arduino.

v1.9
Added LOCK/UNLOCK feature.

v2.0
Added RIDER_SENSOR support - screen is GRAY when rider is OFF and WHITE when rider is ON. P and D will be updated to OFF and ON values.

v2.1
Fixed scaling for Calibrate & Lock view.
Attached Images
File Type: png CloneConsolev1_2.png (59.9 KB, 749 views)
File Type: png UNO_Sabertooth_2XMPU6050.png (19.5 KB, 1057 views)
File Type: png Mega_BTN7960_2XMPU6050.png (23.0 KB, 1182 views)
File Type: png Mega_OSMC_2XMPU6050.png (22.0 KB, 578 views)
File Type: png UNO_BTN7960_2XMPU6050.png (19.9 KB, 9535 views)
File Type: png UNO_BTN7960_2XMPU6050_Bluetooth.png (19.8 KB, 593 views)
File Type: png UNO_Roboclaw_2XMPU6050.png (19.5 KB, 530 views)
File Type: png Mega_Roboclaw_2XMPU6050_No_LED.png (18.7 KB, 145 views)
Attached Files
File Type: zip CloneConsole_v2.1.zip (333.5 KB, 307 views)

Last edited by Ovaltineo; 04-18-2016 at 03:53 AM. Reason: Fixed UNO schematics - XDA and XCL should be SDA and SCL.
Reply With Quote
Sponsored Links
Advertisement
 
  #2  
Old 09-26-2013, 12:36 AM
phaedrus phaedrus is offline
Member
 
Join Date: Aug 2013
Posts: 75
phaedrus is on a distinguished road
Default Re: Ovaltine's Segway Clone

Compiles fine here for an Uno with no mods required, although I've not installed it in any hardware.

Cheers, P.
Reply With Quote
  #3  
Old 09-26-2013, 07:50 AM
quikstep quikstep is offline
Junior Member
 
Join Date: Sep 2013
Posts: 10
quikstep is on a distinguished road
Thumbs up Re: Ovaltine's Segway Clone

Hi Ovaltine!

I'm using Nano V3 and Sketch 1.0.5 of Linux.

My initial issue was:

Motors.ino:18:20: error: motors.h: No such file or directory
Motors.ino: In function ‘void initMotors()’:
Motors:136: error: ‘HZ_3906’ was not declared in this scope
Motors:137: error: ‘LEFT_PWM_PIN’ was not declared in this scope
Motors:138: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:139: error: ‘RIGHT_PWM_PIN’ was not declared in this scope
Motors:140: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors.ino: In function ‘void controlMotors(int, int)’:
Motors:150: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:154: error: ‘LEFT_DIR_PIN’ was not declared in this scope
Motors:156: error: ‘LEFT_PWM_PIN’ was not declared in this scope
Motors:161: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors:165: error: ‘RIGHT_DIR_PIN’ was not declared in this scope
Motors:167: error: ‘RIGHT_PWM_PIN’ was not declared in this scope


This is immediately rectified by changing Motors.ino
from #include "motors.h"
to #include "Motors.h"

Yes. Linux is such

After that, the compilation was a breeze (for PWM_DIR_CONTROLLER).

I'm suspecting that you've some angle protection (ran out of time to check as I wanted to feedback to your good work ASAP). My serial printout (changed to 38400 baud) hung at:

X Accel Offset -1771Y Gyro Offset -190Y Gyro Min -23994Y Gyro Max 28699


But nice work there. My motors just came and I'm conceptualizing the ride soon.
Reply With Quote
 
  #4  
Old 09-26-2013, 05:10 PM
Ovaltineo Ovaltineo is offline
Senior Member
 
Join Date: Jul 2013
Location: Melbourne, Australia
Posts: 697
Ovaltineo is on a distinguished road
Default Re: Ovaltine's Segway Clone

quikstep, I've now fixed the Linux bug. You need to get the latest code because I found out that pin 2 is not a PWM pin in the Uno/Nano.

The debug output is inside the clause which doesn't get called in an over-angle situation. You can move this or just change MIN_ANGLE and MAX_ANGLE.
Reply With Quote
  #5  
Old 09-26-2013, 09:27 PM
Ovaltineo Ovaltineo is offline
Senior Member
 
Join Date: Jul 2013
Location: Melbourne, Australia
Posts: 697
Ovaltineo is on a distinguished road
Default Re: Ovaltine's Segway Clone

quikstep,

I just realized that it is not an over-angle situation. You have compiled and run in MODE_CALIBRATE, hence it will print all those samples, take the average, save to EEPROM, and halt. You now need comment out or delete #define MODE_CALIBRATE, compile and upload. This time, it will wait for you to level the board at +-2 degrees, then it will start balancing on its own.
Reply With Quote
  #6  
Old 09-28-2013, 03:33 AM
quikstep quikstep is offline
Junior Member
 
Join Date: Sep 2013
Posts: 10
quikstep is on a distinguished road
Thumbs up Re: Ovaltine's Segway Clone

Hello Ovaltineo,

I can confirm that after commenting out MODE_CALIBERATE and changing some parameters for my situation ie. using MPU6050_X2_STEERING, PWM_DIR_CONTROLLER, Serial.begin(38400), MAX_ANGLE 30 and MIN_ANGLE -20, everything worked fine. This is at least working for Nano v3 + 2 MPU6050 only.

Thanks again for your help. Once I've hooked up everything, I'm confident I can also contribute to this forum.
Reply With Quote
  #7  
Old 09-28-2013, 05:20 AM
phaedrus phaedrus is offline
Member
 
Join Date: Aug 2013
Posts: 75
phaedrus is on a distinguished road
Default Re: Ovaltine's Segway Clone

OT: I was mulling over things from the other thread and wonder if it's worth commenting on the MPU board orientation in your README file for your next revision?

Nice job getting all those scenarios coded BTW!

Cheers, P.
Reply With Quote
  #8  
Old 09-28-2013, 05:29 AM
phaedrus phaedrus is offline
Member
 
Join Date: Aug 2013
Posts: 75
phaedrus is on a distinguished road
Default Re: Ovaltine's Segway Clone

Quote:
Originally Posted by quikstep View Post

Yes. Linux is such

...

But nice work there. My motors just came and I'm conceptualizing the ride soon.
QS: Thank you for making that comment re Linux; although I've used it in many different situations over the past 15yrs or so it never occurred to me that there would be Linux support for the compiler - just goes to show I'm a bit slow, really it should have been obvious I suppose!

Also, it would be interesting to hear what motors you're using?

Cheers, P.
Reply With Quote
  #9  
Old 09-28-2013, 07:58 AM
quikstep quikstep is offline
Junior Member
 
Join Date: Sep 2013
Posts: 10
quikstep is on a distinguished road
Default Re: Ovaltine's Segway Clone

Quote:
Originally Posted by phaedrus View Post
QS: Thank you for making that comment re Linux; although I've used it in many different situations over the past 15yrs or so it never occurred to me that there would be Linux support for the compiler - just goes to show I'm a bit slow, really it should have been obvious I suppose!

Also, it would be interesting to hear what motors you're using?

Cheers, P.
Bought these motors from China http://mytaofocus.com/item.php?id=20159160122

RMB 345 for only 1 motor. Not recommended seller though. Been really having bad experience with this company. Had to harass my agent many times to get answers from the company.
Reply With Quote
  #10  
Old 09-28-2013, 02:29 PM
phaedrus phaedrus is offline
Member
 
Join Date: Aug 2013
Posts: 75
phaedrus is on a distinguished road
Default Re: Ovaltine's Segway Clone

Quote:
Originally Posted by quikstep View Post
Bought these motors from China http://mytaofocus.com/item.php?id=20159160122

RMB 345 for only 1 motor. Not recommended seller though. Been really having bad experience with this company. Had to harass my agent many times to get answers from the company.
Shame about the seller, the motors look great! From the photographs in the advanced section it looks like they also do hub motors and/or complete balancing scooters. BLDC hub motors are something I'm keen to try at some stage.

Presently I'm using old mobility scooter motors which are relatively slow and with a right-angle gearbox it means there's a large motor casing that's got to stick out somewhere

Anyway it'll be interesting to hear how your design works out

Cheers, P.
Reply With Quote
Reply

Share or Bookmark this

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

 
Support DIY Electric Car
Sponsors

All times are GMT -6. The time now is 03:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
vBulletin Security provided by vBSecurity v2.2.2 (Pro) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
Ad Management by RedTyger