Class CServoeNeck

Inheritance Relationships

Base Type

  • public mrpt::comms::CInterfaceFTDI

Class Documentation

class CServoeNeck : public mrpt::comms::CInterfaceFTDI

A USB-interface for a custom “robotic neck” designed at MAPIR lab.

Public Functions

CServoeNeck()
~CServoeNeck() override
bool queryFirmwareVersion(std::string &out_firmwareVersion)

Gets the firmware version of the eNeck board.

Parameters:

out_firmwareVersion – [OUTPUT] A string containing the firmware version.

Returns:

Whether or not the procedure succeded.

bool getCurrentAngle(double &angle, const uint8_t servo = 0)

Gets the current angle of the servo (in radians within (-pi,pi))

Parameters:
  • Angle – [OUT] The current angle.

  • Servo – [IN] The id of the servo (in our ATMEGA16, from 0 to 2).

Returns:

Whether or not the procedure succeded.

bool setAngle(double angle, const uint8_t servo = 0, bool fast = false)

Turns the servo up to the specified angle (in radians in the range -pi,pi, other values will be saturated to the maximum or the mininum)

Parameters:
  • Angle – the desired angle to turn.

  • Servo – the id of the servo to move (in our ATMEGA16, from 0 to 2).

  • Fast – indicates if the servo must reach the angle at maximum speed

Returns:

Whether or not the procedure succeded.

bool setAngleAndSpeed(double angle, const uint8_t servo, const uint8_t speed)

Turns the servo up to the specified angle (in radians in the range -pi,pi, other values will be saturated to the maximum or the mininum)

Parameters:
  • Angle – the desired angle to turn.

  • Servo – the id of the servo to move (in our ATMEGA16, from 0 to 2).

  • Speed – indicates the speed of the servo

Returns:

Whether or not the procedure succeded.

bool setAngleWithFilter(double angle, const uint8_t servo = 0, bool fast = false)

Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with the last N specified angles.

Parameters:
  • Angle – the new desired angle to turn.

  • Servo – the id of the servo to move (in our ATMEGA16, from 0 to 2).

  • Fast – indicates if the servo must reach the angle at maximum speed

Returns:

Whether or not the procedure succeded.

bool disableServo(const uint8_t servo = 0)

Disables the servo so the neck will be loose.

Parameters:

Servo – the id of the servo to move (in our ATMEGA16, from 0 to 2).

Returns:

Whether or not the procedure succeded.

bool enableServo(const uint8_t servo = 0)

Enables the servo so the neck will be tight.

Parameters:

Servo – the id of the servo to move (in our ATMEGA16, from 0 to 2).

Returns:

Whether or not the procedure succeded.

bool center(const uint8_t servo = 0)

Centers the servo at zero position

inline double getTruncateFactor()

Gets the truncate factor of the turn

inline void setTruncateFactor(const double factor)

Gets the truncate factor of the turn

inline void setNumberOfPreviousAngles(const unsigned int number)

Gets the truncate factor of the turn

inline unsigned int getNumberOfPreviousAngles()

Gets the truncate factor of the turn

void setOffsets(float offset0, float offset1, float offset2)

Load the Offset values for each servo

Protected Functions

bool setRegisterValue(const uint16_t value, const uint8_t servo = 0, bool fast = false)
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
bool getRegisterValue(uint16_t &value, const uint8_t servo = 0)

Protected Attributes

std::string m_usbSerialNumber

A copy of the device serial number (to open the USB FTDI chip).

double m_MaxValue = {10000}

The value set in the ICR register within the ATMEGA16 controller.

double m_TruncateFactor = {0.5}

The range of turn of the servo will be truncated to “+-m_truncate_factor*(pi/2)”.

std::deque<double> m_PrevAngles

A vector containing the last N angles which where passed to the servo (for averaging)

unsigned int m_NumPrevAngles = {5}

Number of previous angles to store for averaging

std::vector<float> m_offsets

The offset used for each servo