davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Self balancing robot??

Mon May 10, 2021 7:17 am

Hi all,

I'm trying to learn robotics - i'm retired and need a few projetcs :D :D

Currently building a simple robo-dog kit but was looking at videos of self-balancing robots which seem more suitable for beginners ?

They all seem to use Arduino's, is the Pico a good substitute for robotics or would i be setting off in the wrong direction?

I realise it would need a wifi module etc but also see hat these days pretty much anything is available for almost no money, i come from the days when i would get a bus to an electronics shop and spend a lump of cash on a couple of transistors!

I have a box of stepper motors, some mini driver boards, a few IMU boards and other bits that i have started collecting for projects :)

Is there any recommended reading or forum for Pico in robotics?

Any tips would be much appreciated

Nitro_fpv
Posts: 74
Joined: Tue Mar 30, 2021 11:56 am
Location: Switzerland

Re: Self balancing robot??

Tue May 11, 2021 8:52 am

Hello, if you are serious I would look at this free PDF and write and execute all these examples myself without copying.
Then you will see if you like Pi Pico and MicroPython.

https://hackspace.raspberrypi.org/books ... ython-pico

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Tue May 11, 2021 9:44 am

Nitro_fpv wrote:
Tue May 11, 2021 8:52 am
Hello, if you are serious I would look at this free PDF and write and execute all these examples myself without copying.
Then you will see if you like Pi Pico and MicroPython.

https://hackspace.raspberrypi.org/books ... ython-pico
Thanks, i have that book on the way, its due today :)

User avatar
HermannSW
Posts: 4123
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Self balancing robot??

Wed May 12, 2021 5:13 am

Quite some information on my two self-balancing robots, with balancing based on distance to ground or camera frame processing and laser dot location:
viewtopic.php?f=37&t=299797

In case code does not balance perfectly, but does move robot a bit too far forward, robot can drive on two wheels!
Image

Image
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Thu May 13, 2021 3:14 pm

Nitro_fpv wrote:
Tue May 11, 2021 8:52 am
Hello, if you are serious I would look at this free PDF and write and execute all these examples myself without copying.
Then you will see if you like Pi Pico and MicroPython.

https://hackspace.raspberrypi.org/books ... ython-pico
Have been playing with Pico and this book all afternoon, a couple of LED's and Pico is a pretty good test bench, lots of fun :D

However, working through the book i have been stumped and not sure if its an error i have made but cannot see or an error in the book?

My code matches the book but i get a syntax error on Line 18 of " 'button' is not defined"

Any tips??
Screenshot 2021-05-13 at 16.10.25.png
Screenshot 2021-05-13 at 16.10.25.png (85.98 KiB) Viewed 1153 times

User avatar
B.Goode
Posts: 12073
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Self balancing robot??

Thu May 13, 2021 3:36 pm

davek0974 wrote:
Thu May 13, 2021 3:14 pm
Nitro_fpv wrote:
Tue May 11, 2021 8:52 am
Hello, if you are serious I would look at this free PDF and write and execute all these examoples myself without copying.
Then you will see if you like Pi Pico and MicroPython.

https://hackspace.raspberrypi.org/books ... ython-pico
Have been playing with Pico and this book all afternoon, a couple of LED's and Pico is a pretty good test bench, lots of fun :D

However, working through the book i have been stumped and not sure if its an error i have made but cannot see or an error in the book?

My code matches the book but i get a syntax error on Line 18 of " 'button' is not defined"

Any tips??

Screenshot 2021-05-13 at 16.10.25.png


I don't see why it would cause the error you report, but the snippet of code you posted does not match my PDF copy at around page 65.

It might help troubleshooting to refer to the specific page in your text, and to post the whole of your script.

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Thu May 13, 2021 3:44 pm

Hi

the code won't match word for word as i am learning using my own version of printed texts,the structure should be the same though which i think it basically is.

the full code is below but remember its not the exact as printed

Code: Select all

import machine
import utime
import _thread

led0 = machine.Pin(25, machine.Pin.OUT)
led1 = machine.Pin(15, machine.Pin.OUT)
led2 = machine.Pin(14, machine.Pin.OUT)
led3 = machine.Pin(13, machine.Pin.OUT)

button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN)

global button_pressed
button_pressed = False

def button_reader_thread():
    global button_pressed
    while True:
        if button.value() == 1:
            button_pressed = True
        utime.sleep(0.01)
_thread.start_new_thread(button_reader_thread, ())


t = 1

while True:
    if button_pressed == True:
        led1.value(1)
        for i in range(5):
            led0.value(1)
            utime.sleep(0.3)
            led0.value(0)
    
    global button_pressed
    button_pressed = False        
    led1.value(1)
    led2.value(0)
    led3.value(0)
    utime.sleep(t)
    led1.value(1)
    led2.value(1)
    led3.value(0)
    utime.sleep(t)
    led1.value(0)
    led2.value(0)
    led3.value(1)
    utime.sleep(t)
    
    
    
    
Last edited by davek0974 on Thu May 13, 2021 4:01 pm, edited 1 time in total.

User avatar
B.Goode
Posts: 12073
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Self balancing robot??

Thu May 13, 2021 3:47 pm

davek0974 wrote:
Thu May 13, 2021 3:44 pm
Hi

the code won't match word for word as i am learning using my own version of printed texts,the structure should be the same though which i think it basically is.

the full code is below but remember its not the exact as printed

also when i save the post it deletes all the indentation??



That's what the forum software provides [ CODE ] tag markup to deal with....


You can rectify it retrospectively.

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Thu May 13, 2021 4:01 pm

Thanks, done

User avatar
HermannSW
Posts: 4123
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Self balancing robot??

Thu May 13, 2021 9:44 pm

Mark button as global in the function, or move the definition into the function
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Fri May 14, 2021 5:19 am

Thanks, i'll try that later

So its an omission in the book?



Dave

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Fri May 14, 2021 6:49 am

This seems to work, thanks

Code: Select all

def button_reader_thread():
    button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_DOWN)
    global button_pressed
    while True:
        if button.value() == 1:
            button_pressed = True
        utime.sleep(0.01)
_thread.start_new_thread(button_reader_thread, ())

Nitro_fpv
Posts: 74
Joined: Tue Mar 30, 2021 11:56 am
Location: Switzerland

Re: Self balancing robot??

Sat May 15, 2021 11:08 pm

davek0974 wrote:
Thu May 13, 2021 3:14 pm
Any tips??

The book has some flaws!
Here are all the errors in the book Described and Corrected:

https://hackspace.raspberrypi.org/downl ... Errata.pdf

Have fun with the examples: =)

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Sun May 16, 2021 5:39 am

Nitro_fpv wrote:
Sat May 15, 2021 11:08 pm
davek0974 wrote:
Thu May 13, 2021 3:14 pm
Any tips??

The book has some flaws!
Here are all the errors in the book Described and Corrected:

https://hackspace.raspberrypi.org/downl ... Errata.pdf

Have fun with the examples: =)
Thanks, they must have revised the print as my copy has all those corrected, just the one i found earlier that is not listed :D

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Sun May 16, 2021 8:28 am

Is there a group or forum recommended for total beginners in robots?

I think the simplest introduction is the self balancing two wheel type?

I have in my box of bits, Pi Pico boards, TB6612 motor drivers, two Nema17 steppers, an IMU board, and loads of discrete components, breadboards etc.

I have no doubt that these things can be combined to reach my goal, but finding in-roads is proving troublesome, probably my fault for picking the Pico and not an Arduino :? I have used steppers in a step/dir control before but i see the 6612 is PWM/direct step control using 4 inputs? maybe i got the wrong controller?

I see lots of videos on SBR's but none that really give detail that strikes a chord with my learning style yet, the wiring is not an issue just the logic the controls the motors etc.


Edit,
it seems the TB6612 stepper drive and my motor choice do not match as there is no current-limit on the 6612 and my motors are 1.7A which is above the output of the 6612 (1.2A) so i'll look for some better boards.

User avatar
B.Goode
Posts: 12073
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Self balancing robot??

Sun May 16, 2021 10:57 am

davek0974 wrote:
Sun May 16, 2021 8:28 am
Is there a group or forum recommended for total beginners in robots?

I think the simplest introduction is the self balancing two wheel type?

I have in my box of bits, Pi Pico boards, TB6612 motor drivers, two Nema17 steppers, an IMU board, and loads of discrete components, breadboards etc.

I have no doubt that these things can be combined to reach my goal, but finding in-roads is proving troublesome, probably my fault for picking the Pico and not an Arduino :? I have used steppers in a step/dir control before but i see the 6612 is PWM/direct step control using 4 inputs? maybe i got the wrong controller?

I see lots of videos on SBR's but none that really give detail that strikes a chord with my learning style yet, the wiring is not an issue just the logic the controls the motors etc.


Edit,
it seems the TB6612 stepper drive and my motor choice do not match as there is no current-limit on the 6612 and my motors are 1.7A which is above the output of the 6612 (1.2A) so i'll look for some better boards.


I think the simplest introduction is the self balancing two wheel type?


Noone else has contradicted you, so I will do it: that sounds like a big challenge! I think the simplest introduction would be an inherently stable 2 or 4 wheeled 'buggy'. Maybe not as challenging initially, but perhaps a simpler start to gain some basic skills?

User avatar
nick.mccloud
Posts: 1227
Joined: Sat Feb 04, 2012 4:18 pm

Re: Self balancing robot??

Sun May 16, 2021 12:19 pm

B.Goode wrote:
Sun May 16, 2021 10:57 am

I think the simplest introduction is the self balancing two wheel type?

Noone else has contradicted you, so I will do it: that sounds like a big challenge! I think the simplest introduction would be an inherently stable 2 or 4 wheeled 'buggy'. Maybe not as challenging initially, but perhaps a simpler start to gain some basic skills?
I would have, but I had to take a moment ...

One simple DIY robot design that allows you to go on to do all sort of stuff is the ChickBot - http://chickbot.club.

Pictures & discussion on my PicoBot: viewtopic.php?f=144&t=305068

Fundamentally you need a bit of ply as the chassis, a way to attaching some of what are referred to as Arduino Yellow Motors on eBay, a motor driver (chip + breadboard as I've used in the picture or a dual motor drive board off eBay (you don't need one with a heatsink)), battery pack and some wire / Dupont (jumper) wires.

I'd put some random full disclosure about me being the ChickBot designer but as it's licensed CC0 1.0 Universal aka not licensed aka no copyright, I'm not going there and I think I'm about £10k down on the project, be assured that no money is being made there at all - turns out it wasn't pre-built or sexy enough. The website hasn't been updated in a while so you have to extrapolate / infer. Happy to answer questions.
Pico/RP2040 ≠ Arduino
Pico = hot rod kit car, Arduino = hot rod kit car wrapped in cotton wool with buoyancy aids & parachute

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Sun May 16, 2021 1:58 pm

Thanks all, seems i need to reduce my entry point a bit then :D

I'll order some smaller steppers and start with just a pico, driver and motor maybe :D

davek0974
Posts: 203
Joined: Mon Jul 22, 2019 1:52 pm

Re: Self balancing robot??

Mon May 17, 2021 1:56 pm

Messing about in the basement of Pico,

I have been playing with a little joystick, scaling, dead-band etc. Is my code the worst ever or am i on the right track, usage is irrelevant really I just wanted to read the stick with ADC and output a value within a certain range 4000-500, with the dead-stick being 0, output falling in either direction and enough dead-band to stop the fairly large random ADC values when the stick is not being touched. There is a direction flag as well as might be used in a step/dir motor drive

Code: Select all

import machine
import utime

Ypot = machine.ADC(26)
dir = 0

def scale_number(unscaled, to_min, to_max, from_min, from_max):
    return (to_max-to_min)*(unscaled-from_min)/(from_max-from_min)+to_min

while True:
    Yval = Ypot.read_u16()#read the ADC value
    if Yval > 33250: #allow for dead-band
        dir = 1#set direction flag
        print(Yval)
        print(dir)
        x = scale_number(Yval, 4000, 500, 33200, 65311)
        print(int(x))
    elif Yval < 33050:#allow for dead-band
        dir = 0#set direction flag
        print(Yval)
        print(dir)
        x = scale_number(Yval, 500, 4000, 200, 33100)
        print(abs(int(x)))
    utime.sleep(0.1)
    

User avatar
nick.mccloud
Posts: 1227
Joined: Sat Feb 04, 2012 4:18 pm

Re: Self balancing robot??

Mon May 17, 2021 6:17 pm

Bit of a departure from the original topic.

Perhaps best re-post in the MicroPython section for code reviews.
Pico/RP2040 ≠ Arduino
Pico = hot rod kit car, Arduino = hot rod kit car wrapped in cotton wool with buoyancy aids & parachute

User avatar
B.Goode
Posts: 12073
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Self balancing robot??

Mon May 17, 2021 6:28 pm

nick.mccloud wrote:
Sun May 16, 2021 12:19 pm
B.Goode wrote:
Sun May 16, 2021 10:57 am

I think the simplest introduction is the self balancing two wheel type?

Noone else has contradicted you, so I will do it: that sounds like a big challenge! I think the simplest introduction would be an inherently stable 2 or 4 wheeled 'buggy'. Maybe not as challenging initially, but perhaps a simpler start to gain some basic skills?
I would have, but I had to take a moment ...

One simple DIY robot design that allows you to go on to do all sort of stuff is the ChickBot - http://chickbot.club.

Pictures & discussion on my PicoBot: viewtopic.php?f=144&t=305068

Fundamentally you need a bit of ply as the chassis, a way to attaching some of what are referred to as Arduino Yellow Motors on eBay, a motor driver (chip + breadboard as I've used in the picture or a dual motor drive board off eBay (you don't need one with a heatsink)), battery pack and some wire / Dupont (jumper) wires.

I seem to have acquired a collection of about 8 wheeled robot buggies of one sort or another, and at least 2 - perhaps 3 - of those are ChickBots.

The last time I was able to work with him in person, over a year ago, my then 5-year old grandson and I were working on a Bluetooth-controlled 'work-alike' implementation of the BeeBot module he is familiar with from school. That was based on a ChickBot chassis with stepper motors.

User avatar
HermannSW
Posts: 4123
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Self balancing robot??

Tue May 18, 2021 8:51 pm

nick.mccloud wrote:
Sun May 16, 2021 12:19 pm
One simple DIY robot design that allows you to go on to do all sort of stuff is the ChickBot - http://chickbot.club.
One simple type of robot platform you can get for 20$ from aliexpress are caterpillar robots.
They are unbelievable stable in curves (this is real time smartphone video of more than U-turn):
Image


You can add camera:
Image


Run wheels at crazy speeds (here when jacked up):
Image


Add whatever you want to add to the platform (that comes with caterpillar base and motors, you have to add the rest):
Image


More info in raspcatbot thread:
viewtopic.php?f=37&t=267999
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

Return to “General”