30 CServoeNeck::CServoeNeck()
    31     : m_usbSerialNumber(
"eNeck001"),
    60             std::this_thread::sleep_for(200ms);
    79         1250 + (1000 / 
M_PI) * (angle - 
M_PI * 0.5);  
   100     double angle = 
M_PI * 0.5 + (
M_PI / 1000) * (value - 1250);
   125     const uint16_t value, 
const uint8_t servo, 
bool fast)
   129         if (!
isOpen()) 
return false;
   140         msg.
content[2] = (uint8_t)value;  
   141         msg.
content[1] = (uint8_t)(value >> 8);  
   145         if (!
archiveFrom(*this).receiveMessage(msgRx)) 
return false;  
   147         std::this_thread::sleep_for(200ms);
   163     const uint16_t value, 
const uint8_t servo, 
const uint16_t speed)
   167         if (!
isOpen()) 
return false;
   175         msg.
content[4] = (uint8_t)speed;  
   177             (uint8_t)(speed >> 8);  
   178         msg.
content[2] = (uint8_t)value;  
   179         msg.
content[1] = (uint8_t)(value >> 8);  
   183         if (!
archiveFrom(*this).receiveMessage(msgRx)) 
return false;  
   185         std::this_thread::sleep_for(200ms);
   204         if (!
isOpen()) 
return false;
   217             if (msgRx.
content.size() != 2) 
return false;
   276     std::cout << 
"Angle: " << 
RAD2DEG(angle) << 
" - Reg: " << reg << std::endl;
   285     double angle, 
const uint8_t servo, 
const uint8_t speed)
   294     uint8_t thisSpeed = speed < 15 ? 15 : speed > 250 ? 250 : speed;
   296         uint16_t(0.25 * 1000000 / (500 + 1000 * (thisSpeed / 180.0f - 0.5)));
   308     double angle, 
const uint8_t servo, 
bool fast)
   318     std::deque<double>::iterator it;
   324     return (
setAngle(nangle, servo, fast));
   334         if (!
isOpen()) 
return false;
   345         if (!
archiveFrom(*this).receiveMessage(msgRx)) 
return false;  
   365         if (!
isOpen()) 
return false;
   376         if (!
archiveFrom(*this).receiveMessage(msgRx)) 
return false;  
   403     if (
isOpen()) 
return true;
   408         std::this_thread::sleep_for(10ms);
   410         std::this_thread::sleep_for(10ms);
 
unsigned int angle2RegValue(const double angle)
Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 contr...
 
bool isOpen()
Checks whether the chip has been successfully open. 
 
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
 
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 satur...
 
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected). 
 
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Gets the firmware version of the eNeck board. 
 
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent) 
 
Contains classes for various device interfaces. 
 
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging. 
 
bool center(const uint8_t servo=0)
Centers the servo at zero position. 
 
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 t...
 
std::vector< float > m_offsets
The offset used for each servo. 
 
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream, std::istream, std::ostream, std::stringstream. 
 
bool getCurrentAngle(double &angle, const uint8_t servo=0)
Gets the current angle of the servo (in radians within (-pi,pi)) 
 
void Close()
Close the USB device. 
 
bool disableServo(const uint8_t servo=0)
Disables the servo so the neck will be loose. 
 
void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
Change read & write timeouts, in milliseconds. 
 
bool enableServo(const uint8_t servo=0)
Enables the servo so the neck will be tight. 
 
void OpenBySerialNumber(const std::string &serialNumber)
Open by device serial number. 
 
void setOffsets(float offset0, float offset1, float offset2)
Load the Offset values for each servo. 
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
 
void getContentAsString(std::string &str)
Gets the contents of the message as a string. 
 
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip). 
 
constexpr double RAD2DEG(const double x)
Radians to degrees. 
 
bool getRegisterValue(uint16_t &value, const uint8_t servo=0)
 
double m_TruncateFactor
The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)". ...
 
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object) ...
 
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 satur...
 
std::deque< double > m_PrevAngles
A vector containing the last N angles which where passed to the servo (for averaging) ...
 
Serial and networking devices and utilities. 
 
double regValue2angle(const uint16_t value)
Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for in...
 
void SetLatencyTimer(unsigned char latency_ms)
Change the latency timer (in milliseconds) implemented on the FTDI chip: for a few ms...
 
bool setRegisterValue(const uint16_t value, const uint8_t servo=0, bool fast=false)
 
void Purge()
Purge the I/O buffers.