Kitronik Autonomous Robotics Platform (Buggy) for Pico
Project description
Other languages: FRANCAIS
Kitronik-Pico-Autonomous-Robotics-Platform-MicroPython
A class and sample code for the Kitronik Autonomous Robotics Platform for the Raspberry Pi Pico. (www.kitronik.co.uk/5335)
On the Autonomous Robotics Platform:
- Forward is defined as the end away from the power switch / castor
- Left and Right are defined when facing Forward
- The Pico should be inserted with the USB connector facing the rear (away from the Pen hole)
To use, save PicoAutonomousRobotics.py file onto the Pico so it can be imported.
Import PicoAutonomousRobotics.py and construct an instance:
import PicoAutonomousRobotics
robot = PicoAutonomousRobotics.KitronikPicoRobotBuggy()
This will setup the various correct pins for motors / servos / sensors.
Motors
Drive a motor:
robot.motorOn(motor, direction, speed)
where:
- motor => "l" or "r" (left or right)
- direction => "f" or "r" (forward or reverse)
- speed => 0 to 100
Stop a motor:
robot.motorOff(motor)
where:
- motor => "l" or "r" (left or right)
Servos
The servo PWM (20ms repeat, on period capped between 500 and 2500us) is driven using the Pico PIO.
The servos are registered automatically in the initalisation of the class.
This process sets the PIO PWM active on the servo pin.
If the pin is needed for another purpose it can be 'deregistered' which sets the PIO to inactive.
robot.deregisterServo(servo)
To re-register a servo after it has been de-registered:
robot.registerServo(servo)
where:
- servo => the servo number (0-3)
Drive a servo:
robot.goToPosition(servo, degrees)
where:
- servo => the servo to control (0-3)
- degrees => 0-180
robot.goToPeriod(servo, period)
where:
- servo => the servo to control (0-3)
- period => 500-2500 in us
Ultrasonic Sensor
Read ultrasonic distance:
robot.getDistance(whichSensor)
where
- whichSensor => "f" or "r" for front or rear sensor This parameter is defaulted to "f" so the call can be:
robot.getDistance()
Setup the units:
robot.setMeasurementsTo(units)
where:
- units => "inch" for imperial (inch) measurements, "cm" for metric (cm) measuerments
Line Following
Sensors are marked on the sensor PCB for left, right, and centre. Left is defined as on the left side when looking down on the buggy, facing the front.
The centre sensor is slightly ahead of the side sensors.
Read values:
robot.getRawLFValue(whichSensor):
returns:
- the raw sensor value in the range 0-65535 (low numbers represent dark surfaces)
where:
- whichSensor => "c", "l", "r" (centre, left or right sensor)
The line following sensor can also return true or false:
robot.isLFSensorLight(whichSensor):
returns:
- True when sensor is over a light surface and False when over a dark surface
where:
- whichSensor => "l","r", or "c"
Set light / dark thresholds:
The light / dark determination is based on the values in "darkThreshold" and "lightThreshold".
To set the thresholds use:
robot.setLFDarkValue(darkThreshold, OptionalLeftThreshold = -1, OptionalRightThreshold = -1)
robot.setLFLightValue(lightThreshold, OptionalLeftThreshold = -1, OptionalRightThreshold = -1)
Typical values for 'Light' surfaces would be under 20000, and for 'Dark' surfaces over 30000.
Optional thresholds can set different values for Left and Right sensors in which case the first value sets the Centre threshold.
If not used all 3 sensors have the same threshold.
Buzzer
The buzzer is driven with a PWM pin.
Sound the buzzer:
robot.soundFrequency(frequency)
where:
- frequency => 0-3000 (the frequency to sound in Hz)
Silence the buzzer:
robot.silence()
Beep the buzzer (like a car horn):
robot.beepHorn():
ZIP LEDs
ZIP LEDs have a 2 stage operation...
Setup ZIP LEDs:
Set the LEDs with the colour required:
robot.setLED(whichLED, whichColour)
where:
- whichLED => 0-3
- whichColour => tuple of (Red Value, Green Value, Blue Value), or one of the pre-defined colours:
COLOURS = (BLACK, RED, YELLOW, GREEN, CYAN, BLUE, PURPLE, WHITE)
Turn off the LEDs:
robot.clear(whichLED)
where:
- whichLED => 0-3
Control the brightness:
robot.setBrightness(value)
where:
- value => 0-100 (brightness value in %)
Make the changes visible:
robot.show():
Troubleshooting
This code is designed to be used as a module. See: https://kitronik.co.uk/blogs/resources/modules-micro-python-and-the-raspberry-pi-pico for more information
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for KitronikPicoAutonomousRoboticsPlatform-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a031d6ba24992f1472c8b5a02e43414dbad8eb9d73054bee8f8686ccb5bb6da3 |
|
MD5 | 517cffb0a419c4fa1b2d0be49fd887f9 |
|
BLAKE2b-256 | 0815a1b18479e0318e3706406e6b4415e7fc9b7a289a5ffd666d8380d8b73974 |
Hashes for KitronikPicoAutonomousRoboticsPlatform-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76be4ca4072ddd450fd2de38475aadb42d9bdf30dcf747e2eec6b24f7906a399 |
|
MD5 | d45875e47be29248bebbd36962af8d21 |
|
BLAKE2b-256 | fc18e9c997dbfce75efcba413775004dd4f8c795831c2ee16d07a0ee5f751758 |