44 carmen_ipc_initialize(1,(
char **)&name);
55 err = IPC_defineMsg(CARMEN_LOCALIZE_GLOBALPOS_NAME, IPC_VARIABLE_LENGTH,
56 CARMEN_LOCALIZE_GLOBALPOS_FMT);
57 carmen_test_ipc_exit(err,
"Could not define", CARMEN_LOCALIZE_GLOBALPOS_NAME);
60 err = IPC_defineMsg(CARMEN_LOCALIZE_PARTICLE_NAME, IPC_VARIABLE_LENGTH,
61 CARMEN_LOCALIZE_PARTICLE_FMT);
62 carmen_test_ipc_exit(err,
"Could not define", CARMEN_LOCALIZE_PARTICLE_NAME);
107 carmen_robot_subscribe_frontlaser_message(NULL, (carmen_handler_t)robot_frontlaser_handler, CARMEN_SUBSCRIBE_LATEST);
108 carmen_robot_subscribe_rearlaser_message(NULL, (carmen_handler_t)robot_rearlaser_handler, CARMEN_SUBSCRIBE_LATEST);
109 carmen_simulator_subscribe_truepos_message(NULL,(carmen_handler_t) simulator_truepos_handler, CARMEN_SUBSCRIBE_LATEST);
113 err = IPC_subscribe(CARMEN_NAVIGATOR_GO_NAME, navigator_go_handler, NULL);
114 carmen_test_ipc_exit(err,
"Could not subscribe",
115 CARMEN_NAVIGATOR_GO_NAME);
116 IPC_setMsgQueueLength(CARMEN_NAVIGATOR_GO_NAME, 1);
118 err = IPC_subscribe(CARMEN_NAVIGATOR_STOP_NAME, navigator_stop_handler, NULL);
119 carmen_test_ipc_exit(err,
"Could not subscribe",
120 CARMEN_NAVIGATOR_STOP_NAME);
121 IPC_setMsgQueueLength(CARMEN_NAVIGATOR_STOP_NAME, 1);
125 signal(SIGINT, shutdown_module);
126 pthread_mutex_init(&m_mutex, 0);
127 pthread_mutex_init(&m_lock, 0);
128 sem_init(&m_dequeSem, 0, 0);
129 m_threadRunning=
true;
130 pthread_create (&m_readingThread,0,m_reading_function,0);
136 pthread_mutex_lock(&m_lock);
141 pthread_mutex_unlock(&m_lock);
146 pthread_mutex_lock(&m_mutex);
147 bool smok=m_frontLaser;
148 pthread_mutex_unlock(&m_mutex);
157 return m_threadRunning;
166 pthread_mutex_lock(&m_mutex);
167 ql=m_rangeDeque.size();
168 pthread_mutex_unlock(&m_mutex);
178 sem_wait(&m_dequeSem);
179 pthread_mutex_lock(&m_mutex);
180 if (!m_rangeDeque.empty()){
182 reading=m_rangeDeque.front();
183 m_rangeDeque.pop_front();
187 sem_getvalue(&m_dequeSem,&sval);
189 pthread_mutex_unlock(&m_mutex);
194 pthread_mutex_lock(&m_mutex);
195 m_rangeDeque.push_back(reading);
196 pthread_mutex_unlock(&m_mutex);
197 sem_post(&m_dequeSem);
199 sem_getvalue(&m_dequeSem,&sval);
266 carmen_navigator_go_message msg;
267 FORMATTER_PTR formatter;
270 formatter = IPC_msgInstanceFormatter(msgRef);
271 err = IPC_unmarshallData(formatter, callData, &msg,
272 sizeof(carmen_navigator_go_message));
273 IPC_freeByteArray(callData);
275 carmen_test_ipc_return
276 (err,
"Could not unmarshall", IPC_msgInstanceName(msgRef));
283 carmen_navigator_stop_message msg;
284 FORMATTER_PTR formatter;
287 formatter = IPC_msgInstanceFormatter(msgRef);
288 err = IPC_unmarshallData(formatter, callData, &msg,
289 sizeof(carmen_navigator_stop_message));
290 IPC_freeByteArray(callData);
292 carmen_test_ipc_return
293 (err,
"Could not unmarshall", IPC_msgInstanceName(msgRef));
301 m_truepos.x=truepos->truepose.x;
302 m_truepos.y=truepos->truepose.y;
303 m_truepos.theta=truepos->truepose.theta;
308 double dth=msg.laser_pose.theta-msg.robot_pose.theta;
309 dth=atan2(sin(dth), cos(dth));
311 if (msg.laser_pose.theta==msg.robot_pose.theta && !m_frontLaser){
313 res = msg.config.angular_resolution;
319 string sensorName=
"FLASER";
320 OrientedPoint rpose(msg.robot_pose.x, msg.robot_pose.y, msg.robot_pose.theta);
321 OrientedPoint lpose(msg.laser_pose.x, msg.laser_pose.y, msg.laser_pose.theta);
323 m_frontLaser=
new RangeSensor(sensorName,msg.num_readings, res,
OrientedPoint(0,0,msg.laser_pose.theta-msg.robot_pose.theta), 0,
324 msg.config.maximum_range);
325 m_frontLaser->updateBeamsLookup();
326 m_sensorMap.insert(make_pair(sensorName, m_frontLaser));
328 cout << __PRETTY_FUNCTION__
329 <<
": " << sensorName <<
" configured." 330 <<
" Readings " << m_frontLaser->beams().size()
331 <<
" Resolution " << res << endl;
333 if (msg.laser_pose.theta!=msg.robot_pose.theta && !m_rearLaser){
335 res = msg.config.angular_resolution;
341 OrientedPoint rpose(msg.robot_pose.x, msg.robot_pose.y, msg.robot_pose.theta);
342 OrientedPoint lpose(msg.laser_pose.x, msg.laser_pose.y, msg.laser_pose.theta);
344 string sensorName=
"RLASER";
345 m_rearLaser=
new RangeSensor(sensorName,msg.num_readings, res,
OrientedPoint(0,0,msg.laser_pose.theta-msg.robot_pose.theta), 0,
346 msg.config.maximum_range);
347 m_rearLaser->updateBeamsLookup();
348 m_sensorMap.insert(make_pair(sensorName, m_rearLaser));
350 cout << __PRETTY_FUNCTION__
351 <<
": " << sensorName <<
" configured." 352 <<
" Readings " << m_rearLaser->beams().size()
353 <<
" Resolution " << res << endl;
356 const RangeSensor * rs=(msg.laser_pose.theta==msg.robot_pose.theta)?m_frontLaser:m_rearLaser;
358 reading.resize(rs->
beams().size());
359 for (
unsigned int i=0; i< (
unsigned int)msg.num_readings; i++){
360 reading[i]=(double)msg.range[i];
369 static carmen_localize_globalpos_message globalpos;
372 globalpos.timestamp = carmen_get_time();
373 globalpos.host = carmen_get_host();
374 globalpos.globalpos = summary->mean;
375 globalpos.globalpos_std = summary->std;
376 globalpos.globalpos_xy_cov = summary->xy_cov;
377 globalpos.odometrypos = summary->odometry_pos;
378 globalpos.converged = summary->converged;
379 err = IPC_publishData(CARMEN_LOCALIZE_GLOBALPOS_NAME, &globalpos);
380 carmen_test_ipc_exit(err,
"Could not publish",
381 CARMEN_LOCALIZE_GLOBALPOS_NAME);
388 carmen_localize_summary_p summary)
391 static carmen_localize_particle_message pmsg;
394 pmsg.timestamp = carmen_get_time();
395 pmsg.host = carmen_get_host();
396 pmsg.globalpos = summary->mean;
397 pmsg.globalpos_std = summary->mean;
398 pmsg.num_particles = filter->param->num_particles;
399 pmsg.particles = (carmen_localize_particle_ipc_p)filter->particles;
400 err = IPC_publishData(CARMEN_LOCALIZE_PARTICLE_NAME, &pmsg);
401 carmen_test_ipc_exit(err,
"Could not publish",
402 CARMEN_LOCALIZE_PARTICLE_NAME);
403 fprintf(stderr,
"P");
423 carmen_ipc_disconnect();
425 fprintf(stderr,
"\nDisconnecting (shutdown_module(%d) called).\n",sig);
445 carmen_robot_laser_message frontlaser;
446 frontlaser.num_readings=reading.size();
447 frontlaser.range =
new float[frontlaser.num_readings];
448 frontlaser.tooclose=0;
449 frontlaser.laser_pose.x=frontlaser.robot_pose.x=reading.
getPose().
x;
450 frontlaser.laser_pose.y=frontlaser.robot_pose.y=reading.
getPose().
y;
451 frontlaser.laser_pose.theta=frontlaser.robot_pose.theta=reading.
getPose().
theta;
452 frontlaser.tv=frontlaser.rv=0;
453 frontlaser.forward_safety_dist=frontlaser.side_safety_dist=0;
454 frontlaser.turn_axis=0;
455 frontlaser.timestamp=reading.
getTime();
456 for (
unsigned int i=0; i< reading.size(); i++){
457 frontlaser.range[i]=(float)reading[i];
463 return (carmen_point_t){p.
x,p.
y,p.
theta};
static carmen_point_t point2carmen(const OrientedPoint &p)
static SensorMap m_sensorMap
static OrientedPoint carmen2point(const carmen_point_t &p)
static carmen_robot_laser_message reading2carmen(const RangeReading &reading)
static pthread_mutex_t m_mutex
static void robot_rearlaser_handler(carmen_robot_laser_message *frontlaser)
static OrientedPoint getTruePos()
static RangeSensor * m_frontLaser
static std::deque< RangeReading > m_rangeDeque
static void addReading(RangeReading &reading)
const OrientedPoint & getPose() const
static void initializeIPC(const char *name)
static void navigator_stop_handler(MSG_INSTANCE msgRef, BYTE_ARRAY callData, void *)
orientedpoint< T, A > absoluteDifference(const orientedpoint< T, A > &p1, const orientedpoint< T, A > &p2)
static void robot_frontlaser_handler(carmen_robot_laser_message *frontlaser)
static void * m_reading_function(void *)
static pthread_mutex_t m_lock
static bool sensorMapComputed()
static bool start(const char *name)
static void navigator_go_handler(MSG_INSTANCE msgRef, BYTE_ARRAY callData, void *)
std::map< std::string, Sensor * > SensorMap
static bool m_threadRunning
static RangeSensor * m_rearLaser
void setPose(const OrientedPoint &pose)
static void shutdown_module(int sig)
static void publish_globalpos(carmen_localize_summary_p summary)
static const SensorMap & sensorMap()
static void simulator_truepos_handler(carmen_simulator_truepos_message *truepos)
static void publish_particles(carmen_localize_particle_filter_p filter, carmen_localize_summary_p summary)
static int registerLocalizationMessages()
static RangeReading carmen2reading(const carmen_robot_laser_message &msg)
static bool getReading(RangeReading &reading)
static pthread_t m_readingThread
static OrientedPoint m_truepos
const std::vector< Beam > & beams() const
orientedpoint< double, double > OrientedPoint