Go to the documentation of this file.
25 using namespace std::literals;
30 CServoeNeck::CServoeNeck()
31 : m_usbSerialNumber(
"eNeck001"),
33 m_TruncateFactor(0.5),
61 std::this_thread::sleep_for(200ms);
80 1250 + (1000 /
M_PI) * (angle -
M_PI * 0.5);
130 if (!
isOpen())
return false;
146 if (!
archiveFrom(*this).receiveMessage(msgRx))
return false;
148 std::this_thread::sleep_for(200ms);
168 if (!
isOpen())
return false;
184 if (!
archiveFrom(*this).receiveMessage(msgRx))
return false;
186 std::this_thread::sleep_for(200ms);
205 if (!
isOpen())
return false;
218 if (msgRx.
content.size() != 2)
return false;
277 std::cout <<
"Angle: " <<
RAD2DEG(angle) <<
" - Reg: " << reg << std::endl;
295 uint8_t thisSpeed = speed < 15 ? 15 : speed > 250 ? 250 : speed;
297 uint16_t(0.25 * 1000000 / (500 + 1000 * (thisSpeed / 180.0f - 0.5)));
309 double angle,
const uint8_t servo,
bool fast)
325 return (
setAngle(nangle, servo, fast));
335 if (!
isOpen())
return false;
346 if (!
archiveFrom(*this).receiveMessage(msgRx))
return false;
366 if (!
isOpen())
return false;
377 if (!
archiveFrom(*this).receiveMessage(msgRx))
return false;
404 if (
isOpen())
return true;
409 std::this_thread::sleep_for(10ms);
411 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 __int16 uint16_t
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...
double RAD2DEG(const double x)
Radians to degrees.
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)
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,...
GLsizei const GLfloat * value
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)
GLsizei const GLchar ** string
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 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |