laurensvalk / segway Goto Github PK
View Code? Open in Web Editor NEWCode for robots balancing on two wheels, made with various robotics platforms.
License: MIT License
Code for robots balancing on two wheels, made with various robotics platforms.
License: MIT License
The building instructions state you can use:
1x Gyroscopic Sensor.
Use one of the following sensors:
Running segway.py with the driver for the HiTechnic gyro sensor set like this:
echo ht-nxt-gyro > /sys/class/lego-port/port1/set_device
The program ends like this:
Traceback (most recent call last):
File "./segway.py", line 52, in <module>
gyroSensor.mode = gyroSensor.MODE_GYRO_RATE
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 1716, in mode
self._mode = self.set_attr_string(self._mode, 'mode', value)
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 229, in set_attr_string
return self._set_attribute(attribute, name, value)
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 216, in _set_attribute
raise Exception("%s is not connected" % self)
Exception: GyroSensor is not connected
Second attenpt with the HT gyro set as default analog device ends quite the same:
Traceback (most recent call last):
File "./segway.py", line 52, in <module>
gyroSensor.mode = gyroSensor.MODE_GYRO_RATE
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 1716, in mode
self._mode = self.set_attr_string(self._mode, 'mode', value)
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 229, in set_attr_string
return self._set_attribute(attribute, name, value)
File "/usr/lib/python3/dist-packages/ev3dev/core.py", line 216, in _set_attribute
raise Exception("%s is not connected" % self)
Exception: GyroSensor is not connected
System info (from ev3dev-sysinfo
)
Image file: ev3dev-stretch-ev3-generic-2017-10-24
Kernel version: 4.9.49-ev3dev-1.5.1-ev3
Brickman: 0.10.0
ev3devKit: 0.5.2
Board: board0
BOARD_INFO_HW_REV=7
BOARD_INFO_MODEL=LEGO MINDSTORMS EV3
BOARD_INFO_ROM_REV=6
BOARD_INFO_SERIAL_NUM=0016535166E2
BOARD_INFO_TYPE=main
The segway is so much fun! Thanks for that Laurens.
the program is great, but at school i am not allowed to use ROBOTC. i am not very good at translating the code, but if you know a way than can you please post it. help me
I just built this, and ran the code- the robot just moves backwards at full power no matter which angle the robot is leaning. All firmware and sensors are updated
As suggested by @laurensvalk in #11
Running EV3 brick with LEGO reloadable battery and HiTechnic Gyro sensor
System info (from ev3dev-sysinfo
)
Image file: ev3dev-stretch-ev3-generic-2017-10-24
Kernel version: 4.9.58-ev3dev-1.6.0-ev3
Brickman: 0.10.0
ev3devKit: 0.5.2
Board: board0
BOARD_INFO_HW_REV=7
BOARD_INFO_MODEL=LEGO MINDSTORMS EV3
BOARD_INFO_ROM_REV=6
BOARD_INFO_SERIAL_NUM=0016535166E2
BOARD_INFO_TYPE=main
Using segway.py and parameters.py at a previous commit
The robot does balance but only for some seconds.
Robot runs on carpet so it does not fall too hard ;-)
Will test later on harder floor
Hi @laurensvalk,
first of all thank you for the code so far, the robot actually balances, even though it is not pretty smooth.
I also ran the balancer software you "coded" using the lego legacy software. (http://robotsquare.com/2014/07/01/tutorial-ev3-self-balancing-robot/) which makes the robot run much more stable while also being able to work with a loop time of 22 milliseconds.
My computations for speed and steering require about 10ms, so it is currently not possible for me to use the python implementation.
The difference between the two implementations seems to be in the PID controller. I tried to reimplement the software but with no success yet.
Do you plan to release a ported version? Or do you have parameters that enable the robot to balance with a looptime of 20+ms?
Best,
Michael
Sometimes when stopping the Python program and restarting it afterwards, you get really sluggish balancing performance or it will fail right away. Something is slowing the loop down.
Reboot fixes it.
I have not yet found a way to reproduce this consistently. I'm opening this issue to log it when it occurs.
Often, the robot will balance just fine for minutes straight. Very constant behavior, with minor motion back and forth.
Then all of a sudden, it starts to sway and falls over, for no apparent reason.
Is anyone else experiencing this?
Things to look for
As a start, some data logging code may help.
Just ran it on my EV3 and unfortunately it doesn't seem to balance well.
Trying to find out why, I think the wheel sizes may be different? Are you aware of what size wheels are needed for this program to work? I am using the ones that came with my EV3 Education kit, but they look different to those pictured in the link given. If the wheels are different sizes, that's probably the issue!
I have copied and pasted this code with no success. The robot moves very jerkily and I have no control with me remote. What am I doing wrong?
Current segway.py needs both the EV3-gyro and the HiTechnic-gyro on the USB side of the EV3 brick.
The Balanc3r building instructions has the HT-gyro on the other (speaker) side.
Hi I'm looking for the docs for the ev3 segway.py code.
Where can i find it?
A running list of things I'd like to investigate or add to the code
Find discrepancies in signals prior to the sudden crash.
Verify that motor speed computation is (approximately) correct. In a datalog, compare this signal to a filtered derivative of the actual motor position. Study delays and other potential problems.
Study that the duty cycle is correctly set. Consider doing a read immediately after write. Does it always match? Or are sets occasionally ignored? What happens if you manage to store a disallowed value (outside [-100, 100])?
Add support for other gyros
Log not just the loop time, but the times prior and past all file read/writes. Are certain read/writes consistently delaying or does it occur randomly across all read/writes?
forward and back are really slow and not smooth at all.. turning seems to be doing ok but not as smooth as your video..
Hi,
i'm new to ev3 gyroboy - mindstorm and i was trying to use the code in this link:
https://github.com/laurensvalk/segway/tree/master/ev3/ev3dev/python
to test it and see how it works. but i keep getting multiple errors:
1- permission denied = changed the permission to 777
2- text file busy = ??
i also created the file makelinks.sh but still can't test the code.
Thanks
When I tried it out it would go back and forth just to balance, and would hardly move otherwise, and was extremely prone to falling. I also noticed in your video that your robot's LED isn't lit up. Why is that, and how do I fix my robot?
I have VEX IQ version updated to 2.1.13.
When i try to start segway-remote program, both of Motors starting working, and doesn't stop till I Cancel this.
If you've followed the instructions carefully but your VEX IQ robot still won't balance, please ask for help here.
Currently, the code does not account for varying battery level. As a consequence, the effective voltage for a given duty cycle percentage varies with battery type and battery level.
One potential solution would be to scale the duty cycle value with the measured battery voltage. However, this relationship might not necessarily be as linear as we might like.
First, it would be useful to have some qualitative insight in the balancing performance with regards to batteries while running the same code:
So far, I've primarily worked with the LEGO Education battery and VEX IQ battery. Various levels of discharge does not seem to have much impact here. However, the response with 6x1.5V=9V might be quite different.
I'm curious to hear about other people's experiences.
I'm currently working on a new version of the code which is a bit more pythonic. Feel free to give it a try if you're interested.
The whole control loop is now about 10 lines of code. The full code is here.
For now only the EV3 gyro is supported. I haven't scaled for battery voltage yet, so the tuning may not work for you right away. But with simpler code, it's hopefully easier to modify on your end.
# Main loop
while True:
# Loop start
start = time()
# Body angle
rate = highpass.filter(gyro.rate)
angle = integrator.integral(rate)
# Wheel translation
average_motor_degrees = (right.position + left.position)/2
distance = average_motor_degrees * cm_per_degree
speed = differentiator.derivative(distance)
# Control signal
duty = gain_angle*angle + gain_rate*rate + \
+ gain_distance*distance + gain_speed*speed
# Motor actuation
left.duty(duty)
right.duty(duty)
# Sleep until loop complete
while time()-start < looptime:
sleep(0.002)
The code uses ev3devlight to interface with the hardware, which is a python3 and micropython compatible library. See this for installation instructions.
It doesn't have all the ev3dev functionality, but it takes only a few seconds to load. It's also faster for reading sensors and controlling motors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.