36 #if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
39 #include <visp3/core/vpConfig.h>
41 #ifndef DOXYGEN_SHOULD_SKIP_THIS
42 #ifdef VISP_HAVE_BICLOPS
45 #include <visp3/robot/vpRobotBiclops.h>
46 #include <visp3/robot/vpRobotBiclopsController.h>
47 #include <visp3/robot/vpRobotException.h>
52 #include <visp3/core/vpDebug.h>
54 vpRobotBiclopsController::vpRobotBiclopsController()
55 : m_biclops(), m_axisMask(0), m_panAxis(NULL), m_tiltAxis(NULL), m_vergeAxis(NULL), m_panProfile(), m_tiltProfile(),
56 m_vergeProfile(), m_shm(), m_stopControllerThread(false)
58 m_axisMask = Biclops::PanMask + Biclops::TiltMask;
63 m_biclops.SetDebugLevel(0);
67 m_shm.status[i] = STOP;
69 m_shm.actual_q[i] = 0.;
70 m_shm.jointLimit[i] =
false;
71 m_shm.status[i] = STOP;
75 vpRobotBiclopsController::~vpRobotBiclopsController() { }
77 void vpRobotBiclopsController::init(
const std::string &configfile)
81 for (
int i = 0; i < 1; i++) {
83 std::cout <<
"Try to initialize Biclops head " << std::endl;
84 binit = m_biclops.Initialize(configfile.c_str());
88 std::cout <<
"Initialization succeed...\n";
92 std::cout <<
"Initialization failed...\n";
96 std::cout <<
"Initialization failed..." << std::endl;
101 std::cout <<
"Cannot initialize Biclops head. " << std::endl;
102 std::cout <<
"Check if the serial cable is connected." << std::endl;
103 std::cout <<
"Check if the robot is powered on." << std::endl;
104 std::cout <<
"Check if you try to open the good serial port." << std::endl;
105 std::cout <<
"Try to power off/on and restart..." << std::endl;
113 m_panAxis = m_biclops.GetAxis(Biclops::Pan);
114 m_tiltAxis = m_biclops.GetAxis(Biclops::Tilt);
115 if ((m_axisMask & Biclops::VergeMask) != 0)
116 m_vergeAxis = m_biclops.GetAxis(Biclops::Verge);
118 #ifdef VISP_HAVE_BICLOPS_AND_GET_HOMED_STATE_FUNCTION
119 if (!m_panAxis->GetHomedState() || !m_tiltAxis->GetHomedState()) {
123 if (!m_panAxis->IsAlreadyHomed() || !m_tiltAxis->IsAlreadyHomed()) {
129 vpDEBUG_TRACE(12,
"Execute the homing sequence for all axes");
130 vpDEBUG_TRACE(12,
"Execute the homing sequence for all axes");
131 if (m_biclops.HomeAxes(m_axisMask))
140 m_panAxis->GetProfile(m_panProfile);
141 m_tiltAxis->GetProfile(m_tiltProfile);
142 if ((m_axisMask & Biclops::VergeMask) != 0)
143 m_vergeAxis->GetProfile(m_vergeProfile);
146 void vpRobotBiclopsController::setPosition(
const vpColVector &q,
double percentVelocity)
153 m_panAxis->SetProfileMode(PMDTrapezoidalProfile);
154 m_tiltAxis->SetProfileMode(PMDTrapezoidalProfile);
157 PMDUtils::AxisList axisList;
158 axisList.push_back(m_panAxis);
159 axisList.push_back(m_tiltAxis);
161 #ifdef VISP_HAVE_BICLOPS_AND_GET_HOMED_STATE_FUNCTION
164 m_panAxis->GetProfile(m_panProfile);
165 m_tiltAxis->GetProfile(m_tiltProfile);
170 m_panProfile.pos = PMDUtils::RadsToRevs(q[0]);
173 m_tiltProfile.pos = PMDUtils::RadsToRevs(q[1]);
177 m_panAxis->SetProfile(m_panProfile);
178 m_tiltAxis->SetProfile(m_tiltProfile);
182 PMDAxisControl::CountsProfile desired_profile;
187 m_panProfile.pos = PMDUtils::RadsToRevs(q[0]);
192 m_panAxis->ProfileToCounts(m_panProfile, desired_profile);
193 vpCDEBUG(12) <<
"desired_profile.pos: " << desired_profile.pos << std::endl;
194 vpCDEBUG(12) <<
"desired_profile.vel: " << desired_profile.vel << std::endl;
196 m_panAxis->SetProfile(desired_profile);
201 m_tiltProfile.pos = PMDUtils::RadsToRevs(q[1]);
204 m_tiltAxis->ProfileToCounts(m_tiltProfile, desired_profile);
205 vpCDEBUG(12) <<
"desired_profile.pos: " << desired_profile.pos << std::endl;
206 vpCDEBUG(12) <<
"desired_profile.vel: " << desired_profile.vel << std::endl;
208 m_tiltAxis->SetProfile(desired_profile);
212 PMDUtils::Coordinate(axisList);
213 m_biclops.Move(Biclops::PanMask + Biclops::TiltMask );
216 void vpRobotBiclopsController::setVelocity(
const vpColVector &q_dot)
223 #ifdef VISP_HAVE_BICLOPS_AND_GET_HOMED_STATE_FUNCTION
226 m_panAxis->GetProfile(m_panProfile);
227 m_tiltAxis->GetProfile(m_tiltProfile);
232 m_panProfile.vel = PMDUtils::RadsToRevs(q_dot[0]);
233 m_tiltProfile.vel = PMDUtils::RadsToRevs(q_dot[1]);
236 m_panAxis->SetProfile(m_panProfile);
237 m_tiltAxis->SetProfile(m_tiltProfile);
239 m_panAxis->SetProfileMode(PMDVelocityContouringProfile);
240 m_tiltAxis->SetProfileMode(PMDVelocityContouringProfile);
242 m_panAxis->SetProfileMode(PMDVelocityContouringProfile);
243 m_tiltAxis->SetProfileMode(PMDVelocityContouringProfile);
245 PMDAxisControl::CountsProfile desired_profile;
250 m_panProfile.vel = PMDUtils::RadsToRevs(q_dot[0]);
252 m_panAxis->ProfileToCounts(m_panProfile, desired_profile);
253 m_panAxis->SetProfile(desired_profile);
258 m_tiltProfile.vel = PMDUtils::RadsToRevs(q_dot[1]);
260 m_tiltAxis->ProfileToCounts(m_tiltProfile, desired_profile);
261 m_tiltAxis->SetProfile(desired_profile);
264 m_biclops.Move(Biclops::PanMask + Biclops::TiltMask, 0);
267 vpColVector vpRobotBiclopsController::getPosition()
269 vpDEBUG_TRACE(12,
"Start vpRobotBiclopsController::getPosition() ");
271 PMDint32 panpos, tiltpos;
273 m_panAxis->GetPosition(panpos);
274 m_tiltAxis->GetPosition(tiltpos);
276 q[0] = PMDUtils::RevsToRads(m_panAxis->CountsToUnits(panpos));
277 q[1] = PMDUtils::RevsToRads(m_tiltAxis->CountsToUnits(tiltpos));
279 vpCDEBUG(11) <<
"++++++++ Mesure : " << q.
t();
280 vpDEBUG_TRACE(12,
"End vpRobotBiclopsController::getPosition()");
285 vpColVector vpRobotBiclopsController::getActualPosition()
288 PMDint32 panpos, tiltpos;
290 m_panAxis->GetActualPosition(panpos);
291 m_tiltAxis->GetActualPosition(tiltpos);
293 q[0] = PMDUtils::RevsToRads(m_panAxis->CountsToUnits(panpos));
294 q[1] = PMDUtils::RevsToRads(m_tiltAxis->CountsToUnits(tiltpos));
299 vpColVector vpRobotBiclopsController::getVelocity()
302 PMDint32 pan_vel, tilt_vel;
304 m_panAxis->GetVelocity(pan_vel);
305 m_tiltAxis->GetVelocity(tilt_vel);
307 q_dot[0] = PMDUtils::RevsToRads(m_panAxis->CountsToUnits(pan_vel));
308 q_dot[1] = PMDUtils::RevsToRads(m_tiltAxis->CountsToUnits(tilt_vel));
313 vpColVector vpRobotBiclopsController::getActualVelocity()
316 PMDint32 pan_vel, tilt_vel;
318 m_panAxis->GetActualVelocity(pan_vel);
319 m_tiltAxis->GetActualVelocity(tilt_vel);
321 q_dot[0] = PMDUtils::RevsToRads(m_panAxis->CountsToUnits(pan_vel));
322 q_dot[1] = PMDUtils::RevsToRads(m_tiltAxis->CountsToUnits(tilt_vel));
327 void vpRobotBiclopsController::writeShm(shmType &shm)
332 memcpy(&this->m_shm, &shm,
sizeof(shmType));
338 vpRobotBiclopsController::shmType vpRobotBiclopsController::readShm()
345 memcpy(&tmp_shm, &this->m_shm,
sizeof(shmType));
347 vpDEBUG_TRACE(13,
"tmp_shm.q_dot[%d]=%f", i, tmp_shm.q_dot[i]);
353 #elif !defined(VISP_BUILD_SHARED_LIBS)
356 void dummy_vpRobotBiclopsController() { };
unsigned int getRows() const
static const float speedLimit
Pan and tilt axis max velocity in rad/s to perform a displacement.
static const unsigned int ndof
Number of dof.
Implementation of column vector and the associated operations.
Error that can be emitted by the vpRobot class and its derivatives.
@ constructionError
Error from constructor.
@ notInitializedError
Cannot initialize the robot.
@ lowLevelError
Error thrown by the low level sdk.