Go to the documentation of this file.
25 using namespace std::literals;
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);
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
void Purge()
Purge the I/O buffers.
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging.
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Gets the firmware version of the eNeck board.
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
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 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...
Contains classes for various device interfaces.
Serial and networking devices and utilities.
uint32_t type
An identifier of the message type (only the least-sig byte is typically sent)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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...
std::vector< float > m_offsets
The offset used for each servo.
A class that contain generic messages, that can be sent and received from a "CClientTCPSocket" object...
bool disableServo(const uint8_t servo=0)
Disables the servo so the neck will be loose.
std::vector< uint8_t > content
The contents of the message (memory is automatically handled by the std::vector object)
constexpr double RAD2DEG(const double x)
Radians to degrees.
bool getCurrentAngle(double &angle, const uint8_t servo=0)
Gets the current angle of the servo (in radians within (-pi,pi))
void setOffsets(float offset0, float offset1, float offset2)
Load the Offset values for each servo.
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip).
void Close()
Close the USB device.
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)".
bool enableServo(const uint8_t servo=0)
Enables the servo so the neck will be tight.
void getContentAsString(std::string &str)
Gets the contents of the message as a string.
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
std::deque< double > m_PrevAngles
A vector containing the last N angles which where passed to the servo (for averaging)
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...
bool setRegisterValue(const uint16_t value, const uint8_t servo=0, bool fast=false)
void OpenBySerialNumber(const std::string &serialNumber)
Open by device serial number.
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,...
void SetTimeouts(unsigned long dwReadTimeout_ms, unsigned long dwWriteTimeout_ms)
Change read & write timeouts, in milliseconds.
Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020 | |