Skip to main content

kitronik :Move buggy (Python controlled servos)

In a previous post I looked at controlling the Kitronik :Move buggy using Javascript based blocks. In this short post I will show controlling the servos of the micro:bit based :Move buggy with Python.

Control is via pin1(left motor) and pin2 (right motor) and the motors have to be driven in opposite directions to move forward or backwards. The direction of the motors is controlled by the analogue value written to the pins; pinX.write_analog(180) - anticlockwise or pinX.write_analog(1) - clockwise (pinX.write_analog(0) - stops the motor). Setting the analog_period seems to work at 20ms; this was found by experiment, discussed in a previous post.

So the initial code below sets up the moves for forward, backward, turn left, turn right all controlled with a move for so many milliseconds.

Code 
from microbit import *

pin1.set_analog_period(20)
pin2.set_analog_period(20)

def forward(N):
    pin1.write_analog(180)
    pin2.write_analog(1)
    sleep(N)
    
def backward(N):
    pin1.write_analog(1)
    pin2.write_analog(180)
    sleep(N)

def turnLeft(N):
    pin1.write_analog(1)
    pin2.write_analog(1)
    sleep(N)

def turnRight(N):
    pin1.write_analog(180)
    pin2.write_analog(180)
    sleep(N)

while True:
    forward(1500)
    backward(1500)
    turnLeft(1500)
    turnRight(1500)   

I would recommend running the :Move buggy on a surface that isn't smooth, I found the wheels slipping on a smooth surface. This is a really nice little robot to play with.

All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with. Twitter @scottturneruon

Comments

  1. With other hand made robots I have also experienced wheels slipping on smooth surfaces like tile floors. The work around I use is to stretch rubber bands around the wheels so the "tread" is not so slippery. Maybe that trick will work for you.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Robot Software

In the previous blog posts for this 'series' "It is a good time...."  Post 1  looked at the hardware unpinning some of this positive rise in robots; Post 2  looked at social robots; Post 3  looked at a collection of small robots; Post 4 looked at further examples of small robots Robots, such as the forthcoming Buddy and JIBO, will be based some established open sourceand other technologies. Jibo will be based around various technologies including Electron and JavaScript (for more details see:  http://blog.jibo.com/2015/07/29/jibo-making-development-readily-accessible-to-all-developers/ ). Buddy is expected to be developed around tools for Unity3d, Arduino and OpenCV, and support Python, C++, C#, Java and JavaScript (for more details see http://www.roboticstrends.com/article/customize_your_buddy_companion_robot_with_this_software_development_kit ).  This post contin ues with some of the software being used with the smaller robots.  A number ...

Speech Recognition in Scratch 3 - turning Hello into Bonjour!

The Raspberry Pi Foundation recently released a programming activity Alien Language , with support Dale from Machine Learning for Kids , that is a brilliant use of Scratch 3 - Speech Recognition to control a sprite in an alien language. Do the activity, and it is very much worth doing, and it will make sense! I  would also recommend going to the  machinelearningforkids.co.uk   site anyway it is full of exciting things to do (for example loads of activities  https://machinelearningforkids.co.uk/#!/worksheets  ) . Scratch 3 has lots of extensions that are accessible through the Extension button in the Scratch 3 editor (see below) which add new fun new blocks to play with. The critical thing for this post is  Machine Learning for Kids  have created a Scratch 3 template with their own extensions for Scratch 3 within it  https://machinelearningforkids.co.uk/scratch3/ . One of which is a Speech to Text extension (see below). You must use this one ...

Escape the Maze with a VR robot - Vex VR

You don't need to buy a robot to get programming a robot, now there are a range of free and relatively simple to start with robot simulators to play with. Three examples are listed below: - Make code for Lego EV3  https://robotsandphysicalcomputing.blogspot.com/2020/05/programming-robots-virtually-3-lego-ev3.html   - i Robot simulator  https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-2-irobot.html - Vex robotics Vexcode VR   https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-1-vexcode.html   It is the last one of these ( https://www.vexrobotics.com/vexcode-vr ) that is the focus of this post and return to hit, after an earlier discussion in  https://robotsandphysicalcomputing.blogspot.com/2020/04/programming-robots-virtually-1-vexcode.html   .  Two of the nice things about the package, apart from being free, are it uses a Scratch-like programming language and it provides a ...