DIY Electric Car Forums banner

1 - 20 of 1718 Posts

·
Registered
Joined
·
697 Posts
Discussion Starter #1 (Edited)
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.
 

Attachments

·
Registered
Joined
·
10 Posts
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.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #4
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.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #5
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.
 

·
Registered
Joined
·
10 Posts
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.
 

·
Registered
Joined
·
75 Posts
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.
 

·
Registered
Joined
·
75 Posts
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.
 

·
Registered
Joined
·
10 Posts
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.
 

·
Registered
Joined
·
75 Posts
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.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #11
v2.3

As P. has suggested, I have now included the sensor orientation in the README.

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

I have now released v2.3. It fixes a bug in the sensor calibration (it didn't save all the calibration data, so steering might be bad). Everyone should re-calibrate using this version.

This version fixes a bug in the Roboclaw packet serial checksum which JRoque found.

I have also added support for the GY80 board which has an ADXL345 accelerometer and L3G4200D gyro.
 

·
Registered
Joined
·
75 Posts
Now that's impressive!

I think the answer is simply to make the clone go faster :D.

I've mentioned before that I'm interested in using BLDC motors; the ones I have in mind are from a washing machine (F&P smartdrive) which will do circa 1200rpm :eek:.

I'm sure that would that work with the LED's if you could stay on it :p

Cheers, P.
 

·
Registered
Joined
·
780 Posts
Hi everyone.

OT, bringing the code discussion here since the build thread is getting long and winded. Keeping in mind that I don't know how the segway works in reality, here's a few questions:

- When the sensor is tilted past the given max angle, the motors seem to be commanded zero speed immediately. Would it be better to initiate a controlled slow-down while attempting to keep the vehicle balanced, if possible? Otherwise, speed demons like myself, pushing the handle forward for more speed and going past max angle, might suddenly get ejected forward when the motors grind to a stop.

- How does "calibration" work? I was expecting that, after running "cal" it would grab whatever position the sensor is in and call that "balanced". However, if I run the "cal" routine and then go in "run" mode without moving the sensor at all, the motors spin forward, presumably trying to reach balance.

- I've seen other clones bring out the P, I and D controls to external pots for tweaking. Is that really necessary or do you typically reach a good set of values quickly enough to not bother with the pots. Knowing me, if I bring those pots out, I'll be twisting them non-stop because "balancing nirvana could be one nudge away..." if you know what I mean.

So I haven't moved the electronics to the wheels yet but from what I've seen on the bench, this thing will work! Congrats again on the code.

JR
 

·
Registered
Joined
·
75 Posts
Would it be better to initiate a controlled slow-down while attempting to keep the vehicle balanced, if possible?

- I've seen other clones bring out the P, I and D controls to external pots for tweaking. Is that really necessary or do you typically reach a good set of values quickly enough to not bother with the pots.

JR: Just as a comment on these two items - in some other balancing scooters there is a 'reserve' speed available to kick the rider back if they go too far. This is typically achieved by limiting max_motor to 60% - 70%, giving the possibility of 30% - 40% kick available to straighten you up (so to speak :)

There are other designs that do the slow down thing you speak of, typically taking 1-2 secs to do so.

In the former case, given the nature of some of the motors we're using it could possibly make the scooter very pedestrian under normal circumstances (I'd get something like 4km/h!) so I guess it's a bit of a trade-off, and so the slow-down system might be better, if your over-balance is correctable by that stage :D. I'm sure OT will comment on what he's done - possibly from empirical knowledge :eek:

In the other query you have, FYI I've tried OT's code on my unit and it operated fairly well with the default levels he has set in his code. I too have seen other designs with the adjustments available externally, but there are plenty more without it.

Personally I suspect the later gyro/accelerometer pairs are somewhat better than the earlier units and may well require less messing around.

I'm doing a little more on my machine presently and will comment further on those values if/when I find a need to adjust them.

Cheers, P.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #16
JR, I chose to do a full stop because, in my experience, the Segway runs into my calves if I fall forward (I live in a steep hill). Maybe sounding the buzzer before reaching Max angle is a good compromise.

There is another bug in the calibration routine which I will fix in the next release.

If you look at getP getI and getD, you will see that I babe commented out code there to read the values from pots. I used them initially and locked them in the code when I was happy. Since your drivetrain is different, I expect you'll be playing with these values a fair bit so the pots will be worth it.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #17
v2.4

I have fixed a gyro calibration bug. Please download v2.4. Select #defines in SegwayClone.h to match your hardware and re-calibrate.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #18 (Edited)
v2.5

Yes, you guessed it -- another calibration bug fixed in v2.5. This time, it is when reading data from EEPROM. I think this is the last of the calibration bugs :eek:. The good news is that if you already calibrated with v2.4, you don't need to re-calibrate coz the calibration data in EEPROM is valid.
 

·
Registered
Joined
·
10 Posts
Re: v2.3

As P. has suggested, I have now included the sensor orientation in the README.

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

I have now released v2.3. It fixes a bug in the sensor calibration (it didn't save all the calibration data, so steering might be bad). Everyone should re-calibrate using this version.

This version fixes a bug in the Roboclaw packet serial checksum which JRoque found.

I have also added support for the GY80 board which has an ADXL345 accelerometer and L3G4200D gyro.
Had a rotten weekend where my car was hit and got summoned the next day :mad:

For "Sensors must be aligned such that the X axis is level and pointing to the front of the vehicle.", is this the case for both breakout boards if I used 2 of them? Thanks.
 

·
Registered
Joined
·
697 Posts
Discussion Starter #20
Yes, it applies for both single and dual boards. I actually have the steering sensor with the X axis pointing down on my clone, but I had to add a different code for that.

I have been testing single and dual sensors recently. With the current code, the dual sensor is better coz steering and board tilting do not affect each other. With a single sensor, the board dips when I'm turning coz the zero level of the tilt (pitch) is affected. I am going to test a more complicated algorithm that hopefully will address this.
 
1 - 20 of 1718 Posts
Top