34#include <visp3/core/vpConfig.h>
36#if defined(VISP_HAVE_POLOLU) && defined(VISP_HAVE_THREADS)
38#include <visp3/core/vpDebug.h>
39#include <visp3/robot/vpRobot.h>
40#include <visp3/robot/vpRobotException.h>
41#include <visp3/robot/vpRobotPololuPtu.h>
48 m_pan.connect(device, baudrate, 0);
49 m_pan.setPwmRange(4095, 7905);
51 m_pan.setVerbose(verbose);
53 m_tilt.connect(device, baudrate, 1);
54 m_tilt.setPwmRange(4095, 7905);
56 m_tilt.setVerbose(verbose);
61 m_pan.stopVelocityCmd();
62 m_tilt.stopVelocityCmd();
85 if (q.
size() !=
static_cast<unsigned int>(
nDof)) {
89 double s2 = sin(q[1]);
90 double c2 = cos(q[1]);
101 if (q.
size() !=
static_cast<unsigned int>(
nDof)) {
107 double s1 = sin(q[0]);
108 double c1 = cos(q[0]);
119 return m_pan.speedToRadS(1);
124 if (q.
size() !=
static_cast<unsigned int>(
nDof)) {
129 std::cout <<
"Warning: Robot is not in position-based control. Modification of the robot state" << std::endl;
151 m_pan.setAngularPosition(
static_cast<float>(q[0]), pos_vel);
152 m_tilt.setAngularPosition(
static_cast<float>(q[1]), pos_vel);
157 if (q_dot.
size() !=
static_cast<unsigned int>(
nDof)) {
163 "Cannot send a velocity to the robot "
164 "use setRobotState(vpRobot::STATE_VELOCITY_CONTROL) first) ");
170 "in the camera frame:"
171 "functionality not implemented");
182 "in the reference frame:"
183 "functionality not implemented");
188 "functionality not implemented");
192 "in the end-effector frame:"
193 "functionality not implemented");
209 for (
unsigned int i = 0; i < static_cast<unsigned int>(
nDof); ++i) {
210 if (fabs(q_dot[i]) > max) {
212 max = fabs(q_dot[i]);
221 q_dot_sat = q_dot * max;
224 std::cout <<
"Send velocity: " << q_dot_sat.
t() << std::endl;
226 m_pan.setAngularVelocity(
static_cast<float>(q_dot_sat[0]));
227 m_tilt.setAngularVelocity(
static_cast<float>(q_dot_sat[1]));
241 std::cout <<
"Switch from velocity to position control." << std::endl;
258 m_pan.stopVelocityCmd();
259 m_tilt.stopVelocityCmd();
282 q[0] = m_pan.getAngularPosition();
283 q[1] = m_tilt.getAngularPosition();
286#elif !defined(VISP_BUILD_SHARED_LIBS)
288void dummy_vpRobotPololuPtu() { }
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
static double rad(double deg)
Implementation of a matrix and operations on matrices.
Error that can be emitted by the vpRobot class and its derivatives.
@ wrongStateError
Wrong robot state.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot) VP_OVERRIDE
void getPosition(const vpRobot::vpControlFrameType frame, vpColVector &q) VP_OVERRIDE
void get_eJe(vpMatrix &eJe) VP_OVERRIDE
~vpRobotPololuPtu() VP_OVERRIDE
vpRobotPololuPtu(const std::string &device="/dev/ttyACM0", int baudrate=9600, bool verbose=false)
vpRobot::vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState) VP_OVERRIDE
float getAngularVelocityResolution() const
void setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &q) VP_OVERRIDE
void get_fJe(vpMatrix &fJe) VP_OVERRIDE
int nDof
number of degrees of freedom
vpMatrix eJe
robot Jacobian expressed in the end-effector frame
virtual vpRobotStateType getRobotState(void) const
@ STATE_POSITION_CONTROL
Initialize the position controller.
@ STATE_VELOCITY_CONTROL
Initialize the velocity controller.
@ STATE_STOP
Stops robot motion especially in velocity and acceleration control.
double getMaxRotationVelocity(void) const
vpMatrix fJe
robot Jacobian expressed in the robot reference frame available
virtual vpRobotStateType setRobotState(const vpRobot::vpRobotStateType newState)