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
-
enumerator Retracted
-
enum class rofi::hal::ConnectorOrientation : signed char
Connection orientation.
Values:
-
enumerator North
-
enumerator East
-
enumerator South
-
enumerator West
-
enumerator North
-
enum class rofi::hal::ConnectorLine : bool
Connector power line.
Values:
-
enumerator Internal
-
enumerator External
-
enumerator Internal
-
enum class rofi::hal::ConnectorEvent : signed char
Connector event.
Values:
-
enumerator PowerChanged
Power status (voltage or current) changed.
-
enumerator PowerChanged
-
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.
-
LidarStatus lidarStatus = LidarStatus::NotMeasured
Status of lidar measurement.
-
uint16_t distance = 0
Lidar measured distance in mm. Validity depends on
lidarStatus
.
-
ConnectorPosition position = ConnectorPosition::Retracted
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 Functions
-
inline Descriptor getDescriptor() const
Get RoFI Descriptor.
- Returns
-
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 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.
-
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.
-
inline Descriptor getDescriptor() const
-
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
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
orJoint::setTorque
) before the position is reached will result in thecallback
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 previouscallback
. You can call this method with empty function to remove thecallback
.- Parameters
callback – callback to be called on error
-
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 float getTorque() = 0
-
virtual void setTorque(float torque) = 0
-
struct Capabilities
-
virtual const Capabilities &getCapabilities() = 0
-
inline float maxPosition() const
-
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 previouscallback
. You can call this method with empty function to remove thecallback
.- 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 previouscallback
. You can call this method with empty function to remove thecallback
.- 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.
-
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 connectPower(ConnectorLine) = 0
-
virtual void disconnectPower(ConnectorLine) = 0
-
virtual void setDistanceMode(LidarDistanceMode) = 0
-
virtual ConnectorState getState() = 0
-
inline ConnectorState getState()
Networking
-
class PBuf
RAII wrapper over LwIP pbuff.
Makes the PBuf non-copyable, but movable.
Public Functions
-
inline ~PBuf()
-
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 std::string asString()
Public Static Functions
-
inline ~PBuf()