This page documents the VEX V5 sensor classes available in the DishPy SDK. Each class provides an interface to a specific VEX sensor, with methods for reading data and controlling sensor behavior.
vex.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()
vex.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
vex.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
vex.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
vex.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
vex.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
vex.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)
vex.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)
vex.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()
vex.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()
vex.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()
vex.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()
vex.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)
vex.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)
vex.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)
vex.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)
vex.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()
vex.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
vex.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
vex.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
vex.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
vex.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
vex.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
vex.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
vex.VisionObject
A vision object, not instantiated by user programs
vex.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
vex.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
vex.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)
vex.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)
vex.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)