Skip to content

Implement BALANC3R #130

Closed
Closed

Description

@dwalton76

Nice article here on these robotos:
http://robotsquare.com/2014/07/01/tutorial-ev3-self-balancing-robot/

The author has an older blog post with a RobotC implemenation of the software:
http://robotsquare.com/2012/02/13/tutorial-segway-with-robotc/

I started porting that to python here:
https://github.com/dwalton76/ev3dev-lang-python/tree/gyro/demo/lego_official_projects

but do not have things working yet.

Activity

  1. dwalton76 commented on Jan 22, 2016

    @dwalton76
    CollaboratorAuthor

    @rhempel feel free to assign this to me. I created the ticket in case anyone else is interested in working on this with me.

  2. antonvh commented on Mar 14, 2016

    @antonvh
    Contributor

    I'm actually working with Laurens on the python port. We're nearly there... Some trouble with r/w speed. It's patched in the development branch.

  3. dwalton76 commented on Mar 14, 2016

    @dwalton76
    CollaboratorAuthor

    Cool. Laurens and I were trading emails in Jan when I was working on this, he was very helpful. I got it somewhat working but it still needed some fine tuning. My branch is
    https://github.com/dwalton76/ev3dev-lang-python/tree/gyro

    feel free to grab anything from there that you like. Laurens said he had a much better algorithm in the works so I stopped working on this until he got that published.

  4. dlech commented on Mar 30, 2016

    @dlech
    Member

    I have a program for the gyroboy in progress. However, I have been having trouble getting the loop time down as well. What kind of loop time are you able to get? I am at 20-25ms. Hoping to get it down below 10ms though. It seems like I was getting this 1+ years ago the last time I was doing a balancing robot in ev3dev. Basically, each sysfs read/write is 3 to 4ms, which is way too long. If we could get it down to 1ms, it would be ok. It depends on if there is something in python that can be changed or if the seek and read/write syscalls just actually take that long.

    It's also interesting to me that the first iteration of the loop takes much longer. Here are my function call times in ms for the first iteration.

    GT: 0
    time: 0
    GG: 14
    GM: 12
    EQ: 1
    cntrl: 8
    CHK: 1
    sleep: 2
    

    Then for a later iteration...

    GT: 0
    time: 0
    GG: 4
    GM: 8
    EQ: 1
    cntrl: 7
    CHK: 1
    sleep: 0
    

    GG is reading the gyro sensor value. GM reads the motor positions of 2 motors and cntrl writes the duty_cycle_sp of 2 motors.

    I've included the patch from @antonvh that removes the extra absolute path lookup, which, by the way, no longer seems to be in the develop branch (did @rhempel force push?)

  5. dlech commented on Mar 30, 2016

    @dlech
    Member

    Interesting. I was using python3, however times are better in python2.

    Python 2.7.9 (default, Mar  1 2015, 13:52:09) 
    [GCC 4.9.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import timeit
    >>> timeit.repeat('f.seek(0); f.read()', 'f = open("/sys/class/tacho-motor/motor0/position", "r+")', number=1000)
    [1.2495520114898682, 1.2299458980560303, 1.206686019897461]
    
    Python 3.4.2 (default, Oct  8 2014, 14:47:30) 
    [GCC 4.9.1] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import timeit
    >>> timeit.repeat('f.seek(0); f.read()', 'f = open("/sys/class/tacho-motor/motor0/position", "r+")', number=1000)
    [3.638115724999807, 3.6730630889996974, 3.7583993859989278]
    
  6. dlech commented on Mar 31, 2016

    @dlech
    Member

    hmm... I implemented the change I suggested for python3 in #155, but I'm not really seeing any changes in performance.

    GT: 0
    time: 1
    GG: 3
    GM: 6
    EQ: 1
    cntrl: 7
    CHK: 0
    sleep: 2
    
  7. rhempel commented on Mar 31, 2016

    @rhempel
    Member

    No @rhempel did not pull in that patch yet (he thinks)

  8. rhempel commented on Mar 31, 2016

    @rhempel
    Member

    First iteration is longer because it sets up the caching subsystem - after that the reads/writes go through already open file handles.

  9. WasabiFan commented on Mar 31, 2016

    @WasabiFan
    Member

    No @rhempel did not pull in that patch yet (he thinks)

    I think @dlech was pointing out that the PR was merged but the commits are no longer in the develop branch. That likely means that someone force-pushed while their working HEAD was behind the remote.

  10. dlech commented on Mar 31, 2016

    @dlech
    Member

    I've made a gyroboy program that does not use ev3dev-lang-python. I got the loop time down to about 15ms, so there is some overhead in ev3dev-lang-python that might be able to be shaved off, but the really just might be the best we can do with python and sysfs.

  11. dwalton76 commented on Mar 31, 2016

    @dwalton76
    CollaboratorAuthor

    Lauren's has a newer version of his balancing algorithm and he wrote it in Python. I made a class based version of it for ev3dev. I am out of town for work right now but will send a pull request this weekend when I get home. He has his cycle time at 10ms

  12. antonvh commented on Mar 31, 2016

    @antonvh
    Contributor

    I did a python version of the balancer here: https://github.com/antonvh/segway
    It's forked from the original by @laurensvalk here: https://github.com/laurensvalk/segway

    I used ev3dev and with my patch (antonvh@abdcae4) I get loop times of around 16-17ms which is enough to balance.

    Laurens' version is without ev3dev and directly reads files. He's getting loop times of around 11ms. I think the ev3dev overhead is still too large. A few lines of python shouldn't make milliseconds of difference. I wonder where that comes from.

    I also did a BrickPi version: https://github.com/antonvh/segway/tree/brickpi

    On the Pi I get loop times of 10ms with ev3dev. But the BrickPi is acting up. It's all shaky and it feels like 'updateMotorsAndSensors()' is called too often by the driver. I have to investigate that some more, but I ran out of time.

  13. 29 remaining items

  14. rhempel commented on Apr 28, 2016

    @rhempel
    Member

    @laurens or @antonvanh - do you have the balancer code with the line follower as well?

  15. laurensvalk commented on Apr 28, 2016

    @laurensvalk

    @rhempel : Yes, I just uploaded the line following example to my github just for you. I'm guessing it is for the FIRST festival so I'll keep it short. You need to:

    • Build BALANC3R, put color sensor on port 3, attach it as shown
    • Put on your ev3:
      • segway-line.py
      • makelinks.sh
    • Go into the folder where these files are
    • Make both executable
    • Run segway-line.py

    Also, you just tagged another Github user called Laurens.

  16. laurensvalk commented on Apr 28, 2016

    @laurensvalk

    Or if you use Git, this is all you need to do, as I believe it maintains the executable settings:

    @edmundronald in your case, if you don't need line following just yet, run the other program, so just do:

    • git clone https://github.com/laurensvalk/segway.git #This downloads all the segway files to your ev3
    • cd segway/ev3/ev3dev/python/ #This navigates to the folder with the code
    • ./segway.py #You can start the code in this way
  17. edmundronald commented on Apr 28, 2016

    @edmundronald

    @laurensvalk
    I followed your instructions. The program segway.py seems to run, except it doesn't do anything apart from exiting when I press the touch sensor. Here is the console output.

    robot@ev3dev:~/segway/ev3/ev3dev/python$ ./segway.py
    -----------------------------------
    Calibrating...
    GyroOffset:  0.07
    -----------------------------------
    GO!
    -----------------------------------
    Loop time: 10.436174568965518 ms
    -----------------------------------
    STOP
    -----------------------------------
    robot@ev3dev:~/segway/ev3/ev3dev/python$ 
    
  18. edmundronald commented on Apr 29, 2016

    @edmundronald

    @laurensvalk
    I've checked that the motors are on A and D, and are seen by Brickman, the values change when I twist the wheels. And I extracted the SD card and ran your Balanc3r-Remote-control project with great success, it balances. It's just the Python version which doesn't move the wheels. Any ideas?

    btw, I also ran the demo in https://github.com/rhempel/ev3dev-lang-python.git and it runs errorfree, now that I have added the touch sensor to the hardware, but it also doesn't move the motors.

    Edmund

  19. dlech commented on Apr 29, 2016

    @dlech
    Member

    my guess is a kernel version/ev3dev-lang-python version mismatch. there have been breaking changes to the motor drivers, so if they don't match, motors don't work.

    Also, I would suggest https://help.github.com/categories/writing-on-github/

    if you put a "code fence" around your terminal output, it makes it much easier to read.

    ```
    ^ this is the start of a code fence
    
    code goes here
    
    v this is the end of the code fence
    ```
    
  20. edmundronald commented on Apr 29, 2016

    @edmundronald

    @dlech
    What should I do at this point? Until "hello world" runs, I am slavishly following instructions.
    I have now scanned through the netiquette link. Here anyway is a codefence test:

    Ceci n'est pas du code
    I wish there were backticks on my french keypboard
    Buvez de ce whisky que le patron juge fameux
    
  21. dlech commented on Apr 29, 2016

    @dlech
    Member

    You can edit your previous post so we can read it. 😉

    Also, what kernel are you running on your EV3 (output of uname -r)?

  22. edmundronald commented on Apr 29, 2016

    @edmundronald

    @dlech
    Edited. Now, why didn't I think of that by myself? :)

    robot@ev3dev:~$ uname -r
    3.16.7-ckt26-10-ev3dev-ev3
    robot@ev3dev:~$ 
    
  23. dlech commented on Apr 29, 2016

    @dlech
    Member

    I image @laurensvalk has not updated for the motor changes in kernel release 10. You can attempt to fix the code or you can attempt to downgrade your kernel.

  24. dlech commented on Apr 29, 2016

    @dlech
    Member

    Although after a quick look at the code, I don't see any changes that need to be made...

  25. edmundronald commented on Apr 29, 2016

    @edmundronald

    @dlech Downgraded kernel, perfect! Thank you!
    @laurensvalk Very stable. Thank you for the help and the code!
    @rhempel Ran your demo too. Balances ok. Needs the touch sensor apparently (not part of original Laurens Valk web demo), and the old kernel. Thank you!

    It would be nice to know whether the code is really incompatible with the new kernel or whether I did something strange ... I guess you'll be interested in that too.

    Here is a log of the fix being applied:

    robot@ev3dev:~$ sudo flash-kernel --force 3.16.7-ckt21-9-ev3dev-ev3
    [sudo] password for robot: 
    flash-kernel: forcing install of 3.16.7-ckt21-9-ev3dev-ev3 instead of 3.16.7-ckt26-10-ev3dev-ev3.
    flash-kernel: WARNING: Installing any new kernel package might override this.
    flash-kernel: installing version 3.16.7-ckt21-9-ev3dev-ev3
    
  26. changed the title [-]Implement BALANC3R and Gyro Boy[/-] [+]Implement BALANC3R[/+] on May 1, 2016
  27. dwalton76 commented on May 1, 2016

    @dwalton76
    CollaboratorAuthor

    BALANC3R is now supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions