Robot Specific Python#

Introduction#

The VIQRC Virtual Skills - Mix & Match Playground features methods exclusive to the build designed for this Playground, including two motor options, a Distance Sensor, Optical Sensor, and Touch LED.

All standard VEXcode VR methods are available for use in the VIQRC Virtual Skills - Mix & Match Playground.

Below is a list of all available Playground specific methods:

Motion – Move and track the robot’s motors.

  • Actions

    • spin – Spins the selected motor or motor group indefinitely.

    • spin_for – Spins a motor or group for a specific distance in degrees or turns.

    • spin_to_position – Spins a motor or motor group to a set position.

    • stop – Stops a specific motor or motor group from spinning.

  • Mutators

    • set_position – Sets the encoder value of a motor or motor group.

    • set_velocity – Sets the speed of a motor or motor group as a percentage.

    • set_timeout – Limits how long a motor block waits before giving up if movement is blocked.

  • Getters

    • is_done – Returns a Boolean indicating whether the motor is no longer spinning.

    • is_spinning – Returns a Boolean indicating whether the motor is currently spinning.

    • position – Returns the motor’s current rotational position in degrees or turns.

    • velocity – Returns the motor’s current velocity in % or rpm.

Sensing - Utilize the robot’s various sensors.

  • Touch LED

    • set_color – Sets the TouchLED to a selected color.

  • Optical

    • is_near_object – Returns whether a detected object is near the Optical Sensor.

    • color – Returns the color detected from the Optical Sensor.

    • brightness – Returns the brightness percentage detected by the sensor.

    • hue – Returns the hue value of the detected color.

    • object_detected – Registers a callback function for when the Optical Sensor detects an object.

    • object_lost – Registers a callback function for when the Optical Sensor loses an object.

  • Distance

    • is_object_detected – Returns whether any object is currently detected by the Distance Sensor.

    • object_distance – Returns the distance of the nearest object from the Distance Sensor.

Motion#

Actions#

spin#

spin spins a motor indefinitely.

Usage:
motor.spin(direction)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.spin()
  • lift_motor – lift_motor.spin()

direction

The direction for the motor to move in:

  • FORWARD – Opens claw or lowers the lift.
  • REVERSE – Closes claw or raises the lift.
# Example coming soon!

spin_for#

spin_for spins a motor for a given amount of degrees or turns.

Usage:
motor.spin_for(direction, distance, units, wait=True)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.spin_for()
  • lift_motor – lift_motor.spin_for()

direction

The direction for the motor to move in:

  • FORWARD – Opens claw or lowers the lift.
  • REVERSE – Closes claw or raises the lift.

distance

The distance for the motor to move as an integer.

units

The unit that represents the distance to rotate:

  • DEGREES
  • TURNS

wait

Optional.

  • wait=True (default) - The robot waits until spin_for is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves on to the next line of code right away, without waiting for spin_for to finish.

# Example coming soon!

spin_to_position#

spin_to spins a motor to a given position.

Usage:
motor.spin_to_position(angle, units, wait=True)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.spin_to_position()
  • lift_motor – lift_motor.spin_to_position()

angle

The specific angle or number of turns that the motor will spin to.

units

The unit that represents the angle to rotate to:

  • DEGREES
  • TURNS

wait

Optional.

  • wait=True (default) - The robot waits until spin_to_position is complete before executing the next line of code.
  • wait=False - The robot starts the action and moves on to the next line of code right away, without waiting for spin_to_position to finish.

# Example coming soon!

stop#

stop stops a motor from spinning.

Usage:
motor.stop()

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.stop()
  • lift_motor – lift_motor.stop()
# Example coming soon!

Mutators#

set_position#

set_position sets a motor’s encoder position to the given position value.

Usage:
motor.set_position(position, units)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.set_position()
  • lift_motor – lift_motor.set_position()

position

The specific integer for the Motor’s encoder to be set to.

units

The unit that represents the angle to rotate to:

  • DEGREES
  • TURNS
# Example coming soon!

set_velocity#

set_velocity sets the speed of a motor.

Usage:
motor.set_velocity(velocity, units)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.set_velocity()
  • lift_motor – lift_motor.set_velocity()

velocity

The speed that the IQ Motor will spin at, ranging from 0 to 100.

units

The unit that represents the new velocity:

  • PERCENT
# Example coming soon!

set_timeout#

set_timeout sets a time limit for a motor’s movement commands. This prevents motion commands that do not reach their intended position from preventing subsequent commands from running.

Usage:
motor.set_timeout(value, units)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.set_timeout()
  • lift_motor – lift_motor.set_timeout()

value

The amount of time the motor will wait before stopping.

units

The unit to represent the timeout:

  • SECONDS
  • MSEC – milliseconds
# Example coming soon!

Getters#

is_done#

is_done returns a Boolean indicating whether the specified motor is not spinning.

  • True – The specified motor is not spinning.

  • False – The specified motor is spinning.

Usage:
motor.is_done()

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.is_done()
  • lift_motor – lift_motor.is_done()
# Example coming soon!

is_spinning#

is_spinning returns a Boolean indicating whether the specified motor is not spinning.

  • True – The specified motor is spinning.

  • False – The specified motor is not spinning.

Usage:
motor.is_spinning()

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.is_spinning()
  • lift_motor – lift_motor.is_spinning()
# Example coming soon!

position#

position returns the total distance the specified motor or motor group has rotated.

Usage:
motor.position(units)

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.position()
  • lift_motor – lift_motor.position()

units

The units that represent the motor’s position:

  • DEGREES
  • TURNS
# Example coming soon!

velocity#

velocity returns the current rotational speed of the motor or motor group.

Usage:
motor.velocity()

Parameters

Description

motor

The motor or motor group to spin:

  • claw_motor – claw_motor.velocity()
  • lift_motor – lift_motor.velocity()

units

The units that represent the motor’s position:

  • DEGREES
  • TURNS
# Example coming soon!

Sensing#

Touch LED#

set_color#

set_color sets the color of the Touch LED.

Usage:
touchled.set_color(color)

Parameters

Description

color

The color to set the Touch LED to:

  • NONE – Turns off the Touch LED
  • RED
  • GREEN
  • BLUE
  • YELLOW
  • ORANGE
  • PURPLE
  • WHITE
  • RED_VIOLET
  • VIOLET
  • BLUE_VIOLET
  • BLUE_GREEN
  • YELLOW_GREEN
  • YELLOW_ORANGE
  • RED_ORANGE

# Example coming soon!

Optical#

is_near_object#

is_near_object returns a Boolean indicating whether or not the Optical Sensor detects an object close to the sensor.

  • True – The object is close to the Optical Sensor.

  • False – The object is not close to the Optical Sensor.

Usage:
optical.is_near_object()

Parameters

Description

This method has no parameters.

# Example coming soon!

color#

color returns the color detected by the Optical Sensor:

Color Returned:

  • NONE – No color detected.
  • RED
  • GREEN
  • BLUE
  • YELLOW
  • ORANGE
  • PURPLE
  • WHITE
  • RED_VIOLET
  • VIOLET
  • BLUE_VIOLET
  • BLUE_GREEN
  • YELLOW_GREEN
  • YELLOW_ORANGE
  • RED_ORANGE

Usage:
optical.color()

Parameters

Description

This method has no parameters.

# Example coming soon!

brightness#

brightness returns the brightness value detected by the Optical Sensor as a percent from 0% to 100%.

Usage:
optical.brightness()

Parameters

Description

This method has no parameters.

# Example coming soon!

hue#

hue returns the hue detected by the Optical Sensor.

Hue values range from 0 to 359 degrees, corresponding to positions on the color wheel shown below.

A circular color wheel displaying a full spectrum of hues labeled with degree values around the perimeter, increasing in 30-degree increments from 0° at the top to 360°.

Usage:
optical.hue()

Parameters

Description

This method has no parameters.

# Example coming soon!

object_detected#

object_detected registers a callback function for when the Optical Sensor detects an object.

Usage:
optical.object_detected(callback, arg)

Parameters

Description

callback

A function that will be called when an object is detected.

arg

Optional. A tuple that is used to pass arguments to the callback function.

# Example coming soon!

object_lost#

object_lost registers a callback function for when the Optical Sensor loses an object.

Usage:
optical.object_lost(callback, arg)

Parameters

Description

callback

A function that will be called when an object is lost.

arg

Optional. A tuple that is used to pass arguments to the callback function.

# Example coming soon!

Distance#

is_object_detected#

is_object_detected returns a Boolean indicating whether the Distance Sensor detects an object.

  • True – The Distance Sensor detects an object.

  • False – The Distance Sensor does not detect an object.

Usage:
distance.is_object_detected()

Parameters

Description

This method has no parameters.

# Example coming soon!

object_distance#

object_distance returns the distance of the nearest object from the Distance Sensor.

Usage:
distance.object_distance(units)

Parameters

Description

units

The units that represents the distance:

  • MM
  • INCHES
# Example coming soon!