XRP
  • Experiential Robotics Platform (XRP)
    • Building the XRP Robo
    • Programming Raspberry Pi Pico W
    • Programming with XRPCode IDE
    • Programming with wpilib
      • Hardware
      • Imaging and Setup
      • Creating an XRP Program
    • Programming with ROS
  • Hardware Components
    • Different Types of Motors
      • Brushed DC Motors
      • Brushless Motor
      • Stepper Motor
      • Servo Motors
    • Key Characteristics of DC Motors
    • Encoders
  • Motor Control Theory
    • What use in FRC
    • PID control (Proportional-Integral-Derivative control)
    • Field Oriented Control (FOV)
  • Use XRP to practice
    • Plotting Fix
    • Reading from the Encoder
    • Measure position
    • Control the motor
    • Tuning PID
  • Use XRP with Micropython
    • Setup Envirrment
    • Use the Shell
    • XRP library
  • Connect with Wifi
Powered by GitBook
On this page
  1. Use XRP with Micropython

XRP library

PreviousUse the ShellNextConnect with Wifi

Last updated 7 months ago

The micro-python git is

The XRP miropython git

Examples in order from XRP_MicroPython/Examples/drive_examples.py

straight motion:

def drive_straight(drive_time: float = 1): # default parameter with default of 1 second
    drivetrain.set_effort(0.8, 0.8) # sets same effort to both wheels to go straight
    time.sleep(drive_time)
    drivetrain.stop()

circular motion:

def arc_turn(turn_time: float = 1):
    drivetrain.set_effort(0.5, 0.8) # sets diff effort to both wheels for circular motion
    time.sleep(turn_time)
    drivetrain.stop()

turn:

def swing_turn(turn_time: float = 1):
    drivetrain.set_effort(0, 0.8) # sets effort to only wheel so the robot turns in one place
    time.sleep(turn_time)
    drivetrain.stop()

circle:

def circle():
    while True:
        drivetrain.set_effort(0.8, 1) # applies arc turn infinitely so it moves in a circle

square:

def square(sidelength):
    for sides in range(4): # iterates through loop 4 times
        drivetrain.straight(sidelength, 0.8) # draws one side
        drivetrain.turn(90) # turns 90 degrees
        
    # could also use polygon(sidelength, 4)

polygon

def polygon(side_length, number_of_sides): # basically math of any polyon 
    for s in range(number_of_sides):
        drivetrain.straight(side_length)
        drivetrain.turn(360/number_of_sides)

log of data from the ultrasonic sensor

def ultrasonic_test():
    while True:
        print(rangefinder.distance()) # continuously prints distance reported from sensor
        time.sleep(0.1)

drive till reaching wall

def drive_till_close(target_distance: float = 10.0):
    speed = 0.6
    while rangefinder.distance() > target_distance:
        drivetrain.set_effort(speed, speed) # just drives forward till target distance reached
        time.sleep(0.01)
    drivetrain.set_effort(0, 0)

maintain same distance from wall

def standoff(target_distance: float = 10.0):
    KP = 0.2
    while True:
        distance = rangefinder.distance() 
        error = distance - target_distance
        drivetrain.set_effort(error * KP, error*KP) # proportional control to adjust for error
        time.sleep(0.01)

https://github.com/micropython
https://github.com/Open-STEM/XRP_MicroPython