Skip to main content

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

Release files for KitronikPicoAutonomousRoboticsPlatform 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for KitronikPicoAutonomousRoboticsPlatform 1.0.0
File Size Uploaded
KitronikPicoAutonomousRoboticsPlatform-1.0.0.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for KitronikPicoAutonomousRoboticsPlatform 1.0.0
File Interpreter ABI Platform
KitronikPicoAutonomousRoboticsPlatform-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / KitronikPicoAutonomousRoboticsPlatform-1.0.0.tar.gz

Download URL KitronikPicoAutonomousRoboticsPlatform-1.0.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a031d6ba24992f1472c8b5a02e43414dbad8eb9d73054bee8f8686ccb5bb6da3
BLAKE2b-256 checksum
How to use checksums
0815a1b18479e0318e3706406e6b4415e7fc9b7a289a5ffd666d8380d8b73974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / KitronikPicoAutonomousRoboticsPlatform-1.0.0-py3-none-any.whl

Download URL KitronikPicoAutonomousRoboticsPlatform-1.0.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76be4ca4072ddd450fd2de38475aadb42d9bdf30dcf747e2eec6b24f7906a399
BLAKE2b-256 checksum
How to use checksums
fc18e9c997dbfce75efcba413775004dd4f8c795831c2ee16d07a0ee5f751758
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page