Class Can

Class Documentation

class Can

A simple CAN wrapper class that handles I/O from both CAN bus 1 and 2.

Public Functions

Can() = default
~Can() = default
void initialize()

Initializes CAN 1 and CAN 2 hardware to pins specific to the development board and sets up the CAN bus filters necessary for reading from the CAN bus.

Note

CAN 1 is connected to pins D0 (RX) and D1 (TX) and CAN 2 is connected to pins B12 (RX) and B12 (TX).

Note

The CAN filters are set up to receive NOT extended identifier IDs.

bool isMessageAvailable(CanBus bus) const

Checks the passed in CanBus to see if there is a message waiting and available.

Parameters:

bus[in] the CanBus to check for a message.

Returns:

true if a message is available, false otherwise.

bool getMessage(CanBus bus, modm::can::Message *message)

Checks the CanBus for a message and if a message is successfully acquired, returns true and places the message in the return parameter message.

Parameters:
  • bus[in] the CanBus to acquire a message from.

  • message[out] a return parameter which the message is placed in.

Returns:

true if a valid message was placed in the parameter message. False otherwise.

bool isReadyToSend(CanBus bus) const

Checks the given CanBus to see if the CanBus is idle.

Parameters:

bus[in] the CanBus to check.

Returns:

true if the bus is not busy, false otherwise.

bool sendMessage(CanBus bus, const modm::can::Message &message)

Sends the passed in message over the CanBus. Returns whether or not the message succeeded.

Attention

modm::can::Message defaults to an extended message identifier. For all RoboMaster products we have, we do not want our messages to be extended. Be sure to be explicit when instantiating a message object and setting extended to false.

Parameters:
  • bus[in] the CanBus for which the message should be sent across.

  • message[in] the message to send

Returns:

true if the message was successfully sent, false otherwise.