42 #include <visp/vpConfig.h>
43 #include <visp/vpRobotCycab.h>
45 #ifdef VISP_HAVE_CYCAB
55 vpRobotCycab::vpRobotCycab()
57 #ifdef VISP_HAVE_CYCABTK_OLD
61 sprintf(servername,
"cycab-hf1");
62 cycab =
new EtherCycab(servername, <R);
63 if (!cycab->doInitialization(&end, 50, 0,
false)) {
64 printf(
"ERROR: Can't connect to %s\n", servername);
67 cycab->releaseSecurity();
68 printf(
"Control limits : phi in [%f:%f], V in [%f:%f]\n",
69 cycab->minAllowedSteering(),
70 cycab->maxAllowedSteering(),
71 cycab->minAllowedSpeed(),
72 cycab->maxAllowedSpeed());
73 #elif defined VISP_HAVE_CYCABTK
75 std::string name =
"cycab";
76 CycabCarCommand cycab_command;
77 setDualSteering(
false);
79 cycab_commandId = store.lookupVariable( name + cycabCarCommandSuffix );
80 cycab_stateId = store.lookupVariable( name + cycabStateSuffix );
81 store.writeVariable( cycab_commandId, cycab_command );
88 vpRobotCycab::~vpRobotCycab()
90 #ifdef VISP_HAVE_CYCABTK_OLD
91 if (cycab != NULL)
delete cycab;
103 void vpRobotCycab::setDualSteering(
bool dual)
114 void vpRobotCycab::setCommand(
double v,
double phi)
116 #ifdef VISP_HAVE_CYCABTK_OLD
118 cycab->sendCommands(v, phi);
119 #elif defined VISP_HAVE_CYCABTK
121 CycabCarCommand cycab_command;
122 store.readVariable( cycab_commandId, cycab_command );
124 cycab_command.phi = phi;
125 cycab_command.manualDriving =
false;
126 cycab_command.dualSteering = dualSteering;
127 store.writeVariable( cycab_commandId, cycab_command );
140 void vpRobotCycab::getOdometry(
double &vmean,
double &phi)
143 getOdometry(vmean, phi, timestamp);
157 void vpRobotCycab::getOdometry(
double &vmean,
double &phi,
double ×tamp)
163 #ifdef VISP_HAVE_CYCABTK_OLD
166 double dsl,dsr,lphi,ltime;
168 cycab->getState(&rec, &dsl, &dsr, &lphi, <ime);
172 vmean = (rec.vmsec[REAR][LEFT] + rec.vmsec[REAR][RIGHT])*0.5;
175 #elif defined VISP_HAVE_CYCABTK
177 CycabState cycab_state;
178 store.readVariable(cycab_stateId, cycab_state);
179 vmean = (cycab_state.v_rear_left + cycab_state.v_rear_right)*0.5;
181 phi = cycab_state.phi_front;
182 timeval tp = store.getTimestamp(cycab_stateId);
183 timestamp = 1000.0*tp.tv_sec + tp.tv_usec/1000.0;
197 void vpRobotCycab::getOdometry(
double &vfl,
double &vfr,
198 double &vrl,
double &vrr,
202 getOdometry(vfl, vfr, vrl, vrr, phi, timestamp);
218 void vpRobotCycab::getOdometry(
double &vfl,
double &vfr,
219 double &vrl,
double &vrr,
220 double &phi,
double ×tamp)
222 vfr = vfr = vrl = vrr = 0.;
226 #ifdef VISP_HAVE_CYCABTK_OLD
229 double dsl,dsr,lphi,ltime;
231 cycab->getState(&rec, &dsl, &dsr, &lphi, <ime);
235 vfl = rec.vmsec[FRONT][LEFT];
236 vfr = rec.vmsec[FRONT][RIGHT];
237 vrl = rec.vmsec[REAR][LEFT];
238 vrr = rec.vmsec[REAR][RIGHT];
241 #elif defined VISP_HAVE_CYCABTK
243 CycabState cycab_state;
244 store.readVariable(cycab_stateId, cycab_state);
245 vfl = cycab_state.v_front_left;
246 vfr = cycab_state.v_front_right;
247 vrl = cycab_state.v_rear_left;
248 vrr = cycab_state.v_rear_right;
250 phi = cycab_state.phi_front;
251 timeval tp = store.getTimestamp(cycab_stateId);
252 timestamp = 1000.0*tp.tv_sec + tp.tv_usec/1000.0;
262 void vpRobotCycab::getJoystickPosition(
double &x,
double &y)
265 getJoystickPosition(x, y, timestamp);
276 void vpRobotCycab::getJoystickPosition(
double &x,
double &y,
double ×tamp)
278 #ifdef VISP_HAVE_CYCABTK_OLD
283 #elif defined VISP_HAVE_CYCABTK
285 CycabState cycab_state;
286 store.readVariable(cycab_stateId, cycab_state);
287 x = cycab_state.joy_x;
288 y = cycab_state.joy_y;
289 timeval tp = store.getTimestamp(cycab_stateId);
290 timestamp = 1000.0*tp.tv_sec + tp.tv_usec/1000.0;