XRPLib.defaults¶
In addition to you being able to construct any of the classes in XRPLib by themselves, you are also able to import all of the default objects needed for normal robot operations, using just one line.
By running from XRPLib.defaults import *
, you import all of the
pre-constructed objects, as specified and named below:
1from .board import Board
2from .differential_drive import DifferentialDrive
3from .motor import Motor
4from .encoder import Encoder
5from .encoded_motor import EncodedMotor
6from .rangefinder import Rangefinder
7from .imu import IMU
8from .reflectance import Reflectance
9from .servo import Servo
10from .webserver import Webserver
11
12"""
13A simple file that constructs all of the default objects for the XRP robot
14Run "from XRPLib.defaults import *" to use
15"""
16
17left_motor = EncodedMotor.get_default_encoded_motor(index=1)
18right_motor = EncodedMotor.get_default_encoded_motor(index=2)
19imu = IMU.get_default_imu()
20drivetrain = DifferentialDrive.get_default_differential_drive()
21rangefinder = Rangefinder.get_default_rangefinder()
22reflectance = Reflectance.get_default_reflectance()
23servo_one = Servo.get_default_servo(index=1)
24servo_two = Servo.get_default_servo(index=2)
25webserver = Webserver.get_default_webserver()
26board = Board.get_default_board()
We use this import in most of the curriculum and example programs, which is why you will often see the DifferentialDrive class refered to as just “drivetrain”.
Here’s an example of that from drive_examples.py
:
>>> from XRPLib.defaults import *
>>> # Follow the perimeter of a square with variable sidelength
>>> def square(sidelength):
>>> for sides in range(4):
>>> drivetrain.straight(sidelength, 80)
>>> drivetrain.turn(90)``