Giter Site home page Giter Site logo

segway's People

Contributors

laurensvalk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

segway's Issues

Document how to use the NXT HiTechnic Gyroscope sensor on segway.py

The building instructions state you can use:

1x Gyroscopic Sensor.
Use one of the following sensors:

  • EV3 Gyro by LEGO (pictured below)
  • NXT Gyroscope by HiTechnic

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.

[VEX IQ] modkit help

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

imperfect balancing and only for some time

As suggested by @laurensvalk in #11

Hardware:

Running EV3 brick with LEGO reloadable battery and HiTechnic Gyro sensor

Software:

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

Symptoms:

The robot does balance but only for some seconds.

Environment:

Robot runs on carpet so it does not fall too hard ;-)

Progress:

Will test later on harder floor

Increased loop time

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

Not balancing after restarting

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.

Sudden glitch causes robot to crash

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

  • Potential bug in Segway code
    • Overflow
    • Issue with deque
    • Math error (/0)
    • Rounding error
    • Sending incorrect duty signal, outside [-100,100]. Or noninteger
  • Corrupt / Missing sensor data
    • Outlier
    • (Persistently) incorrect value
    • Sensor(s) not giving new data
  • Timing glitch, loop hanging for too long, causing all kinds of problems:
    • Incorrect signal time integration
    • Incorrect signal derivatives (motor speed)
    • Correlation with Bluetooth/Wifi being active?
    • Some useful info here

As a start, some data logging code may help.

Doesn't balance well... What's the wheel size?

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!

Where's the docs?

Hi I'm looking for the docs for the ev3 segway.py code.
Where can i find it?

To Do

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?

(Vex IQ) Not balancing correctly

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?

Investigate effect of battery level on smoothness and tuning

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:

  • Run the Segway at various levels of discharge of the same battery
  • Run the Segway with various types of batteries (e.g. 1.5V or 1.2V rechargeable), or the provided battery pack

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.

Simplification

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.