Skip to main content

utils.packet

PendantButtons Objects​

class PendantButtons()

Bit field for pendant buttons.

AmigaControlState Objects​

class AmigaControlState()

State of the Amiga vehicle control unit (VCU).

NodeState Objects​

class NodeState()

State of the MainLoop.

BOOTUP​

Boot up / Initializing

STOPPED​

Stopped

OPERATIONAL​

Operational

PRE_OPERATIONAL​

Pre-Operational

ActuatorCommands Objects​

class ActuatorCommands()

Defines commands for actuators.

actuator_bits_cmd​

def actuator_bits_cmd(a0=ActuatorCommands.passive,
a1=ActuatorCommands.passive,
a2=ActuatorCommands.passive,
a3=ActuatorCommands.passive)

Performs bit shifting to return a single byte representing command of 4 actuators.

actuator_bits_read​

def actuator_bits_read(bits)

Reads and returns individual actuator states from a bit pattern.

Packet Objects​

class Packet()

Base class inherited by all CAN message data structures.

from_can_data​

@classmethod
def from_can_data(cls, data)

Unpack CAN data directly into CAN message data structure.

stamp​

def stamp()

Time most recent message was received.

fresh​

def fresh(thresh_ms=500)

Returns False if the most recent message is older than thresh_ms

age​

def age()

Age of the most recent message.

encode​

def encode()

Encodes the packet data for transmission.

Must be implemented by subclasses.

decode​

def decode(data)

Decodes the packet data from transmission.

Must be implemented by subclasses.

PendantState Objects​

class PendantState(Packet)

State of the Pendant (joystick position & pressed buttons)

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

PendantLEDs Objects​

class PendantLEDs(Packet)

Command to the pendant on LEDs / backlight to illuminate.

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

AmigaRpdo1 Objects​

class AmigaRpdo1(Packet)

State, speed, and angular rate command (request) sent to the Amiga vehicle control unit (VCU).

New in fw v0.1.9 / farm-ng-amiga v0.0.7: Add pto & hbridge control. Message data is now 8 bytes (was 5).

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

AmigaTpdo1 Objects​

class AmigaTpdo1(Packet)

State, speed, and angular rate of the Amiga vehicle control unit (VCU).

New in fw v0.1.9 / farm-ng-amiga v0.0.7: Add pto & hbridge control. Message data is now 8 bytes (was 5).

New in fw v0.6.0 / farm-ng-amiga v2.4.0: Add SOC (state of charge) to the message.

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

AmigaPdo2 Objects​

class AmigaPdo2(Packet)

AmigaPdo2​

Contains a request or reply of RPM for each in individual motor (0xA - 0xD).

Identical packet for RPDO (request) & TPDO (reply/measured). Should be used in conjunction with AmigaRpdo1 / AmigaTpdo1 for auto control.

Introduced in fw version v0.2.0.

Usage​

To send individual motor rpm commands:

  • Send an AmigaRpdo1 with:
    • state_req = STATE_AUTO_ACTIVE
    • cmd_speed = 0.0
    • cmd_ang_rate = 0.0
  • Send an AmigaPdo2 on cob_id_req with:
    • a_rpm, AmigaTpdo10, AmigaTpdo11, AmigaTpdo12 = desired rpm for each motor

Warning: If you send any cmd_speed or cmd_ang_rate in your AmigaRpdo1 while sending individual motor rpm commands, the Amiga may go into an error state.

To switch back to AmigaRpdo1 only control, stop sending AmigaPdo2 messages and wait ~1 second.

Tip​

RPM is signed based on the direction of your motors. Check your dashboard to see which direction each of your motors spin for forward/reverse motion.

cob_id_req​

RPDO2

cob_id_rep​

TPDO2

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

FarmngHeartbeat Objects​

class FarmngHeartbeat(Packet)

Custom Heartbeat message = status sent regularly by farm-ng components.

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

EstopRequest Objects​

class EstopRequest(Packet)

An 8 byte packet that requests an e-stop.

We only care about the first byte and ignore the rest for now. The other bytes can be used as a message state unique to the device requesting the e-stop.

cob_id​

TPDO1

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

make_message​

@classmethod
def make_message(cls, node_id, request_estop)

Returns a CAN message with the e-stop request encoded.

EstopReply Objects​

class EstopReply(Packet)

An 8 byte packet that responds with registered e-stop devices.

We only care about the first 4 bytes and ignore the rest for now.

cob_id​

RPDO1

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.

BumperState Objects​

class BumperState(Packet)

This is an expansion of the EstopRequest packet that also includes the state of the 4 Bumpers. This is so the dashboard can treat the BumperState as a generic EstopRequest, ignoring the contents of any byte besides the estop_request bool in the first signed char. While other components could look for more insight from the BumperState encoded data.

Encoding:

  • b: signed char used as bool for true/false estop-request
  • h: signed short encoding pressed bumpers
  • 5x: pad bytes

For the circuitpy/examples/bumpers/main.py: (True => corresponding pin is pressed) button states are packed as follows: (0x1 * board.D10) + (0x2 * board.D11) + (0x4 * board.12) + (0x8 * board.b13) In other words, pins are bit coded in the first 4 bits bit 0 => pin D10, bit 1 => pin D11, bit 2 => pin D12, bit 3 => pin D13

cob_id​

TPDO1

encode​

def encode()

Returns the data contained by the class encoded as CAN message data.

decode​

def decode(data)

Decodes CAN message data and populates the values of the class.