This page contains the full API reference for the VEX Python SDK as provided by DishPy. All classes, functions, enums, and types are documented here.
vex
BRAKE = BrakeType.BRAKE
A brake unit that is defined as motor brake.
COAST = BrakeType.COAST
A brake unit that is defined as motor coast.
DEGREES = RotationUnits.DEG
A rotation unit that is measured in degrees.
DPS = VelocityUnits.DPS
A velocity unit that is measured in degrees per second.
FORWARD = DirectionType.FORWARD
A direction unit that is defined as forward.
HOLD = BrakeType.HOLD
A brake unit that is defined as motor hold.
INCHES = DistanceUnits.IN
A distance unit that is measured in inches.
LEFT = TurnType.LEFT
A turn unit that is defined as left turning.
MM = DistanceUnits.MM
A distance unit that is measured in millimeters.
MSEC = TimeUnits.MSEC
A time unit that is measured in milliseconds.
MV = VoltageUnits.MV
A voltage unit that is measured in millivolts.
PARTNER = ControllerType.PARTNER
A controller defined as a partner controller.
PERCENT = PercentUnits.PERCENT
A percentage unit that represents a value from 0% to 100%
PITCH = OrientationType.PITCH
pitch, orientation around the Y axis of the Inertial sensor.
PRIMARY = ControllerType.PRIMARY
A controller defined as a primary controller.
REVERSE = DirectionType.REVERSE
A direction unit that is defined as backward.
RIGHT = TurnType.LEFT
A turn unit that is defined as right turning.
ROLL = OrientationType.ROLL
roll, orientation around the X axis of the Inertial sensor.
RPM = VelocityUnits.RPM
A velocity unit that is measured in rotations per minute.
SECONDS = TimeUnits.SECONDS
A time unit that is measured in seconds.
TURNS = RotationUnits.REV
A rotation unit that is measured in revolutions.
VOLT = VoltageUnits.VOLT
A voltage unit that is measured in volts.
XAXIS = AxisType.XAXIS
The X axis of the Inertial sensor.
YAW = OrientationType.YAW
yaw, orientation around the Z axis of the Inertial sensor.
YAXIS = AxisType.YAXIS
The Y axis of the Inertial sensor.
ZAXIS = AxisType.ZAXIS
The Z axis of the Inertial sensor.
Accelerometer
For full functionality, three Accelerometer instances would need to be created, one for each axis.
port : The 3wire port to use for the accelerometer
sensitivity (optional) : set high sensitivity mode (+/- 2G), use True or 1
An instance of the Accelerometer class
accx = Accelerometer(brain.three_wire_port.a)\
accy = Accelerometer(brain.three_wire_port.b)\
accz = Accelerometer(brain.three_wire_port.c)
acceleration()
None
A value in the range +/- 6 or +/-2G if high sensitivity mode is set
# get accelerometer in range+/- 6G
value = accz.acceleration()
changed(callback, arg=())
callback : A function that will be called when the value of the accelerometer changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("accelerometer changed")
accz.changed(foo)
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get accelerometer in range 0 - 4095\
value = accz.value()
# get accelerometer in range 0 - 1023\
value = accz.value(AnalogUnits.TENBIT)
AddressableLed
port : The 3wire port to use for the addressable led strip
An instance of the AddressableLed class
addr1 = AddressableLed(brain.three_wire_port.a)
clear()
None
None
addr1.clear()
set(data, offset=0)
data : An list of Color values
offset (optional) : index of led to start at, 0 based
None
addr1 = AddressableLed(brain.three_wire_port.a)\
pix = [Color(0x800000),Color(0x008000),Color(0x000080)]\
addr1.set(pix)
AnalogIn
port : The 3wire port to use for the analog input
An instance of the AnalogIn class
ana1 = AnalogIn(brain.three_wire_port.a)
changed(callback, arg=())
callback : A function that will be called when the value of the analog input changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("analog input changed")
ana1.changed(foo)
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get analog input in range 0 - 4095\
value = ana1.value()
# get analog input in range 0 - 1023\
value = ana1.value(AnalogUnits.TENBIT)
AnalogUnits
The measurement units for analog values.
EIGHTBIT = AnalogUnits(0, '8BIT')
An analog unit that is measured in an 8-bit analog value (a value with 256 possible states).
MV = AnalogUnits(0, 'MV')
An analog unit that is measured in millivolts.
PCT = AnalogUnits(0, 'PCT')
An analog unit that is measured in percentage.
TENBIT = AnalogUnits(0, '10BIT')
An analog unit that is measured in an 10-bit analog value (a value with 1024 possible states).
TWELVEBIT = AnalogUnits(0, '12BIT')
An analog unit that is measured in an 12-bit analog value (a value with 4096 possible states).
AxisType
The defined units for inertial sensor axis.
XAXIS = AxisType(0, 'XAXIS')
The X axis of the Inertial sensor.
YAXIS = AxisType(1, 'YAXIS')
The Y axis of the Inertial sensor.
ZAXIS = AxisType(2, 'ZAXIS')
The Z axis of the Inertial sensor.
Brain
The Brain class creates a number of instances of internal classes that allow access\ to the screen, battery, 3wire ports and sd card on the V5 brain.
None
An instance of the Brain class
brain = Brain()
battery = Brain.Battery()
An instance of the Battery class
screen = Brain.Lcd()
An instance of the Lcd class
sdcard = Brain.Sdcard()
An instance of the Sdcard class
three_wire_port = Triport(Ports.PORT22)
An instance of the Triport (3wire) class
timer = Timer()
An instance of the Timer class
Battery
None
Instance of Battery class
capacity()
None
capacity as percentage
current(units=CurrentUnits.AMP)
units (optional) : AMP, default is mA but jot available as an enum.
current in supplied units
temperature(units=PercentUnits.PERCENT)
units (optional) : PERCENT, CELSIUS or FAHRENHEIT, default is CELSIUS
temperature in supplied units
voltage(units=VoltageUnits.MV)
units (optional) : VOLTS or MV, default is MV
voltage in supplied units
Lcd
A class used to access to screen on the V5 for drawing and receiving touch events.
None
An instance of the Brain.Lcd class
clear_row(number=None, color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
row (optional) : The row to clear, default is current cursor row
color (optional) : The color the screen will be set to, default is BLACK
None
# clear row to black\
brain.screen.clear_row()
# clear row 2 to red\
brain.screen.clear_row(2, Color.RED)
clear_screen(color=Color.BLACK)
The color can be passed in similar ways to the Color class.\
color (optional) : The color the screen will be set to, default is BLACK
None
# clear screen to black\
brain.screen.clear_screen()
# clear screen to blue using predefined color\
brain.screen.clear_screen(Color.BLUE)
column()
Return the current column where text will be printed
draw_circle(x, y, radius, color=None)
x : The x position of the circle center referenced to the screen origin.
y : The y position of the circle center referenced to the screen origin.
radius : The height of the circle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green circle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_circle(50, 50, 10)
# draw a green circle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_circle(100, 50, 10, Color.RED)
draw_image_from_file(filename, x, y)
filename : The file name of the image.
x : The X coordinate for the top left corner of the image on the screen
y : The Y coordinate for the top left corner of the image on the screen
True if successfully drawn, False on error
# draw the vex.bmp image on the screen at coordinate 0, 0\
# an image named vex.bmp must be on the SD Card in the root folder\
brain.screen.draw_image_from_file('vex.bmp', 0, 0)
draw_line(x1, y1, x2, y2)
x1 : The x position of the beginning of the line referenced to the screen origin.
y1 : The y position of the beginning of the line referenced to the screen origin.
x2 : The x position of the end of the line referenced to the screen origin.
y2 : The y position of the end of the line referenced to the screen origin.
None
# draw a red line on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_line(10, 10, 20, 20)
draw_pixel(x, y)
x : The x position to draw the pixel referenced to the screen origin.
y : The y position to draw the pixel referenced to the screen origin.
None
# draw a red pixel on the screen\
brain.screen.set_pen_color(Color.RED)\
brain.screen.draw_pixel(10, 10)
draw_rectangle(x, y, width, height, color=None)
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
color (optional) : An optional fill color, the current fill color will be used if not supplied
None
# draw a green rectangle on the screen that is filled using blue\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.set_fill_color(Color.BLUE)\
brain.screen.draw_rectangle(10, 10, 20, 20)
# draw a green rectangle on the screen that is filled using red\
brain.screen.set_pen_color(Color.GREEN)\
brain.screen.draw_rectangle(50, 50, 20, 20, Color.RED)
get_string_height(*args)
arguments are in the same format as can be passed to the print function.
height of string as integer.
get_string_width(*args)
arguments are in the same format as can be passed to the print function.
width of string as integer.
next_row()
None
None
pressed(callback, arg=())
callback : A function that will be called when the screen is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen pressed")
brain.screen.pressed(foo)
pressing()
None
True or False
print(*args, **kwargs)
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
None
# print the number 1 on the screen at current cursor position\
brain.screen.print(1)
# print the numbers 1, 2, 3 and 4 on the screen at current cursor position separated by a '-'\
brain.screen.print(1, 2, 3, 4, sep='-')
# print motor1 velocity on the screen using a format string\
brain.screen.print("motor 1 : % 7.2f" %(motor1.velocity()))
print_at(*args, **kwargs)
Required keyword arguments
x : The x position of the text referenced to the screen origin.
y : The y position of the text referenced to the screen origin.
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
opaque : text does not clear background pixels if set to False. default is True.
None
# print the number 1 on the screen at position x=100, y=40\
brain.screen.print_at(1, x=100, y=40)
# print the numbers 1, 2, 3 and 4 on the screen at position x=100, y=40\
brain.screen.print_at(1, 2, 3, 4, x=100, y=40)
# print motor1 velocity on the screen using a format string at position x=100, y=40\
brain.screen.print_at("motor 1 : % 7.2f" %(motor1.velocity()), x=100, y=40)
released(callback, arg=())
callback : A function that will be called when the screen is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("screen released")
brain.screen.released(foo)
render()
Once called, further drawing will not appear on the screen until the next time\ render is called. This function will block until the screen can be updated.
None
True if buffer was successfully rendered to screen.
row()
Return the current row where text will be printed
set_clip_region(x, y, width, height)
All drawing is clipped to the given rectangle.\ This is set on a per thread basis.
x : The x position of the rectangle top/left corner referenced to the screen origin.
y : The y position of the rectangle top/left corner referenced to the screen origin.
width : The width of the rectangle.
height : The height of the rectangle.
None
set_cursor(row, col)
row and column spacing will take into account the selected font.\ The base cell size if 10x20 pixels for the MONO20 font.\ text may not accurately print if using a proportional font.\ The top, left corner of the screen is position 1,1
row : The cursor row
col : The cursor column
None
set_fill_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The fill color
None
# set pen color red using a hex value\
brain.screen.set_fill_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_fill_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_fill_color("#00FF00")
set_font(fontname)
fontname : The font name
None
brain.screen.font_type(FontType.MONO40)
set_origin(x, y)
drawing functions consider the top left corner of the screen as the origin.\ This function can move the origin to an alternate position such as the center of the screen.
x : The origins x position relative to top left corner
y : The origins y position relative to top left corner
None
set_pen_color(color)
The color can be passed in similar ways to the Color class.\ The color is specific to the running thread.
color : The pen color
None
# set pen color red using a hex value\
brain.screen.set_pen_color(0xFF0000)
# set pen color blue using predefined color\
brain.screen.set_pen_color(Color.BLUE)
# set pen color green using web string\
brain.screen.set_pen_color("#00FF00")
set_pen_width(width)
width : The pen width
None
x_position()
None
The X coordinate as an int
def foo():
print("screen pressed at ", brain.screen.x_position())
brain.screen.pressed(foo)
y_position()
None
The Y coordinate as an int
def foo():
print("screen pressed at ", brain.screen.y_position())
brain.screen.pressed(foo)
Sdcard
None
Instance of Sdcard class
appendfile(filename, *args)
Append is used to add more data to an existing file.
filename : The name of the file to write
buffer : A bytearray to write into the file
The number of bytes written
# append bytearray into file\
brain.sdcard.appendfile('MyTextFile.txt', bytearray("World "))
exists(*args)
filename : The name of the file to check
True if file exists
filesize(filename)
filename : The name of the file to check
size of file in bytes
is_inserted()
None
True if an sdcard is inserted into the brain
loadfile(filename, *args)
filename : The name of the file to read
buffer (optional) : A bytearray to read the file into
A bytearray with file data
# read file into new bytearray\
b = brain.sdcard.loadfile('MyTextFile.txt')
savefile(filename, *args)
If the optional bytearray is None, then an empty file is created.
filename : The name of the file to write
buffer (optional) : A bytearray to write into the file
The number of bytes written
# write bytearray into file\
brain.sdcard.savefile('MyTextFile.txt', bytearray("Hello "))
size(filename)
filename : The name of the file to check
size of file in bytes
BrakeType
The defined units for motor brake values.
BRAKE = BrakeType(1, 'BRAKE')
A brake unit that is defined as motor brake.
COAST = BrakeType(0, 'COAST')
A brake unit that is defined as motor coast.
HOLD = BrakeType(2, 'HOLD')
A brake unit that is defined as motor hold.
Bumper
port : The 3wire port the bumper switch is connected to
An instance of the Bumper class
bumper1 = Bumper(brain.three_wire_port.a)
pressed(callback, arg=())
callback : A function that will be called when the bumper switch is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("switch pressed")
bumper1.pressed(foo)
pressing()
None
True or False
released(callback, arg=())
callback : A function that will be called when the bumper switch is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("switch released")
bumper1.released(foo)
value()
None
1 or 0
Code
A vision code is a collection of up to five vision signatures.
sig1 : A vision signature
sig2 : A vision signature
sig3 (optional) : A vision signature
sig4 (optional) : A vision signature
sig5 (optional) : A vision signature
An instance of the Signature class
SIG_1 = Signature(1, 6035, 7111, 6572, -1345, -475, -910, 3.000, 0)\
SIG_2 = Signature(2, 6035, 7111, 6572, -1345, -475, -910, 3.000, 0)\
C1 = Code(SIG_1, SIG_2)
id()
Not used, always returns 0
Color
This class is used to create instances of color objects
value : The color value, can be specified in various ways, see examples.
An instance of the Color class
# create blue using hex value\
c = Color(0x0000ff)
# create blue using r, g, b values\
c = Color(0, 0, 255)
# create blue using web string\
c = Color("#00F")
# create blue using web string (alternate)\
c = Color("#0000FF")
# create red using an existing object\
c = Color(Color.RED)
BLACK = DefinedColor(0)
predefined Color black
BLUE = DefinedColor(255)
predefined Color blue
CYAN = DefinedColor(65535)
predefined Color cyan
GREEN = DefinedColor(65280)
predefined Color green
ORANGE = DefinedColor(16753920)
predefined Color orange
PURPLE = DefinedColor(16711935)
predefined Color purple
RED = DefinedColor(16711680)
predefined Color red
TRANSPARENT = DefinedColor(0)
predefined Color transparent
WHITE = DefinedColor(16777215)
predefined Color white
YELLOW = DefinedColor(16776960)
predefined Color yellow
hsv(hue, saturation, value)
hue : The hue of the color
saturation : The saturation of the color
value : The brightness of the color
integer value representing the color
# create a color that is red
c.hsv( 0, 1.0, 1.0)
is_transparent()
None
True or False
rgb(*args)
value : The color value, can be specified in various ways, see examples.
integer value representing the color
# create a color that is red
c = Color(0xFF0000)
# change color to blue using single value
c.rgb(0x0000FF)
# change color to green using three values
c.rgb(0, 255, 0)
web(value)
value : The new color as a web string
integer value representing the color
# create a color that is red
c.web('#F00')
Competition
driver : A function called as a thread when the driver control period starts.
autonomous : A function called as a thread when the driver control period starts.
An instance of the Competition class
def driver():
print("driver called")
def auton():
print("auton called")
comp = Competition(driver, auton)
is_autonomous()
None
True if autonomous is enabled
is_competition_switch()
None
True if competition switch is connected
is_driver_control()
None
True if driver control is enabled
is_enabled()
None
True if the robot is enabled
is_field_control()
None
True if field controller is connected
Controller
None
An instance of the Controller class
axis1 = Controller.Axis()
The joystick axis 1 on the controller
axis2 = Controller.Axis()
The joystick axis 2 on the controller
axis3 = Controller.Axis()
The joystick axis 3 on the controller
axis4 = Controller.Axis()
The joystick axis 4 on the controller
buttonA = Controller.Button()
The A button on the controller
buttonB = Controller.Button()
The B button on the controller
buttonDown = Controller.Button()
The Down button on the controller
buttonL1 = Controller.Button()
The L1 button on the controller
buttonL2 = Controller.Button()
The L2 button on the controller
buttonLeft = Controller.Button()
The Left button on the controller
buttonR1 = Controller.Button()
The R1 button on the controller
buttonR2 = Controller.Button()
The R2 button on the controller
buttonRight = Controller.Button()
The Right button on the controller
buttonUp = Controller.Button()
The Up button on the controller
buttonX = Controller.Button()
The X button on the controller
buttonY = Controller.Button()
The Y button on the controller
screen = Controller.Lcd()
An instance of the Lcd class
Axis
None
An instance of an Axis class
changed(callback, arg=())
callback : A function that will be called when the axis value changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("axis changed")
controller.axis1.changed(foo)
position()
None
A value in the range +/- 100
a = controller.axis1.position()
value()
None
A value in the range +/- 127
a = controller.axis1.position()
Button
pressed(callback, arg=())
callback : A function that will be called when the button is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("button pressed")
controller.buttonL1.pressed(foo)
pressing()
None
True or False
released(callback, arg=())
callback : A function that will be called when the button is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("button released")
controller.buttonL1.released(foo)
Lcd
A class used to access the screen on the V5 controller.
None
An instance of the Brain.Lcd class
clear_row(number)
row (optional) : The row to clear, 1, 2, or 3, default is current cursor row
None
# clear row 2\
controller.screen.clear_row(2)
clear_screen()
None
None
controller.screen.clear_screen()
column()
Return the current column where text will be printed
next_row()
None
None
print(*args)
Optional keyword arguments:
sep : string inserted between values, default a space.
precision : the number of decimal places to display when printing simple numbers, default is 2
None
# print the number 1 on the screen at current cursor position\
controller.screen.print(1)
# print the numbers 1, 2, 3 and 4 on the screen at current cursor position separated by a '-'\
controller.screen.print(1, 2, 3, 4, sep='-')
# print motor1 velocity on the screen using a format string\
controller.screen.print("motor 1 : % 7.2f" %(motor1.velocity()))
row()
Return the current row where text will be printed
set_cursor(row, col)
V5 controller has at most 3 lines of text
row : The cursor row. 1, 2 or 3
col : The cursor column. The first column is 1.
None
rumble(pattern)
pattern : A pattern using '.' and '-' for short and long rumbles.
None
controller.rumble('..--')
ControllerType
The defined types for controller devices.
PARTNER = ControllerType(1, 'PARTNER')
A controller defined as a partner controller.
PRIMARY = ControllerType(0, 'PRIMARY')
A controller defined as a primary controller.
CurrentUnits
The measurement units for current values.
AMP = CurrentUnits(0, 'AMP')
A current unit that is measured in amps.
DigitalIn
port : The 3wire port to use for the digital input
An instance of the DigitalIn class
dig1 = DigitalIn(brain.three_wire_port.a)
high(callback, arg=())
callback : A function that will be called when the digital input goes to the logic high state
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("input high")
dig1.high(foo)
low(callback, arg=())
callback : A function that will be called when the digital input goes to the logic low state
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("input low")
dig1.low(foo)
value()
None
1 or 0
DigitalOut
port : The 3wire port to use for the digital output
An instance of the DigitalOut class
dig1 = DigitalOut(brain.three_wire_port.a)
set(value)
value : 0, 1, True or False
None
dig1.set(True)
value()
None
1 or 0
DirectionType
The defined units for direction values.
FORWARD = DirectionType(0, 'FORWARD')
A direction unit that is defined as forward.
REVERSE = DirectionType(1, 'REVERSE')
A direction unit that is defined as backward.
UNDEFINED = DirectionType(2, 'UNDEFINED')
A direction unit used when direction is not known.
Distance
port : The smartport this device is attached to
An instance of the Distance class
dist1 = Distance(Ports.PORT1)
changed(callback, arg=())
callback : A function that will be called when the distance value changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("distance changed")
dist1.changed(foo)
installed()
None
True or False
is_object_detected()
None
True or False
object_distance(units=DistanceUnits.MM)
The distance will return a large positive number if no object is detected.
units (optional): The distance units to return the distance value in. default is MM.
A value for distance in the specified units.
# get distance in mm\
value = dist1.object_distance()
# get distance in inches\
value = dist1.object_distance(INCHES)
object_rawsize()
Raw size will be a number ranging from 0 to about 400\ Larger and more reflective objects will return larger values.
None
A value for object size that is a number.\
# get object raw size\
size = dist1.object_rawsize()
object_size()
None
A value for object size.\
The value will be of type ObjectSizeType
# get object size\
size = dist1.object_size()
object_velocity()
velocity is calculated from change of distance over time
None
The velocity in m/s
timestamp()
None
timestamp of the last status packet in mS
DistanceUnits
The measurement units for distance values.
CM = DistanceUnits(2, 'CM')
A distance unit that is measured in centimeters.
IN = DistanceUnits(1, 'IN')
A distance unit that is measured in inches.
MM = DistanceUnits(0, 'MM')
A distance unit that is measured in millimeters.
DriveTrain
lm : Left motor or motorgroup
rm : Right motor or motorgroup
wheelTravel (optional) : The circumference of the driven wheels, default is 300 mm
trackWidth (optional) : The trackwidth of the drivetrain, default is 320 mm
wheelBase (optional) : The wheelBase of the drivetrain, default is 320 mm
units (optional) : The units that wheelTravel, trackWidth and wheelBase are specified in, default is MM.
externalGearRatio (optional) : An optional gear ratio used to compensate drive distances if gearing is used.
A new DriveTrain object.
# A simple two motor drivetrain using default values\
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2, True)\
drive1 = DriveTrain(motor1, motor2)
# A four motor drivetrain using custom values\
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2)\
motor3 = Motor(Ports.PORT3, True)\
motor4 = Motor(Ports.PORT4, True)\
mgl = MotorGroup(motor1, motor3)\
mgr = MotorGroup(motor2, motor4)\
drive1 = DriveTrain(mgl, mgr, 8.6, 10, 12, INCHES)
current(units=CurrentUnits.AMP)
units (optional) : The units for the returned current, the default is AMP
The drivetrain current in provided units
drive(direction, velocity=None, units=VelocityUnits.RPM)
The drive command is similar to the motor spin command.\ all drive motors are commanded using the provided parameters.
direction : The direction to drive, FORWARD or REVERSE
velocity (optional) : spin the motors using this velocity, the default velocity set by set_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# drive forward at velocity set with set_velocity\
drive1.drive(FORWARD)
# drive forward at 50 rpm\
drive1.drive(FORWARD, 50)
# drive with negative velocity, ie. backwards\
drive1.drive(FORWARD, -20)
# drive forwards with 100% velocity\
drive1.drive(FORWARD, 100, PERCENT)
# drive forwards at 50 rpm\
drive1.drive(FORWARD, 50, RPM)
# drive forwards at 360 dps\
drive1.drive(FORWARD, 360.0, VelocityUnits.DPS)
drive_for(direction, distance, units=DistanceUnits.IN, velocity=None, units_v=VelocityUnits.RPM, wait=True)
The drive_for command is similar to the motor spin_for command,\ however, the drivetrain is commanded to move a distance.
direction : The direction to drive
distance : The distance to drive
units (optional) : The units for the provided distance, the default is INCHES
velocity (optional) : drive using this velocity, the default velocity set by set_drive_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None or if wait is True then completion success or failure
# drive forward 10 inches from the current position\
drive1.drive_for(FORWARD, 10, INCHES)
# drive reverse 1000mm from the current position with motors at 50 rpm\
drive1.drive_for(REVERSE, 10000, MM, 50, RPM)
efficiency(units=PercentUnits.PERCENT)
This command only considers the first motor for left and right sides of the drive.
units (optional) : The units for the efficiency, the only valid value is PERCENT
The motor efficiency in percent
get_timeout()
None
Timeout value in mS
is_done()
This function is used when False has been passed as the wait parameter to drive_for or turn_for\ It will return False if the drivetrain is still moving or True if it has completed the move or a timeout occurred.
None
The current drive_for or turn_for status
is_moving()
This function is used when False has been passed as the wait parameter to drive_for or turn_for\ It will return True if the drivetrain is still moving or False if it has completed the move or a timeout occurred.
None
The current drive_for or turn_for status
power(units=PowerUnits.WATT)
This command only considers the first motor for left and right sides of the drive.
units (optional) : The units for the returned power, the default is WATT
The drivetrain power in provided units
set_drive_velocity(velocity, units=VelocityUnits.RPM)
This will be the velocity used for subsequent calls to drive if a velocity is not provided to that function.
velocity : The new velocity
units : The units for the supplied velocity, the default is RPM
None
set_stopping(mode=BrakeType.COAST)
Setting the action for the motors when stopped.
mode : The stopping mode, COAST, BRAKE or HOLD
None
set_timeout(timeout, units=TimeUnits.MSEC)
The timeout value is used when performing drive_for and turn_for commands. If timeout is reached and the motor has not completed moving, then the function will return False.
timeout : The new timeout
units : The units for the provided timeout, the default is MSEC
None
set_turn_velocity(velocity, units=VelocityUnits.RPM)
This will be the velocity used for subsequent calls to turn if a velocity is not provided to that function.
velocity : The new velocity
units : The units for the supplied velocity, the default is RPM
None
stop(mode=None)
The motors will be stopped and set to COAST, BRAKE or HOLD
None
None
temperature(units=TemperatureUnits.CELSIUS)
This command only considers the first motor for left and right sides of the drive.
units (optional) : The units for the returned temperature, the default is CELSIUS
The motor temperature in provided units
torque(units=TorqueUnits.NM)
This command only considers the first motor for left and right sides of the drive.
units (optional) : The units for the returned torque, the default is NM
The motor torque in provided units
turn(direction, velocity=None, units=VelocityUnits.RPM)
The drive command is similar to the motor spin command.\ all drive motors are commanded using the provided parameters.
direction : The turn direction, LEFT or RIGHT
velocity (optional) : spin the motors using this velocity, the default velocity set by set_turn_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# turn left at velocity set with set_turn_velocity\
drive1.turn(LEFT)
# drive right at 50 rpm\
drive1.turn(RIGHT, 50)
# turn right with 100% velocity\
drive1.turn(RIGHT, 100, PERCENT)
# turn right at 50 rpm\
drive1.turn(RIGHT, 50, RPM)
# turn right at 360 dps\
drive1.turn(RIGHT, 360.0, VelocityUnits.DPS)
turn_for(direction, angle, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
The turn_for command is similar to the motor spin_for command,\ however, the drivetrain is commanded to turn a specified angle.
direction : The direction to turn, LEFT or RIGHT
angle : The angle to turn
units (optional) : The units for the provided angle, the default is DEGREES
velocity (optional) : drive using this velocity, the default velocity set by set_drive_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None or if wait is True then completion success or failure
# turn right 90 degrees\
drive1.turn_for(RIGHT, 90, DEGREES)
# turn left 180 degrees with motors at 50 rpm\
drive1.turn_for(LEFT, 180, DEGREES, 50, RPM)
velocity(units=VelocityUnits.RPM)
units (optional) : The units for the returned velocity, the default is RPM
The drivetrain velocity in provided units
Electromagnet
port : The smartport this device is attached to
An instance of the Electromagnet class
em1 = Electromagnet(Ports.PORT1)
drop(duration=1000, units=MSEC, power=50)
duration (optional) : the duration to energize the magnet for, default is 1 second
units (optional) : the units for duration, default is MSEC
power (optional) : the power used when energizing.
None
# drop with default values\
em1.drop()
# drop with custom values\
em1.drop(250, MSEC, 90)
installed()
None
True or False
pickup(duration=1000, units=MSEC, power=50)
duration (optional) : the duration to energize the magnet for, default is 1 second
units (optional) : the units for duration, default is MSEC
power (optional) : the power used when energizing.
None
# pickup with default values\
em1.pickup()
# pickup with custom values\
em1.pickup(250, MSEC, 90)
set_power(value)
value : power in range 0 to 100
None
# set default power to 80\
em1.set_power(80)
temperature(*args)
units (optional) : The units for the returned temperature, the default is CELSIUS
The electromagnet temperature in provided units
timestamp()
None
timestamp of the last status packet in mS
Encoder
An encoder uses two adjacent 3wire ports.\ valid port pairs are a/b, c/d, e/f and g/h
port : The 3wire port to use for the encoder sensor
An instance of the Encoder class
enc1 = Encoder(brain.three_wire_port.a)
position(units=RotationUnits.DEG)
units (optional) : The rotation units to return the position value in, default is DEGREES.
A value for encoder position in the specified units.
# get encoder position\
value = enc1.position()
reset_position()
None
None
set_position(value, units=RotationUnits.DEG)
value : The new value to use for position.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of position to 180 degrees\
enc1.set_position(180)
value()
One full turn of the encoder is 360 counts.
None
A value for encoder counts.
# get encoder raw counts\
value = enc1.value()
velocity(units=VelocityUnits.RPM)
units (optional) : The velocity units to return the value in, default is RPM.
A value for encoder velocity in the specified units.
# get encoder velocity in rpm\
value = enc1.velocity()
Event
A function is registered that will be called when the event broadcast() function is called. More than one function can be assigned to a single event.
callback (optional) : A function that will be called when the event is broadcast.
arg (optional) : A tuple that is used to pass arguments to the event callback function.
An instance of the Event class
def foo():
print("foo")
def bar():
print("bar")
e = Event(foo)\
e.set(bar)
# There needs to be some small delay after events are created before they can be broadcast to\
sleep(20)
# cause both foo and bar to be called\
e.broadcast()
__call__(callback, arg=())
callback : A function that will be called when the event is broadcast.
arg (optional) : A tuple that is used to pass arguments to the event callback function.
None
def bar():
print("bar")
# add callback function to existing event e\
e(bar)
broadcast()
None
None
# broadcast to an existing event e\
e.broadcast()
broadcast_and_wait(timeout=60000)
This is similar to broadcast except that it will wait for all registered callbacks to complete before returning.
None
None
# broadcast to an existing event e, wait for completion\
e.broadcast_and_wait()
set(callback, arg=())
callback : A function that will be called when the event is broadcast.
arg (optional) : A tuple that is used to pass arguments to the event callback function.
None
def bar():
print("bar")
# add callback function to existing event e\
e.set(bar)
FontType
A unit representing font type and size
CJK16 = FontType(10, 'CJK16')
Chinese/Japanese/Korean font of size 16
MONO12 = FontType(9, 'MONO12')
proportional font of size 12
MONO15 = FontType(8, 'MONO15')
proportional font of size 15
MONO20 = FontType(0, 'MONO20')
monotype font of size 20
MONO30 = FontType(1, 'MONO30')
monotype font of size 30
MONO40 = FontType(2, 'MONO40')
monotype font of size 40
MONO60 = FontType(3, 'MONO60')
monotype font of size 60
PROP20 = FontType(4, 'PROP20')
proportional font of size 20
PROP30 = FontType(5, 'PROP30')
proportional font of size 30
PROP40 = FontType(6, 'PROP40')
proportional font of size 40
PROP60 = FontType(7, 'PROP60')
proportional font of size 60
GearSetting
The defined units for gear values.
RATIO_18_1 = GearSetting(1, 'RATIO18_1')
A gear unit that is defined as the green 18:1 gear cartridge used in V5 Smart Motors.
RATIO_36_1 = GearSetting(0, 'RATIO36_1')
A gear unit that is defined as the red 36:1 gear cartridge used in V5 Smart Motors.
RATIO_6_1 = GearSetting(2, 'RATIO6_1')
A gear unit that is defined as the blue 6:1 gear cartridge used in V5 Smart Motors.
GestureType
The defined units for optical sensor gesture types.
Gps
port : The smartport this device is attached to
origin_x (optional) : The X location of the GPS with respect to origin of the robot.
origin_y (optional) : The Y location of the GPS with respect to origin of the robot.\
note. both X and Y must be supplied
units (optional) : The units that X and Y location are specified in, default is MM
An instance of the Gps class
gps1 = Gps(Ports.PORT1)
acceleration(axis)
axis : The axis to read
A value for the acceleration of the axis in units of gravity.
# get the acceleration for the Z axis of the gps\
zaccel = gps1.acceleration(ZAXIS)
calibrate()
not used on the GPS sensor
changed(callback, arg=())
This is not particularly useful as gps heading is not stable and will cause many events.
callback : A function that will be called when the value of the gps heading changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("heading changed")
gps1.changed(foo)
get_turn_type()
An advanced function that is not generally used.
None
The current TurnType, LEFT or RIGHT
gyro_rate(axis, units=VelocityUnits.DPS)
axis : The axis to read
units (optional) : The units to return the gyro rate in, default is DPS
A value for the gyro rate of the axis in the units specified.
# get the gyro rate for the Z axis of the gps\
zrate = gps1.gyro_rate(ZAXIS)
heading(units=RotationUnits.DEG)
heading will be returned in the range 0 - 359.99 degrees
units (optional) : The units to return the heading in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current heading for the gps\
value = gps1.heading()
installed(*args)
None
True or False
is_calibrating()
not used on the GPS sensor
orientation(axis, units=RotationUnits.DEG)
axis : The axis to read
units (optional) : The units to return the orientation in, default is DEGREES
A value for the axis orientation in the units specified.
# get the pitch value for the gps\
pitch = gps1.orientation(OrientationType.PITCH)
quality()
A quality of 100 indicates the gps can see the gps field strip and is returning good readings\ The value for quality will reduce as the confidence in x and y location lowers.
None
A value of quality in the range 0 to 100
# get the current location and heading quality for the gps\
q = gps1.quality()
reset_heading()
None
None
reset_rotation()
None
None
rotation(units=RotationUnits.DEG)
rotation is not limited, it can be both positive and negative and shows the absolute angle of the gps.
units (optional) : The units to return the rotation in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current rotation for the gps\
value = gps1.rotation()
set_heading(value, units=RotationUnits.DEG)
The new value for heading should be in the range 0 - 359.99 degrees.
value : The new value to use for heading.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of heading to 180 degrees\
gps1.set_heading(180)
set_location(x, y, units=DistanceUnits.MM, angle=0, units_r=RotationUnits.DEG)
This gives a hint as to the location of the robot/gps sensor when it is first initialized.\ This can be used if in the initial position the gps cannot see the gps field strip.
x : The initial X coordinate.
y : The initial Y coordinate.\
note. both X and Y must be supplied
units (optional) : The units that X and Y coordinates are specified in, default is MM
angle (optional) : The initial heading of the robot.
units_r (optional) : The units that angle is specified in, default is DEGREES
None
# set the initial location of the gps\
gps1.set_location(1000, -1000, MM, 90, DEGREES)
set_origin(x=0, y=0, units=DistanceUnits.MM)
An alternate way of setting sensor origin if not provided in the Gps class constructor.
x : The X location of the GPS with respect to origin of the robot.
y : The Y location of the GPS with respect to origin of the robot.\
note. both X and Y must be supplied
units (optional) : The units that X and Y location are specified in, default is MM
None
# set the origin of the gps\
gps1.set_origin(6, -6, INCHES)
set_rotation(value, units=RotationUnits.DEG)
value : The new value to use for rotation.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of rotation to 180 degrees\
gps1.set_rotation(180)
set_sensor_rotation(value, units=RotationUnits.DEG)
This allows heading and rotation methods to return angles relative to the robot rather than the gps.
value : The angle of the GPS with respect to the robot.
units (optional) : The units that value is specified in, default is DEGREES
None
# set the sensor rotation of the gps\
gps1.set_sensor_rotation(180, DEGREES)
set_turn_type(turntype)
An advanced function that is not generally used.
turntype : TurnType.LEFT or TurnType.RIGHT
None
timestamp()
None
timestamp of the last status packet in mS
x_position(units=DistanceUnits.MM)
units (optional) : The units to return the position in, default is MM
A value for the x coordinate in the units specified.
# get the current x coordinate for the gps\
posx = gps1.x_position()
y_position(units=DistanceUnits.MM)
units (optional) : The units to return the position in, default is MM
A value for the y coordinate in the units specified.
# get the current y coordinate for the gps\
posy = gps1.y_position()
Gyro
port : The 3wire port to use for the gyro sensor
An instance of the Gyro class
gyro1 = Gyro(brain.three_wire_port.a)
calibrate()
Calibration should done when the gyro is not moving.
None
None
# start calibration\
gyro1.calibrate()\
# wait for completion\
while gyro1.is_calibrating():\
sleep(50, MSEC)
changed(callback, arg=())
callback : A function that will be called when the value of the gyro heading changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("gyro changed")
gyro1.changed(foo)
get_turn_type()
An advanced function that is not generally used.
None
The current TurnType, LEFT or RIGHT
heading(units=RotationUnits.DEG)
heading will be returned in the range 0 - 359.99 degrees
units (optional) : The units to return the heading in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current heading for the gyro\
value = gyro1.heading()
is_calibrating()
Calibration should done when the gyro is not moving.
None
True when the gyro is calibrating
# start calibration\
gyro1.calibrate()\
# wait for completion\
while gyro1.is_calibrating():\
sleep(50, MSEC)
reset_heading()
None
None
reset_rotation()
None
None
rotation(units=RotationUnits.DEG)
rotation is not limited, it can be both positive and negative and shows the absolute angle of the gyro.
units (optional) : The units to return the rotation in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current rotation for the gyro\
value = gyro1.rotation()
set_heading(value, units=RotationUnits.DEG)
The new value for heading should be in the range 0 - 359.99 degrees.
value : The new value to use for heading.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of heading to 180 degrees\
gyro1.set_heading(180)
set_rotation(value, units=RotationUnits.DEG)
value : The new value to use for rotation.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of rotation to 180 degrees\
gyro1.set_rotation(180)
set_turn_type(turntype)
An advanced function that is not generally used.
turntype : TurnType.LEFT or TurnType.RIGHT
None
value(units=DEGREES)
This method is generally not used, see heading() and rotation()
units (optional) : A valid RotationUnits type or PERCENT, the default is DEGREES
A value in the range that is specified by the units.
# get gyro value in range 0 - 360 degrees\
value = gyro1.value()
Inertial
port : The smartport this device is attached to
An instance of the Inertial class
imu1 = Inertial(Ports.PORT1)
acceleration(axis)
axis : The axis to read
A value for the acceleration of the axis in units of gravity.
# get the acceleration for the Z axis of the inertial sensor\
zaccel = imu1.acceleration(ZAXIS)
calibrate()
Calibration should done when the inertial sensor is not moving.
None
None
# start calibration\
imu1.calibrate()\
# wait for completion\
while imu1.is_calibrating():\
sleep(50, MSEC)
changed(callback, arg=())
callback : A function that will be called when the value of the inertial sensor heading changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("heading changed")
imu1.changed(foo)
collision(callback, arg=())
callback : A function that will be called when the inertial sensor detects a collision
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("collision")
imu1.collision(foo)
get_turn_type()
An advanced function that is not generally used.
None
The current TurnType, LEFT or RIGHT
gyro_rate(axis, units=VelocityUnits.DPS)
axis : The axis to read
units (optional) : The units to return the gyro rate in, default is DPS
A value for the gyro rate of the axis in the units specified.
# get the gyro rate for the Z axis of the inertial sensor\
zrate = imu1.gyro_rate(ZAXIS)
heading(units=RotationUnits.DEG)
heading will be returned in the range 0 - 359.99 degrees
units (optional) : The units to return the heading in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current heading for the inertial sensor\
value = imu1.heading()
installed(*args)
None
True or False
is_calibrating()
Calibration should done when the inertial sensor is not moving.
None
True when the inertial sensor is calibrating
# start calibration\
imu1.calibrate()\
# wait for completion\
while imu1.is_calibrating():\
sleep(50, MSEC)
orientation(axis, units=RotationUnits.DEG)
axis : The axis to read
units (optional) : The units to return the orientation in, default is DEGREES
A value for the axis orientation in the units specified.
# get the pitch value for the inertial sensor\
pitch = imu1.orientation(OrientationType.PITCH)
reset_heading()
None
None
reset_rotation()
None
None
rotation(units=RotationUnits.DEG)
rotation is not limited, it can be both positive and negative and shows the absolute angle of the gps.
units (optional) : The units to return the rotation in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current rotation for the inertial sensor\
value = imu1.rotation()
set_heading(value, units=RotationUnits.DEG)
The new value for heading should be in the range 0 - 359.99 degrees.
value : The new value to use for heading.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of heading to 180 degrees\
imu1.set_heading(180)
set_rotation(value, units=RotationUnits.DEG)
value : The new value to use for rotation.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of rotation to 180 degrees\
imu1.set_rotation(180)
set_turn_type(turntype)
An advanced function that is not generally used.
turntype : TurnType.LEFT or TurnType.RIGHT
None
timestamp()
None
timestamp of the last status packet in mS
Led
port : The 3wire port to use for the led
An instance of the Led class
led1 = Led(brain.three_wire_port.a)
off()
None
None
led1.off()
on()
None
None
led1.on()
value()
None
1 or 0
LedStateType
The defined units for optical sensor led state.
Light
port : The 3wire port to use for the light sensor
An instance of the Light class
light1 = Light(brain.three_wire_port.a)
brightness(units=PercentUnits.PERCENT)
The brightness of the light sensor is an estimation based on the raw value of the sensor.\ A brightness of 0% is a raw value of approximated 900 or greater\ A brightness of 100% is a raw value of 0
units (optional) : The only valid value is PERCENT
A value in the range 0 to 100%
# get light sensor brightness in range of 0 -100%\
value = light1.brightness()
changed(callback, arg=())
callback : A function that will be called when the value of the light sensor changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("light sensor changed")
light1.changed(foo)
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get light sensor in range 0 - 4095\
value = light1.value()
# get light sensor in range 0 - 1023\
value = light1.value(AnalogUnits.TENBIT)
Limit
port : The 3wire port the limit switch is connected to
An instance of the Limit class
limit1 = Limit(brain.three_wire_port.a)
pressed(callback, arg=())
callback : A function that will be called when the limit switch is pressed
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("switch pressed")
limit1.pressed(foo)
pressing()
None
True or False
released(callback, arg=())
callback : A function that will be called when the limit switch is released
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("switch released")
limit1.released(foo)
value()
None
1 or 0
Line
port : The 3wire port to use for the line sensor
An instance of the Line class
line1 = Line(brain.three_wire_port.a)
changed(callback, arg=())
callback : A function that will be called when the value of the line sensor changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("line sensor changed")
line1.changed(foo)
reflectivity(units=PercentUnits.PERCENT)
The reflectivity of the line sensor is an estimation based on the raw value of the sensor.\ A reflectivity of 0% is a raw value of approximated 3000 or greater\ A reflectivity of 100% is a raw value of 0
units (optional) : The only valid value is PERCENT
A value in the range 0 to 100%
# get line sensor reflectivity in range of 0 -100%\
value = line1.reflectivity()
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get line sensor in range 0 - 4095\
value = line1.value()
# get line sensor in range 0 - 1023\
value = line1.value(AnalogUnits.TENBIT)
MessageLink
port : The smartport the VEXlink radio is attached to
name : The name of this link
linktype : The type of this link, either VexlinkType.MANAGER or VexlinkType.WORKER
wired (optional) : Set to True if this is a wired link
An instance of the MessageLink class
link = MessageLink(Ports.PORT1, 'james', VexlinkType.MANAGER)
installed()
None
True or False
is_linked()
None
True if the link is active and connected to the paired brain.
receive(timeout=300000)
timeout (optional) : An optional timeout value in mS before the function returns.
None or received message
message = link.receive()
received(*args)
If the message is omitted then the callback will be called for all messages.
message (optional) : A message name for which the callback will be called
callback : A function that will be called when a message is received
None
def cb(message, link, index, value):
print(link, message, index, value)
link.received('test', cb)
send(message, *args)
message : A string, the message to send
index (optional) : A int such as port number
value (optional) : A float
length of transmitted data or None on error
# send the message 'test' with no parameters\
link.send('test')
# send the message 'test' with parameters\
link.send('test', 1, 3.14)
Motor
port : The smartport this device is attached to
gears (optional) : The gear cartridge installed in the motor, default is the green 18_1
reverse (optional) : Should the motor's spin direction be reversed, default is False
A new Motor object.
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2, GearSetting.RATIO_36_1)\
motor3 = Motor(Ports.PORT3, True)\
motor4 = Motor(Ports.PORT4, GearSetting.RATIO_6_1, True)
command(*args)
units (optional) : The units for the returned velocity, the default is RPM
The motor command velocity in provided units
current(*args)
units (optional) : The units for the returned current, the default is AMP
The motor current in provided units
direction()
None
The spin direction, FORWARD, REVERSE or UNDEFINED
efficiency(*args)
units (optional) : The units for the efficiency, the only valid value is PERCENT
The motor efficiency in percent
get_timeout()
None
The current timeout value
installed()
None
True or False
is_done()
This function is used when False has been passed as the wait parameter to spin_to_position or spin_for\ It will return False if the motor is still spinning or True if it has completed the move or a timeout occurred.
None
The current spin_to_position or spin_for status
is_spinning()
This function is used when False has been passed as the wait parameter to spin_to_position or spin_for\ It will return True if the motor is still spinning or False if it has completed the move or a timeout occurred.
None
The current spin_to_position or spin_for status
position(*args)
units (optional) : The units for the returned position, the default is DEGREES
The motor position in provided units
power(*args)
units (optional) : The units for the returned power, the default is WATT
The motor power in provided units
reset_position()
None
None
set_max_torque(value, units)
The torque can be set as torque, current or percent of maximum.
value : the new maximum torque to use
units : the units that value is passed in
None
# set maximum torque to 2 Nm\
motor1.set_max_torque(2, TorqueUnits.NM)
# set maximum torque to 1 Amp\
motor1.set_max_torque(1, CurrentUnits.AMP)
# set maximum torque to 20 percent\
motor1.set_max_torque(20, PERCENT)
set_position(value, units=RotationUnits.DEG)
The position returned by the position() function is set to this value.
value : The new position
units : The units for the provided position, the default is DEGREES
None
set_reversed(value)
Setting the reverse flag will cause spin commands to run the motor in reverse.
value : Reverse flag, True or False
None
set_stopping(value)
Setting the action for the motor when stopped.
value : The stopping mode, COAST, BRAKE or HOLD
None
set_timeout(value, units=TimeUnits.MSEC)
The timeout value is used when performing spin_to_position and spin_for commands. If timeout is reached and the motor has not completed moving, then the spin... function will return False.
value : The new timeout
units : The units for the provided timeout, the default is MSEC
None
set_velocity(value, units=VelocityUnits.RPM)
This will be the velocity used for subsequent calls to spin if a velocity is not provided to that function.
value : The new velocity
units : The units for the supplied velocity, the default is RPM
None
spin(direction, *args, **kwargs)
direction : The direction to spin the motor, FORWARD or REVERSE
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# spin motor forward at velocity set with set_velocity\
motor1.spin(FORWARD)
# spin motor forward at 50 rpm\
motor1.spin(FORWARD, 50)
# spin with negative velocity, ie. backwards\
motor1.spin(FORWARD, -20)
# spin motor forwards with 100% velocity\
motor1.spin(FORWARD, 100, PERCENT)
# spin motor forwards at 50 rpm\
motor1.spin(FORWARD, 50, RPM)
# spin motor forwards at 360 dps\
motor1.spin(FORWARD, 360.0, VelocityUnits.DPS)
spin_for(direction, rot_or_time, *args, **kwargs)
Move the motor to the requested position or for the specified amount of time.\ The position is relative (ie. an offset) to the current position\ This function supports keyword arguments.
dir : The direction to spin the motor, FORWARD or REVERSE
rot_or_time : The relative position to spin the motor to or tha amount of time to spin for
units (optional) : The units for the provided position or time, the default is DEGREES or MSEC
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# spin 180 degrees from the current position\
motor1.spin_for(FORWARD, 180)
# spin reverse 2 TURNS (revolutions) from the current position\
motor1.spin_for(REVERSE, 2, TURNS)
# spin 180 degrees from the current position at 25 rpm\
motor1.spin_for(FORWARD, 180, DEGREES, 25, RPM)
# spin 180 degrees from the current position and do not wait for completion\
motor1.spin_for(FORWARD, 180, DEGREES, False)
# spin 180 degrees from the current position and do not wait for completion\
motor1.spin_for(FORWARD, 180, DEGREES, wait=False)
spin_to_position(rotation, *args, **kwargs)
Move the motor to the requested position.\ This function supports keyword arguments.
rotation : The position to spin the motor to
units (optional) : The units for the provided position, the default is DEGREES
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# spin to 180 degrees\
motor1.spin_to_position(180)
# spin to 2 TURNS (revolutions)\
motor1.spin_to_position(2, TURNS)
# spin to 180 degrees at 25 rpm\
motor1.spin_to_position(180, DEGREES, 25, RPM)
# spin to 180 degrees and do not wait for completion\
motor1.spin_to_position(180, DEGREES, False)
# spin to 180 degrees and do not wait for completion\
motor1.spin_to_position(180, DEGREES, wait=False)
stop(mode=None)
The motor will be stopped and set to COAST, BRAKE or HOLD
None
None
temperature(*args)
units (optional) : The units for the returned temperature, the default is CELSIUS
The motor temperature in provided units
timestamp()
None
timestamp of the last status packet in mS
torque(*args)
units (optional) : The units for the returned torque, the default is NM
The motor torque in provided units
velocity(*args)
units (optional) : The units for the returned velocity, the default is RPM
The motor velocity in provided units
Motor29
The Motor29 class will create raw RC style pwm waveform.\ This is primarily for use with the VEX MC29 motor controller\ To minimize current draw, new values sent to the motor will have slew rate control applied
port : The 3wire port to use for the motor controller
reverse_flag (optional) : set reverse flag for this motor, spin commands will cause opposite rotation if set True. default is False.
An instance of the Motor29 class
motor1 = Motor29(brain.three_wire_port.a)
set_reversed(value)
value : 1, 0, True or False
None
# set motor reversed flag True\
motor1.set_reversed(True)
set_velocity(value, units=VelocityUnits.RPM)
This will be the velocity used for subsequent calls to spin of a velocity is not provided to that function.
value : The new velocity
units : The units for the supplied velocity, the default is RPM
None
spin(direction, velocity=None, units=None)
The motor is assumed to have a maximum velocity of 100 rpm.
direction : The direction to spin the motor, FORWARD or REVERSE
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# spin motor forward at velocity set with set_velocity\
motor1.spin(FORWARD)
# spin motor forward at 50 rpm\
motor1.spin(FORWARD, 50)
# spin with negative velocity, ie. backwards\
motor1.spin(FORWARD, -20)
# spin motor forwards with 100% velocity\
motor1.spin(FORWARD, 100, PERCENT)
# spin motor forwards at 50 rpm\
motor1.spin(FORWARD, 50, RPM)
# spin motor forwards at 360 dps\
motor1.spin(FORWARD, 360.0, VelocityUnits.DPS)
stop()
None
None
value()
This is the raw internal pwm value\ A motor velocity of 0 will return 127\ A maximum positive motor velocity will return 255
None
A value in the range 0 to 255.
# get motor current pwm value\
value = motor1.value()
MotorGroup
One or more Motor class instances
A new MotorGroup object.
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2)\
mg1 = MotorGroup(motor1, motor2)
count()
None
The number of motors in the group
current(units=CurrentUnits.AMP)
units (optional) : The units for the returned current, the default is AMP
The motor current in provided units
direction()
None
The spin direction, FORWARD, REVERSE or UNDEFINED
efficiency(units=PercentUnits.PERCENT)
units (optional) : The units for the efficiency, the only valid value is PERCENT
The motor efficiency in percent
is_done()
This function is used when False has been passed as the wait parameter to spin_to_position or spin_for\ It will return False if any motor is still spinning or True if they have completed the move or a timeout occurred.
None
The current spin_to_position or spin_for status
is_spinning()
This function is used when False has been passed as the wait parameter to spin_to_position or spin_for\ It will return True if any motor is still spinning or False if they have completed the move or a timeout occurred.
None
The current spin_to_position or spin_for status
position(units=RotationUnits.DEG)
units (optional) : The units for the returned position, the default is DEGREES
The motor position in provided units
power(units=PowerUnits.WATT)
units (optional) : The units for the returned power, the default is WATT
The motor power in provided units
reset_position()
None
None
set_max_torque(value, units=TorqueUnits.NM)
The torque can be set as torque, current or percent of maximum.
value : the new maximum torque to use
units : the units that value is passed in
None
# set maximum torque to 2 Nm\
motor1.set_max_torque(2, TorqueUnits.NM)
# set maximum torque to 1 Amp\
motor1.set_max_torque(1, CurrentUnits.AMP)
# set maximum torque to 20 percent\
motor1.set_max_torque(20, PERCENT)
set_position(value, units=None)
The position returned by the position() function is set to this value.
value : The new position
units : The units for the provided position, the default is DEGREES
None
set_stopping(mode=BrakeType.COAST)
Setting the action for the motor when stopped.
mode : The stopping mode, COAST, BRAKE or HOLD
None
set_timeout(timeout, units=TimeUnits.MSEC)
The timeout value is used when performing spin_to_position and spin_for commands. If timeout is reached and the motor has not completed moving, then the spin... function will return False.
timeout : The new timeout
units : The units for the provided timeout, the default is MSEC
None
set_velocity(velocity, units=None)
This will be the velocity used for subsequent calls to spin if a velocity is not provided to that function.
velocity : The new velocity
units : The units for the supplied velocity, the default is RPM
None
spin(direction, velocity=None, units=VelocityUnits.RPM)
direction : The direction to spin the motor, FORWARD or REVERSE
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# spin motors forward at velocity set with set_velocity\
mg1.spin(FORWARD)
# spin motors forward at 50 rpm\
mg1.spin(FORWARD, 50)
# spin with negative velocity, ie. backwards\
mg1.spin(FORWARD, -20)
# spin motors forwards with 100% velocity\
mg1.spin(FORWARD, 100, PERCENT)
# spin motors forwards at 50 rpm\
mg1.spin(FORWARD, 50, RPM)
# spin motors forwards at 360 dps\
mg1.spin(FORWARD, 360.0, VelocityUnits.DPS)
spin_for(direction, rotation, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
Move the motor to the requested position or for the specified amount of time.\ The position is relative (ie. an offset) to the current position\ This function supports keyword arguments.
direction : The direction to spin the motor, FORWARD or REVERSE
rotation : The relative position to spin the motor to or tha amount of time to spin for
units (optional) : The units for the provided position or time, the default is DEGREES or MSEC
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# spin 180 degrees from the current position\
mg1.spin_for(FORWARD, 180)
# spin reverse 2 TURNS (revolutions) from the current position\
mg1.spin_for(REVERSE, 2, TURNS)
# spin 180 degrees from the current position at 25 rpm\
mg1.spin_for(FORWARD, 180, DEGREES, 25, RPM)
# spin 180 degrees from the current position and do not wait for completion\
mg1.spin_for(FORWARD, 180, DEGREES, False)
# spin 180 degrees from the current position and do not wait for completion\
mg1.spin_for(FORWARD, 180, DEGREES, wait=False)
spin_to_position(rotation, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
Move the motor to the requested position.\ This function supports keyword arguments.
rotation : The position to spin the motor to
units (optional) : The units for the provided position, the default is DEGREES
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# spin to 180 degrees\
mg1.spin_to_position(180)
# spin to 2 TURNS (revolutions)\
mg1.spin_to_position(2, TURNS)
# spin to 180 degrees at 25 rpm\
mg1.spin_to_position(180, DEGREES, 25, RPM)
# spin to 180 degrees and do not wait for completion\
mg1.spin_to_position(180, DEGREES, False)
# spin to 180 degrees and do not wait for completion\
mg1.spin_to_position(180, DEGREES, wait=False)
stop(mode=None)
The motor will be stopped and set to COAST, BRAKE or HOLD
None
None
temperature(units=TemperatureUnits.CELSIUS)
units (optional) : The units for the returned temperature, the default is CELSIUS
The motor temperature in provided units
torque(units=TorqueUnits.NM)
units (optional) : The units for the returned torque, the default is NM
The motor torque in provided units
velocity(units=VelocityUnits.RPM)
units (optional) : The units for the returned velocity, the default is RPM
The motor velocity in provided units
MotorVictor
The MotorVictor class will create raw RC style pwm waveform.\ This is primarily for use with the VEX Victor motor controller\
port : The 3wire port to use for the motor controller
reverse_flag (optional) : set reverse flag for this motor, spin commands will cause opposite rotation if set True. default is False.
An instance of the MotorVictor class
motor1 = MotorVictor(brain.three_wire_port.a)
set_reversed(value)
value : 1, 0, True or False
None
# set motor reversed flag True\
motor1.set_reversed(True)
set_velocity(value, units=VelocityUnits.RPM)
This will be the velocity used for subsequent calls to spin of a velocity is not provided to that function.
value : The new velocity
units : The units for the supplied velocity, the default is RPM
None
spin(direction, velocity=None, units=None)
The motor is assumed to have a maximum velocity of 100 rpm.
direction : The direction to spin the motor, FORWARD or REVERSE
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units (optional) : The units of the provided velocity, default is RPM
None
# spin motor forward at velocity set with set_velocity\
motor1.spin(FORWARD)
# spin motor forward at 50 rpm\
motor1.spin(FORWARD, 50)
# spin with negative velocity, ie. backwards\
motor1.spin(FORWARD, -20)
# spin motor forwards with 100% velocity\
motor1.spin(FORWARD, 100, PERCENT)
# spin motor forwards at 50 rpm\
motor1.spin(FORWARD, 50, RPM)
# spin motor forwards at 360 dps\
motor1.spin(FORWARD, 360.0, VelocityUnits.DPS)
stop()
None
None
value()
This is the raw internal pwm value\ A motor velocity of 0 will return 127\ A maximum positive motor velocity will return 255
None
A value in the range 0 to 255.
# get motor current pwm value\
value = motor1.value()
ObjectSizeType
The defined units for distance sensor object size.
Optical
port : The smartport this device is attached to
An instance of the Optical class
opt1 = Optical(Ports.PORT1)
brightness(readraw=False)
readraw (optional) : return raw brightness value if True rather than percentage.
brightness as a float in the range 0 - 100%
brightness = opt1.brightness()
color()
None
color as an instance of the Color class
c = opt1.color()
gesture_disable()
None
None
opt1.gesture_disable()
gesture_down(callback, arg=())
gesture must be enabled for events to fire.
callback : A function that will be called when a gesture down event is detected
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("down detected")
opt1.gesture_down(foo)
gesture_enable()
None
None
opt1.gesture_enable()
gesture_left(callback, arg=())
gesture must be enabled for events to fire.
callback : A function that will be called when a gesture left event is detected
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("left detected")
opt1.gesture_left(foo)
gesture_right(callback, arg=())
gesture must be enabled for events to fire.
callback : A function that will be called when a gesture right event is detected
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("right detected")
opt1.gesture_right(foo)
gesture_up(callback, arg=())
gesture must be enabled for events to fire.
callback : A function that will be called when a gesture up event is detected
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("up detected")
opt1.gesture_up(foo)
get_gesture(newobject=False)
newobject (optional) : create a new Gesture object to return data in
An object with the last gesture data
opt1.gesture_disable()
hue()
None
hue as a float in the range 0 - 359.99 degrees
hue = opt1.hue()
installed()
None
True or False
integration_time(value=-1)
value (optional) : integration time in mS (5 to 700)
The current integration time
opt1.set_light_power(50)
is_near_object()
None
True if near an object
if opt1.is_near_object():
print('near object')
object_detect_threshold(value)
value : Number in the range 0 to 255. A value of 0 will just return current value.
current value
opt1.object_detect_threshold(100)
object_detected(callback, arg=())
callback : A function that will be called when an object detected event occurs
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("object detected")
opt1.object_detected(foo)
object_lost(callback, arg=())
callback : A function that will be called when an object lost event occurs
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("object lost")
opt1.object_lost(foo)
rgb(raw=False)
raw (optional) : return raw or processed values
A tuple with red, green, blue and brightness
value=opt1.rgb()
set_light(*args)
value : LedStateType.ON, LedStateType.OFF or power of led, 0 to 100%
None
# turn on led with previous intensity\
opt1.set_light(LedStateType.ON)
# turn on led with new intensity\
opt1.set_light(65)
set_light_power(value)
value : power of led, 0 to 100%
None
opt1.set_light_power(50)
timestamp()
None
timestamp of the last status packet in mS
OrientationType
The defined units for inertial sensor orientation.
PITCH = OrientationType(1, 'PITCH')
pitch, orientation around the Y axis of the Inertial sensor.
ROLL = OrientationType(0, 'ROLL')
roll, orientation around the X axis of the Inertial sensor.
YAW = OrientationType(2, 'YAW')
yaw, orientation around the Z axis of the Inertial sensor.
PercentUnits
The measurement units for percentage values.
PERCENT = PercentUnits(0, 'PERCENT')
A percentage unit that represents a value from 0% to 100%
Pneumatics
port : The 3wire port to use for the pneumatics
An instance of the Pneumatics class
p1 = Pneumatics(brain.three_wire_port.a)
close()
None
None
p1.close()
open()
None
None
p1.open()
value()
None
1 or 0
Ports
Smartport definitions
Potentiometer
port : The 3wire port to use for the potentiometer
An instance of the Potentiometer class
pot1 = Potentiometer(brain.three_wire_port.a)
angle(units=RotationUnits.DEG)
units (optional) : A valid RotationUnits type or PERCENT, the default is DEGREES
A value in the range that is specified by the units.
# get potentiometer in range 0 - 250 degrees\
angle = pot1.angle()
# get potentiometer in range 0 - 100%\
angle = pot1.angle(PERCENT)
changed(callback, arg=())
callback : A function that will be called when the value of the potentiometer changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("pot changed")
pot1.changed(foo)
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get potentiometer in range 0 - 4095\
value = pot1.value()
# get potentiometer in range 0 - 1023\
value = pot1.value(AnalogUnits.TENBIT)
PotentiometerV2
port : The 3wire port to use for the potentiometer
An instance of the PotentiometerV2 class
pot1 = PotentiometerV2(brain.three_wire_port.a)
angle(units=RotationUnits.DEG)
units (optional) : A valid RotationUnits type or PERCENT, the default is DEGREES
A value in the range that is specified by the units.
# get potentiometer in range 0 - 250 degrees\
angle = pot1.angle()
# get potentiometer in range 0 - 100%\
angle = pot1.angle(PERCENT)
changed(callback, arg=())
callback : A function that will be called when the value of the potentiometer changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("pot changed")
pot1.changed(foo)
value(units=AnalogUnits.TWELVEBIT)
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get potentiometer in range 0 - 4095\
value = pot1.value()
# get potentiometer in range 0 - 1023\
value = pot1.value(AnalogUnits.TENBIT)
PowerUnits
The measurement units for power values.
WATT = PowerUnits(0, 'WATT')
A power unit that is measured in watts.
Pwm
The pwm class will create raw RC style pwm waveform.\ A pwm output of 0% corresponds to pulse width of 1.5mS every 16mS\ A pwm output of 100% corresponds to pulse width of 2mS\ A pwm output of -100% corresponds to pulse width of 1mS
port : The 3wire port to use for the pwm output
An instance of the Pwm class
pwm1 = Pwm(brain.three_wire_port.a)
state(value, units=PercentUnits.PERCENT)
value : The new value for pwm output, -100 to +100 percent.
units (optional) : units must be specified in PERCENT
None
# set pwm1 output to 50%\
pwm1.state(50)
value()
None
A value in the range -100 to +100 percent.
# get pwm1 current value\
value = pwm1.value()
Rotation
port : The smartport this device is attached to
reverse (optional) : set to reverse the angle and position returned by the sensor.
An instance of the Rotation class
rot1 = Rotation(Ports.PORT1)\
rot2 = Rotation(Ports.PORT2, True)
angle(units=RotationUnits.DEG)
units (optional) : A valid RotationUnits type, the default is DEGREES
A value in the range that is specified by the units.
# get rotation sensor angle angle = rot1.angle()
changed(callback, arg=())
callback : A function that will be called when the value of the rotation sensor changes
arg (optional) : A tuple that is used to pass arguments to the callback function.
An instance of the Event class
def foo():
print("rotation changed")
rot1.changed(foo)
installed()
None
True or False
position(units=RotationUnits.DEG)
The position is an absolute value that continues to increase or decrease as the\ sensor is rotated.
units (optional) : The units for the returned position, the default is DEGREES
The rotation sensor in provided units
reset_position()
None
None
set_position(value, units=RotationUnits.DEG)
The position returned by the position() function is set to this value.
The position is an absolute value that continues to increase or decrease as the\ sensor is rotated.
value : The new position
units : The units for the provided position, the default is DEGREES
None
set_reversed(value)
Usually this would be done in the constructor.
value : 1, 0, True or False
None
# set reversed flag True\
rot1.set_reversed(True)
timestamp()
None
timestamp of the last status packet in mS
velocity(units=VelocityUnits.RPM)
units (optional) : The units for the returned velocity, the default is RPM
The rotation sensor velocity in provided units
RotationUnits
The measurement units for rotation values.
DEG = RotationUnits(0, 'DEG')
A rotation unit that is measured in degrees.
RAW = RotationUnits(99, 'RAW')
A rotation unit that is measured in raw data form.
REV = RotationUnits(1, 'REV')
A rotation unit that is measured in revolutions.
SerialLink
port : The smartport the VEXlink radio is attached to
name : The name of this link
linktype : The type of this link, either VexlinkType.MANAGER or VexlinkType.WORKER
wired (optional) : Set to True if this is a wired link
An instance of the SerialLink class
link = SerialLink(Ports.PORT1, 'james', VexlinkType.MANAGER)
installed()
None
True or False
is_linked()
None
True if the link is active and connected to the paired brain.
receive(length, timeout=300000)
length : maximum amount of data to wait for
timeout (optional) : An optional timeout value in mS before the function returns.
None or bytearray with data
# wait for 128 bytes of data for 1000mS\
buffer = link.receive(128, 1000)
received(callback)
This will receive a bytearray and a length indicating how much
callback : A function that will be called when data is received
None
def cb(buffer, length):
print(buffer, length)
link.received(cb)
send(buffer)
buffer : A string or bytearray, the message to send
None
# send the string 'test'\
link.send('test')
# send the bytearray 'test' with parameters\
link.send('test', 1, 3.14)
Servo
The Servo class will create raw RC style pwm waveform.\ An output of 0 corresponds to pulse width of 1.5mS every 16mS\ An output of 50 degrees corresponds to pulse width of 2mS\ An output of -50 degrees corresponds to pulse width of 1mS
port : The 3wire port to use for the servo output
An instance of the Servo class
servo1 = Servo(brain.three_wire_port.a)
set_position(value, units=RotationUnits.DEG)
value : The new value for the servo using the supplied units.
units (optional) : The rotation units, default is PERCENT
None
# set servo output to 10 degrees\
servo1.set_position(10, DEGREES)
value()
This is the raw internal pwm value\ A servo position of 0 will return 127\ A maximum positive servo position will return 255
None
A value in the range 0 to 255.
# get servo1 current value\
value = servo1.value()
Signature
index : The signature index
p0 : signature value p0
p1 : signature value p1
p2 : signature value p2
p3 : signature value p3
p4 : signature value p4
p5 : signature value p5
sigrange : signature range
sigtype : signature type
An instance of the Signature class
SIG_1 = Signature(1, 6035, 7111, 6572, -1345, -475, -910, 3.000, 0)\
vision1 = Vision(Ports.PORT1, 50, SIG_1)
id()
Not used, always returns 0
SmartDrive
Bases: DriveTrain
A smart drivetrain uses a gyro or similar sensor to turn more accurately.\ The smartdrive inherits all drivetrain functions.
lm : Left motor or motorgroup
rm : Right motor or motorgroup
g : The gyro, inertial sensor or gps to use for turns
wheelTravel (optional) : The circumference of the driven wheels, default is 300 mm
trackWidth (optional) : The trackwidth of the drivetrain, default is 320 mm
wheelBase (optional) : The wheelBase of the drivetrain, default is 320 mm
units (optional) : The units that wheelTravel, trackWidth and wheelBase are specified in, default is MM.
externalGearRatio (optional) : An optional gear ratio used to compensate drive distances if gearing is used.
A new SmartDrive object.
# A simple two motor smart drivetrain using default values\
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2, True)\
imu1 = Inertial(Ports.PORT9)\
smart1 = SmartDrive(motor1, motor2, imu1)
# A four motor smart drivetrain using custom values\
motor1 = Motor(Ports.PORT1)\
motor2 = Motor(Ports.PORT2)\
motor3 = Motor(Ports.PORT3, True)\
motor4 = Motor(Ports.PORT4, True)\
imu1 = Inertial(Ports.PORT9)\
mgl = MotorGroup(motor1, motor3)\
mgr = MotorGroup(motor2, motor4)\
smart1 = SmartDrive(mgl, mgr, imu1, 8.6, 10, 12, INCHES)
heading(units=RotationUnits.DEG)
heading will be returned in the range 0 - 359.99 degrees
units (optional) : The units to return the heading in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current heading for the smartdrive\
value = smart1.heading()
is_moving()
This function is used when False has been passed as the wait parameter to drive_for\ It will return True if the drivetrain is still moving or False if it has completed the move or a timeout occurred.
None
The current drive_for status
is_turning()
This function is used when False has been passed as the wait parameter to turn_to_heading or turn_for\ It will return True if the drivetrain is still moving or False if it has completed the move or a timeout occurred.
None
The current turn_to_heading, turn_to_rotation or turn_for status
rotation(units=RotationUnits.DEG)
rotation is not limited, it can be both positive and negative and shows the absolute angle of the gyro.
units (optional) : The units to return the rotation in, default is DEGREES
A value for heading in the range that is specified by the units.
# get the current rotation for the smartdrive\
value = smart1.rotation()
set_heading(value, units=RotationUnits.DEG)
The new value for heading should be in the range 0 - 359.99 degrees.
value : The new value to use for heading.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of heading to 180 degrees\
smart1.set_heading(180)
set_rotation(value, units=RotationUnits.DEG)
value : The new value to use for rotation.
units (optional) : The rotation units type for value, the default is DEGREES
None
# set the value of rotation to 180 degrees\
smart1.set_rotation(180)
set_turn_constant(value)
The smartdrive uses a simple P controller when doing turns.\ This constant, generally known as kp, is the gain used in the equation that\ turns angular error into motor velocity.
value : The new turn constant in the range 0.1 - 4.0, the default is 1.0
None
set_turn_direction_reverse(value)
value : True or False
None
set_turn_threshold(value)
This is the threshold value used to determine that turns are complete.\ If this is too large then turns will not be accurate, if too small then turns ma\ not complete.
value : The new turn threshold in degrees, the default for a smartdrive is 1 degree
None
turn_for(direction, angle, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
The turn_for command is similar to the motor spin_for command,\ however, the smartdrive is commanded to turn a specified angle.
direction : The direction to turn, LEFT or RIGHT
angle : The angle to turn
units (optional) : The units for the provided angle, the default is DEGREES
velocity (optional) : drive using this velocity, the default velocity set by set_drive_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None or if wait is True then completion success or failure
# turn right 90 degrees\
smart1.turn_for(RIGHT, 90, DEGREES)
# turn left 180 degrees with motors at 50 rpm\
smart1.turn_for(LEFT, 180, DEGREES, 50, RPM)
turn_to_heading(angle, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
The turn_to_heading command is similar to the motor spin_to_position command,\ however, the smartdrive is commanded to turn to a specified angle.\ This function uses the value of heading() when turning the smartdrive\ This function supports keyword arguments.
angle : The angle to turn to
units (optional) : The units for the provided angle, the default is DEGREES
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# turn to heading 180 degrees\
smart1.turn_to_heading(180)
# turn to heading 180 degrees at 25 rpm\
smart1.turn_to_heading(180, DEGREES, 25, RPM)
# turn to heading 180 degrees and do not wait for completion\
smart1.turn_to_heading(180, DEGREES, False)
# turn to heading 180 degrees and do not wait for completion\
smart1.turn_to_heading(180, DEGREES, wait=False)
turn_to_rotation(angle, units=RotationUnits.DEG, velocity=None, units_v=VelocityUnits.RPM, wait=True)
The turn_to_rotation command is similar to the motor spin_to_position command,\ however, the smartdrive is commanded to turn to a specified angle.\ This function uses the value of rotation() when turning the smartdrive\ This function supports keyword arguments.
angle : The angle to turn to
units (optional) : The units for the provided angle, the default is DEGREES
velocity (optional) : spin the motor using this velocity, the default velocity set by set_velocity will be used if not provided.
units_v (optional) : The units of the provided velocity, default is RPM
wait (optional) : This indicates if the function should wait for the command to complete or return immediately, default is True.
None
# turn to rotation 180 degrees\
smart1.turn_to_rotation(180)
# turn to rotation 400 degrees at 25 rpm\
smart1.turn_to_rotation(400, DEGREES, 25, RPM)
# turn to rotation 180 degrees and do not wait for completion\
smart1.turn_to_rotation(180, DEGREES, False)
# turn to rotation 180 degrees and do not wait for completion\
smart1.turn_to_rotation(180, DEGREES, wait=False)
Sonar
A sonar uses two adjacent 3wire ports.\ valid port pairs are a/b, c/d, e/f and g/h\ connect the wire labeled "output" to the lower 3wire port, eg. a
port : The 3wire port to use for the sonar sensor
An instance of the Sonar class
sonar1 = Sonar(brain.three_wire_port.a)
distance(units)
The sonar will return a large positive number if no object is detected in range.
units : The distance units to return the position value in.
A value for sonar distance in the specified units.
# get sonar distance in mm\
value = sonar1.distance(MM)
found_object()
The sonar will return True if an object is detected closer than 1000mm.
None
True of an object is detected.
# is an object closer than 1000mm\
if sonar1.found_object():\
print("object found")
value(units=AnalogUnits.TWELVEBIT)
This method has no practical use, see distance.
units (optional) : A valid AnalogUnits type or PERCENT, the default is 12 bit analog
A value in the range that is specified by the units.
# get sonar raw value\
value = sonar1.value()
TemperatureUnits
The measurement units for temperature values.
CELSIUS = TemperatureUnits(0, 'CELSIUS')
A temperature unit that is measured in celsius.
FAHRENHEIT = TemperatureUnits(0, 'FAHRENHEIT')
A temperature unit that is measured in fahrenheit.
Thread
This class is used to create a new thread using the vexos scheduler.
callback : A function used as the entry point for the thread
arg (optional) : A tuple that is used to pass arguments to the thread entry function.
An instance of the Thread class
def foo():
print('the callback was called')
t1 = Thread( foo )
def bar(p1, p2):
print('the callback was called with ', p1, ' and ', p2)
t2 = Thread( bar, (1,2) )
sleep_for(duration, units=TimeUnits.MSEC)
duration : time to sleep this thread for
units (optional) : units of time, default is MSEC
None
stop()
None
None
ThreeWireType
The defined units for 3-wire devices.
ACCELEROMETER = ThreeWireType(9, 'ACCELEROMETER')
A 3-wire sensor that is defined as a accelerometer.
ANALOG_IN = ThreeWireType(0, 'ANALOG_IN')
A 3-wire sensor that is defined as an analog input.
ANALOG_OUT = ThreeWireType(1, 'ANALOG_OUT')
A 3-wire sensor that is defined as an analog output.
DIGITAL_IN = ThreeWireType(2, 'DIGITAL_IN')
A 3-wire sensor that is defined as an digital input.
DIGITAL_OUT = ThreeWireType(3, 'DIGITAL_OUT')
A 3-wire sensor that is defined as an digital output.
ENCODER = ThreeWireType(12, 'ENCODER')
A 3-wire sensor that is defined as a quadrature encoder.
GYRO = ThreeWireType(8, 'GYRO')
A 3-wire sensor that is defined as a yaw rate gyro.
LIGHT_SENSOR = ThreeWireType(7, 'LIGHT_SENSOR')
A 3-wire sensor that is defined as a light sensor.
LINE_SENSOR = ThreeWireType(6, 'LINE_SENSOR')
A 3-wire sensor that is defined as a line sensor.
MOTOR = ThreeWireType(10, 'MOTOR')
A 3-wire sensor that is defined as a legacy vex motor.
POTENTIOMETER = ThreeWireType(5, 'POT')
A 3-wire sensor that is defined as a potentiometer.
SERVO = ThreeWireType(11, 'SERVO')
A 3-wire sensor that is defined as a legacy vex servo.
SLEW_MOTOR = ThreeWireType(14, 'SLEW_MOTOR')
A 3-wire sensor that is defined as a legacy vex motor using slew rate control.
SONAR = ThreeWireType(13, 'SONAR')
A 3-wire sensor that is defined as an ultrasonic sensor (sonar)
SWITCH = ThreeWireType(4, 'BUTTON')
A 3-wire sensor that is defined as a switch.
TimeUnits
The measurement units for time values.
MSEC = TimeUnits(1, 'MSEC')
A time unit that is measured in milliseconds.
SEC = TimeUnits(0, 'SECONDS')
A time unit that is measured in seconds.
SECONDS = TimeUnits(0, 'SECONDS')
A time unit that is measured in seconds.
Timer
This class is used to create a new timer\ A timer can be used to measure time, access the system time and run a function at a time in the future.
None
An instance of the Timer class
t1 = Timer()
clear()
None
None
event(callback, delay, arg=())
callback : A function that will called after the supplied delay
delay : The delay before the callback function is called.
arg (optional) : A tuple that is used to pass arguments to the function.
None
def foo(arg):
print('timer has expired ', arg)
t1 = Timer()\
t1.event(foo, 1000, ('Hello',))
reset()
None
None
system()
None
system time in mS
system_high_res()
None
system time in uS
time(units=TimeUnits.MSEC)
units (optional) : the units that the time should be returned in, default is MSEC
An the current time in specified units.
value()
None
An the current time in seconds.
TorqueUnits
The measurement units for torque values.
INLB = TorqueUnits(1, 'INLB')
A torque unit that is measured in Inch Pounds.
NM = TorqueUnits(0, 'NM')
A torque unit that is measured in Newton Meters.
Triport
installed()
None
True or False
timestamp()
None
timestamp of the last status packet in mS
TurnType
Bases: vexEnum
The defined units for turn values.
LEFT = TurnType(0, 'LEFT')
A turn unit that is defined as left turning.
RIGHT = TurnType(1, 'RIGHT')
A turn unit that is defined as right turning.
UNDEFINED = TurnType(2, 'UNDEFINED')
A turn unit unit used when direction is not known.
VelocityUnits
The measurement units for velocity values.
DPS = VelocityUnits(2, 'DPS')
A velocity unit that is measured in degrees per second.
PERCENT = VelocityUnits(0, 'PCT')
A velocity unit that is measured in percentage.
RPM = VelocityUnits(1, 'RPM')
A velocity unit that is measured in rotations per minute.
VexlinkType
The defined units for vexlink types.
GENERIC = VexlinkType(3, 'GENERIC')
A vexlink type that is defined as a raw unmanaged link.
MANAGER = VexlinkType(1, 'MANAGER')
A vexlink type that is defined as the manager radio.
WORKER = VexlinkType(2, 'WORKER')
A vexlink type that is defined as the worker radio.
Vision
port : The smartport this device is attached to
brightness (optional) : set the brightness value for the vision sensor
sigs (optional) : one or more signature objects
An instance of the Vision class
SIG_1 = Signature(1, 6035, 7111, 6572, -1345, -475, -910, 3.000, 0)\
vision1 = Vision(Ports.PORT1, 50, SIG_1)
installed()
None
True or False
take_snapshot(index, count=1)
index : A signature, code or signature id.
count (optional) : the maximum number of objects to obtain. default is 1.
tuple of VisionObject or None if nothing is available
# look for and return 1 object matching SIG_1\
objects = vision1.take_snapshot(SIG_1)
# look for and return a maximum of 4 objects matching SIG_1\
objects = vision1.take_snapshot(SIG_1, 4)
timestamp()
None
timestamp of the last status packet in mS
VisionObject
A vision object, not instantiated by user programs
VoltageUnits
The measurement units for voltage values.
MV = VoltageUnits(0, 'mV')
A voltage unit that is measured in millivolts.
VOLT = VoltageUnits(0, 'VOLT')
A voltage unit that is measured in volts.
vexEnum
Base class for all enumerated types
clear_errors()
None
None
info()
on_screen_errors(value)
value : True or False
None
sleep(duration, units=TimeUnits.MSEC)
duration: The number of seconds or milliseconds to sleep for
units: The units of duration, optional, default is milliseconds
None
wait(duration, units=TimeUnits.MSEC)
duration: The number of seconds or milliseconds to sleep for
units: The units of duration, optional, default is milliseconds
None