Libraries.Robots.Spike.Device Documentation

The device library allows you to gather information about the devices connected to each of the hubs ports, as well as set the duty cycle of a device at a specific port.

Example Code

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Port
Device dv
Port port
integer raw_data_of_port_A = dv:GetDataFromPort(port:A)

Inherits from: Libraries.Language.Object

Variables Table

VariablesDescription
integer MOTOR_LARGE_ID
integer FORCE_SENSOR_IDRetrieves raw LPF-2 data from the device connected to the provided port. The data is returned in an integer array of size 8
integer DISTANCE_SENSOR_ID
integer MOTOR_MEDIUM_ID
integer COLOR_SENSOR_ID

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetDataFromPort(integer port)

Retrieves raw LPF-2 data from the device connected to the provided port. The data is returned in an integer array of size 8

Parameters

  • integer port: The port (ranging from A to F or 0 to 5) with the device to collect data from

Return

Libraries.Containers.Array: An Array containing the raw LPF-2 data from the device

Example

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Port
use Libraries.Containers.Array
Device dv
Port port
Array<integer> raw_data_of_port_A
raw_data_of_port_A = dv:GetDataFromPort(port:A)

GetDutyCycle(integer port)

Retrieves the duty cycle (PWM) of the device connected to the provided port

Parameters

  • integer port: The port (ranging from A to F or 0 to 5) with the device to get the duty cycle of

Return

integer: PWM, the duty cycle (from 0 to 10000) of the device at the provided port

Example

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Port
Device dv
Port port
integer port_A_duty_cycle = dv:GetDutyCycle(port:A)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetIDOfPort(integer port)

Retrieves the ID of the device connected to the provided port

Parameters

  • integer port: The port (ranging from A to F or 0 to 5) with the device to get the ID of

Return

integer: ID, the integer ID of the device at the provided port

Example

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Port
Device dv
Port port
integer port_A_device_ID = dv:GetIDOfPort(port:A)

IsPortReady(integer port)

Returns true if the device is ready for requests, false if not

Parameters

  • integer port: The port (ranging from A to F or 0 to 5) with the device to check the ready state of

Return

boolean: A boolean that's true if the device is ready for requests, false if it isn't ready

Example

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Hub
use Libraries.Robots.Spike.LightMatrix
use Libraries.Robots.Spike.Port
Port port
Device dv
Hub hb
LightMatrix lights
repeat until IsPortReady(port:A)
    hb:Sleep(1)
end
lights:Write("Device at Port A is READY!!!")

SetDutyCycle(integer port, integer duty_cycle)

Sets the duty cycle (PWM) of a device at the provided port. Duty cycle value can range from 0 to 10000.

Parameters

  • integer port: The port (ranging from A to F or 0 to 5) with the device to set the duty cycle of
  • integer duty_cycle: The integer value from 0 to 10000 to set the duty cycle of the device to

Example

use Libraries.Robots.Spike.Device
use Libraries.Robots.Spike.Port
Device dv
Port port
dv:SetDutyCycle(port:A, 5000)