RoFI HAL

RoFI Hardware Abstraction Layer, RoFI HAL for short, allows to use the same code for both the physical RoFIs and for the simulated ones.

Types and Constants

enum class rofi::hal::ConnectorPosition : bool

Connector position.

Values:

enumerator Retracted
enumerator Extended
enum class rofi::hal::ConnectorOrientation : signed char

Connection orientation.

Values:

enumerator North
enumerator East
enumerator South
enumerator West
enum class rofi::hal::ConnectorLine : bool

Connector power line.

Values:

enumerator Internal
enumerator External
enum class rofi::hal::ConnectorEvent : signed char

Connector event.

Values:

enumerator Connected

Connection with other Connector started.

enumerator Disconnected

Connection with other Connector ended.

enumerator PowerChanged

Power status (voltage or current) changed.

struct ConnectorState

Connector state descriptor.

Public Members

ConnectorPosition position = ConnectorPosition::Retracted

Position of the Connector.

bool internal = false

Is internal power bus connected to the connector?

bool external = false

Is the external power bus connected to the connector?

LidarDistanceMode distanceMode = LidarDistanceMode::Autonomous

The current distance mode of the RoFICoM’s Lidar.

bool connected = false

Is there a mating side connected?

ConnectorOrientation orientation = ConnectorOrientation::North

Orientation of the connection. Applicable only when connected.

float internalVoltage = 0.f

Internal voltage of the Connector.

float internalCurrent = 0.f

Internal current of the Connector.

float externalVoltage = 0.f

External voltage of the Connector.

float externalCurrent = 0.f

External current of the Connector.

LidarStatus lidarStatus = LidarStatus::NotMeasured

Status of lidar measurement.

uint16_t distance = 0

Lidar measured distance in mm. Validity depends on lidarStatus.

Classes

class RoFI

Proxy for accessing RoFI hardware.

The class has a private constructor - you can obtain an instance by calling static methods RoFI::getLocalRoFI and RoFI::getRemoteRoFI.

Since the class is only a proxy it can be safely copied and passed around.

Public Types

using Id = int

Unique RoFI identifier.

Public Functions

inline Id getId() const

Get RoFI Id.

Returns

RoFI Id

inline Joint getJoint(int index)

Get proxy for controlling Joint.

Parameters

index – index of the Joint

Returns

proxy for controlling Joint

inline Connector getConnector(int index)

Get proxy for controlling Connector.

Parameters

index – index of the Connector

Returns

proxy for controlling Connector

inline Descriptor getDescriptor() const

Get RoFI Descriptor.

Returns

RoFI Descriptor

inline Partition getRunningPartition() const

Get partition from which running firmware was loaded.

Returns

partition from which running firmware was loaded

inline UpdatePartition initUpdate()

Initialize firmware update.

If this method is called and another update is already in process std::runtime_error is thrown

Returns

UpdatePartition to write the new firmware to

inline void reboot()

Reboot device.

Public Static Functions

static RoFI getLocalRoFI()

Get proxy for controlling local RoFI.

Returns

proxy for controlling local RoFI

static RoFI getRemoteRoFI(Id remoteId)

Get proxy for controlling a remote RoFI identified by Id.

Parameters

remoteId – Id of the remote RoFI

Returns

proxy for controlling remote RoFI

static void sleep(int ms)

Blocks the execution for given amount of time.

Parameters

ms – delay in milliseconds

static void postpone(int ms, std::function<void()> callback)

Call callback after given delay.

The call is non-blocking.

You can assume that the callback will always be called exactly once.

Parameters
  • ms – wait time in milliseconds

  • callback – non-empty callback to be called after the delay

struct Descriptor

Module shape and capabilities description.

Public Members

int jointCount = 0
int connectorCount = 0
class Implementation

Interface of the actual implementation - either physical local, physical remote or a simulation one.

To provide an implementation, simply inherit from this class and implement the RoFI::getLocalRoFI() and RoFI::getRemoteRoFI() in a cpp file to return RoFI initialized with an instance of your implementation.

For method description, see description of RoFI.

Public Functions

virtual Id getId() const = 0
virtual Joint getJoint(int index) = 0
virtual Connector getConnector(int index) = 0
virtual Descriptor getDescriptor() const = 0
virtual Partition getRunningPartition() = 0
virtual UpdatePartition initUpdate() = 0
virtual void reboot() = 0
class Joint

Proxy for controlling a single joint of RoFI.

Joint cannot be instantiated on its own; you can obtain its instance from RoFI::getJoint().

Since the class is only a proxy it can be safely copied and passed around.

Public Types

enum class Error

Values:

enumerator Communication

Cannot communicate with the servo motor.

enumerator Hardware

Servo motor responded with an error.

Public Functions

inline float maxPosition() const

Get maximal joint position.

Returns

maximal joint position in rad

inline float minPosition() const

Get minimal joint position.

Returns

minimal joint position in rad

inline float maxSpeed() const

Get maximal joint speed.

Returns

maximal joint speed in rad / s

inline float minSpeed() const

Get minimal joint speed.

Returns

minimal joint speed in rad / s

inline float maxTorque() const

Get maximal joint torque.

Returns

maximal joint torque in N * m

inline float getVelocity()

Get current joint velocity setpoint.

Returns

velocity setpoint in rad / s

inline void setVelocity(float velocity)

Change the joint’s control mode to velocity and move at velocity.

Parameters

velocity – velocity setpoint in rad / s

inline float getPosition()

Get current joint position.

This works in all three control modes - position, velocity and torque mode.

Returns

current position in rad

inline void setPosition(float pos, float velocity, std::function<void(Joint)> callback)

Change the joint’s control mode to position and move to position.

Calling any joint control method (Joint::setPosition, Joint::setVelocity or Joint::setTorque) before the position is reached will result in the callback never beeing called.

Parameters
  • pos – position setpoint in rad

  • velocity – velocity limit in rad / s, required to be positive and non-zero

  • callback – callback to be called once the position is reached

inline float getTorque()

Get current joint torque.

Returns

current torque in N * m

inline void setTorque(float torque)

Change the joint’s control mode to torque and provide torque.

Parameters

torque – torque setpoint in N * m

inline void onError(std::function<void(Joint, Error, const std::string&)> callback)

Set error handling callback.

Calling this method again (on the same Joint) will overwrite the previous callback. You can call this method with empty function to remove the callback.

Parameters

callback – callback to be called on error

inline Joint(std::shared_ptr<Implementation> impl)
class Implementation

Interface of the actual implementation - either physical local, physical remote or a simulation one.

To provide an implementation, simply inherit from this class.

For method description, see description of Joint.

Public Functions

virtual const Capabilities &getCapabilities() = 0
virtual float getVelocity() = 0
virtual void setVelocity(float velocity) = 0
virtual float getPosition() = 0
virtual void setPosition(float pos, float velocity, std::function<void(Joint)> callback) = 0
virtual float getTorque() = 0
virtual void setTorque(float torque) = 0
virtual void onError(std::function<void(Joint, Error, const std::string&)> callback) = 0
struct Capabilities

Public Members

float maxPosition
float minPosition
float maxSpeed
float minSpeed
float maxTorque
class Connector

Proxy for controlling a single connector of RoFI.

Connector cannot be instantiated on its own; you can obtain its instance from RoFI::getConnector().

Since the class is only a proxy it can be safely copied and passed around.

Public Functions

inline ConnectorState getState()

Get connector state.

Returns

connector state

inline void connect()

Extend the connector to be ready to accept connection.

This action does not establish connection. To react to connections, register a callback via Connector::onConnectorEvent().

inline void disconnect()

Retract the connector.

Does not release a connection immediately. After the connection is broken physically, calls callback registered via Connector::onConnectorEvent().

inline void onConnectorEvent(std::function<void(Connector, ConnectorEvent)> callback)

Register callback for connector events.

Calling this method again (on the same Connector) will overwrite the previous callback. You can call this method with empty function to remove the callback.

Parameters

callback – callback to be called on connector events

inline void onPacket(std::function<void(Connector, uint16_t, PBuf)> callback)

Register callback for incoming packets.

The callback takes connector which received the packet, contentType and the packet.

Calling this method again (on the same Connector) will overwrite the previous callback. You can call this method with empty function to remove the callback.

Parameters

callback – callback to be called on a packet

inline void send(uint16_t contentType, PBuf packet)

Send a packet to mating side.

If no mating side is present, packet is discarded.

inline void connectPower(ConnectorLine line)

Connect power of mating side to a power line.

inline void disconnectPower(ConnectorLine line)

Disconnect power of mating side from a power line.

inline void setDistanceMode(LidarDistanceMode mode)

Sets distance mode for the RoFICoM’s Lidar.

inline Connector(std::shared_ptr<Implementation> impl)
class Implementation

Interface of the actual implementation - either physical local, physical remote or a simulation one.

To provide an implementation, simply inherit from this class.

For method description, see description of Connector.

Public Functions

virtual ConnectorState getState() = 0
virtual void connect() = 0
virtual void disconnect() = 0
virtual void onConnectorEvent(std::function<void(Connector, ConnectorEvent)> callback) = 0
virtual void onPacket(std::function<void(Connector, uint16_t contentType, PBuf)> callback) = 0
virtual void send(uint16_t contentType, PBuf packet) = 0
virtual void connectPower(ConnectorLine) = 0
virtual void disconnectPower(ConnectorLine) = 0
virtual void setDistanceMode(LidarDistanceMode) = 0

Networking

class PBuf

RAII wrapper over LwIP pbuff.

Makes the PBuf non-copyable, but movable.

Public Functions

inline PBuf(const PBuf &o)
inline PBuf &operator=(PBuf o)
inline PBuf(PBuf &&o)
inline PBuf &operator=(PBuf &&o)
inline ~PBuf()
inline void swap(PBuf &o)
inline pbuf *release()

Release owenership of the packet.

This function should be called when the packet is passed to a C interface which manages its lifetime.

inline pbuf *get()
inline operator bool() const
inline bool simple() const
inline uint8_t *payload()
inline const uint8_t *payload() const
inline int size() const
inline uint8_t &operator[](int idx)
inline const uint8_t &operator[](int idx) const
inline ChunkIt chunksBegin()
inline ChunkIt chunksEnd()
inline std::string asString()

Public Static Functions

static inline PBuf allocate(int size)
static inline PBuf reference(pbuf *b)
static inline PBuf own(pbuf *b)
static inline PBuf empty()
struct Chunk

Public Functions

inline uint8_t *mem()
inline int size()

Public Members

const pbuf *_buf
class ChunkIt

Public Types

using value_type = Chunk
using reference = Chunk&
using pointer = Chunk*
typedef int difference_type
typedef std::forward_iterator_tag iterator_category

Public Functions

inline ChunkIt(pbuf *buf = nullptr)
inline ChunkIt operator++(int)
inline ChunkIt &operator++()
inline reference operator*()
inline pointer operator->()
inline bool operator==(const ChunkIt &o) const
inline bool operator!=(const ChunkIt &o) const