2 * RobomonAtlantis.cpp 07/10/31
4 * Robot`s visualization and control GUI for robot of the
5 * Eurobot 2008 (Mission to Mars).
7 * Copyright: (c) 2008 CTU Dragons
8 * CTU FEE - Department of Control Engineering
9 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
10 * License: GNU GPL v.2
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
27 #include <path_planner.h>
34 #include <actuators.h>
35 #include "PlaygroundScene.h"
37 #include "robomon_orte.h"
38 #include "RobomonAtlantis.h"
39 #include "playgroundview.h"
42 #include <QCoreApplication>
46 #include <QMessageBox>
48 RobomonAtlantis::RobomonAtlantis(QStatusBar *_statusBar)
49 : QWidget(0), statusBar(_statusBar)
55 debugWindowEnabled = false;
60 QHBoxLayout *mainLayout = new QHBoxLayout;
61 mainLayout->addLayout(leftLayout);
62 mainLayout->addLayout(rightLayout);
63 setLayout(mainLayout);
70 // connect(vidle, SIGNAL(valueChanged(int)),
71 // robotEstPosBest, SLOT(setVidle(int)));
73 setFocusPolicy(Qt::StrongFocus);
74 sharedMemoryOpened = false;
75 WDBG("Youuuhouuuu!!");
78 /**********************************************************************
80 **********************************************************************/
81 void RobomonAtlantis::createLeftLayout()
83 leftLayout = new QVBoxLayout();
85 createDebugGroupBox();
86 debugWindowEnabled = true;
87 createPlaygroundGroupBox();
88 leftLayout->addWidget(playgroundGroupBox);
89 //leftLayout->addWidget(debugGroupBox); // FIXME: move this to separate tab
92 void RobomonAtlantis::createRightLayout()
94 rightLayout = new QVBoxLayout();
96 createPositionGroupBox();
99 createActuatorsGroupBox();
100 createPowerGroupBox();
102 rightLayout->addWidget(positionGroupBox);
103 rightLayout->addWidget(miscGroupBox);
104 rightLayout->addWidget(fsmGroupBox);
105 rightLayout->addWidget(powerGroupBox);
106 rightLayout->addWidget(actuatorsGroupBox);
109 void RobomonAtlantis::createPlaygroundGroupBox()
111 playgroundGroupBox = new QGroupBox(tr("Playground"));
112 QHBoxLayout *layout = new QHBoxLayout();
114 playgroundScene = new PlaygroundScene();
115 playgroundSceneView = new PlaygroundView(playgroundScene);
116 //playgroundSceneView->setMinimumWidth(630);
117 //playgroundSceneView->setMinimumHeight(445);
118 playgroundSceneView->setMatrix(QMatrix(1,0,0,-1,0,0), true);
119 playgroundSceneView->fitInView(playgroundScene->itemsBoundingRect());
120 playgroundSceneView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
121 playgroundSceneView->setMouseTracking(true);
122 layout->addWidget(playgroundSceneView);
124 playgroundGroupBox->setLayout(layout);
127 void RobomonAtlantis::createPositionGroupBox()
129 positionGroupBox = new QGroupBox(tr("Position state"));
130 positionGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
131 QGridLayout *layout = new QGridLayout();
133 actPosX = new QLineEdit();
134 actPosY = new QLineEdit();
135 actPosPhi = new QLineEdit();
137 estPosX = new QLineEdit();
138 estPosY = new QLineEdit();
139 estPosPhi = new QLineEdit();
141 actPosX->setReadOnly(true);
142 actPosY->setReadOnly(true);
143 actPosPhi->setReadOnly(true);
145 estPosX->setReadOnly(true);
146 estPosY->setReadOnly(true);
147 estPosPhi->setReadOnly(true);
149 layout->addWidget(MiscGui::createLabel("X"), 1, 0);
150 layout->addWidget(MiscGui::createLabel("Y"), 2, 0);
151 layout->addWidget(MiscGui::createLabel("Phi"), 3, 0);
153 layout->addWidget(MiscGui::createLabel("X"), 5, 0);
154 layout->addWidget(MiscGui::createLabel("Y"), 6, 0);
155 layout->addWidget(MiscGui::createLabel("Phi"), 7, 0);
157 layout->addWidget(MiscGui::createLabel("Reference", Qt::AlignLeft), 0, 1);
158 layout->addWidget(actPosX, 1, 1);
159 layout->addWidget(actPosY, 2, 1);
160 layout->addWidget(actPosPhi, 3, 1);
162 layout->addWidget(MiscGui::createLabel("Estimated (indep. odo.)", Qt::AlignLeft), 4, 1);
163 layout->addWidget(estPosX, 5, 1);
164 layout->addWidget(estPosY, 6, 1);
165 layout->addWidget(estPosPhi, 7, 1);
167 positionGroupBox->setLayout(layout);
170 void RobomonAtlantis::createMiscGroupBox()
172 miscGroupBox = new QGroupBox(tr("Miscellaneous"));
173 miscGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
174 QGridLayout *layout = new QGridLayout();
176 obstacleSimulationCheckBox = new QCheckBox(tr("&Obstacle simulation"));
177 obstacleSimulationCheckBox->setShortcut(tr("o"));
178 layout->addWidget(obstacleSimulationCheckBox);
180 // startPlug = new QCheckBox("&Start plug");
181 // layout->addWidget(startPlug);
182 miscGroupBox->setLayout(layout);
185 void RobomonAtlantis::createFSMGroupBox()
187 fsmGroupBox = new QGroupBox(tr("FSM"));
188 fsmGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
189 QGridLayout *layout = new QGridLayout();
191 layout->addWidget(MiscGui::createLabel("Main:"), 1, 0);
192 fsm_main_state = new QLabel();
193 fsm_main_state->setMinimumWidth(100);
194 fsm_main_state->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
195 layout->addWidget(fsm_main_state, 1, 1);
197 layout->addWidget(MiscGui::createLabel("Act:"), 2, 0);
198 fsm_act_state = new QLabel();
199 layout->addWidget(fsm_act_state, 2, 1);
201 layout->addWidget(MiscGui::createLabel("Motion:"), 3, 0);
202 fsm_motion_state = new QLabel();
203 layout->addWidget(fsm_motion_state, 3, 1);
205 fsmGroupBox->setLayout(layout);
208 void RobomonAtlantis::createDebugGroupBox()
210 debugGroupBox = new QGroupBox(tr("Debug window"));
211 debugGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
212 QHBoxLayout *layout = new QHBoxLayout();
214 debugWindow = new QTextEdit();
215 debugWindow->setReadOnly(true);
217 layout->addWidget(debugWindow);
218 debugGroupBox->setLayout(layout);
221 void RobomonAtlantis::createActuatorsGroupBox()
223 actuatorsGroupBox = new QGroupBox(tr("Actuators"));
224 actuatorsGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
225 QHBoxLayout *layout = new QHBoxLayout();
226 // vidle = new QDial();
228 // vidle->setMinimum(VIDLE_VYSIP);
229 // vidle->setMaximum((VIDLE_UP-VIDLE_VYSIP)+VIDLE_VYSIP);
230 // vidle->setEnabled(true);
232 //createMotorsGroupBox();
234 layout->setAlignment(Qt::AlignLeft);
235 // layout->addWidget(vidle);
236 //layout->addWidget(enginesGroupBox);
237 actuatorsGroupBox->setLayout(layout);
240 void RobomonAtlantis::createPowerGroupBox()
242 powerGroupBox = new QGroupBox(tr("Power management"));
243 powerGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
244 QGridLayout *layout = new QGridLayout();
246 voltage33CheckBox = new QCheckBox(tr("&3.3V"));
247 voltage50CheckBox = new QCheckBox(tr("&5.0V"));
248 voltage80CheckBox = new QCheckBox(tr("&8.0V"));
250 voltage33CheckBox->setShortcut(tr("3"));
251 voltage50CheckBox->setShortcut(tr("5"));
252 voltage80CheckBox->setShortcut(tr("8"));
254 layout->addWidget(voltage33CheckBox, 0, 0);
255 layout->addWidget(voltage50CheckBox, 1, 0);
256 layout->addWidget(voltage80CheckBox, 2, 0);
257 layout->addWidget(MiscGui::createLabel("BAT"), 3, 0);
259 voltage33LineEdit = new QLineEdit();
260 voltage50LineEdit = new QLineEdit();
261 voltage80LineEdit = new QLineEdit();
262 voltageBATLineEdit = new QLineEdit();
264 voltage33LineEdit->setReadOnly(true);
265 voltage50LineEdit->setReadOnly(true);
266 voltage80LineEdit->setReadOnly(true);
267 voltageBATLineEdit->setReadOnly(true);
269 layout->addWidget(voltage33LineEdit, 0, 1);
270 layout->addWidget(voltage50LineEdit, 1, 1);
271 layout->addWidget(voltage80LineEdit, 2, 1);
272 layout->addWidget(voltageBATLineEdit, 3, 1);
274 powerGroupBox->setLayout(layout);
277 void RobomonAtlantis::createRobots()
279 robotRefPos = new Robot("Ref", QPen(Qt::darkBlue), QBrush(Qt::NoBrush));
280 robotRefPos->setZValue(11);
281 trailRefPos = new Trail(QPen(Qt::darkBlue));
282 trailRefPos->setZValue(11);
284 robotEstPosBest = new Robot("Est", QPen(), QBrush(Qt::darkGray));
285 robotEstPosBest->setZValue(10);
286 trailEstPosBest = new Trail(QPen());
287 trailEstPosBest->setZValue(10);
289 robotEstPosOdo = new Robot("Mot", QPen(Qt::white), QBrush(Qt::darkRed));
290 robotEstPosOdo->setZValue(10);
291 trailOdoPos = new Trail(QPen(Qt::red));
292 trailOdoPos->setZValue(10);
294 robotEstPosIndepOdo = new Robot("Odo", QPen(Qt::white), QBrush(Qt::darkGreen));
295 robotEstPosIndepOdo->setZValue(10);
296 trailPosIndepOdo = new Trail(QPen(Qt::green));
297 trailPosIndepOdo->setZValue(10);
299 playgroundScene->addItem(robotRefPos);
300 playgroundScene->addItem(robotEstPosBest);
301 playgroundScene->addItem(robotEstPosIndepOdo);
302 playgroundScene->addItem(robotEstPosOdo);
306 playgroundScene->addItem(trailRefPos);
307 playgroundScene->addItem(trailPosIndepOdo);
308 playgroundScene->addItem(trailOdoPos);
310 hokuyoScan = new HokuyoScan();
311 hokuyoScan->setZValue(10);
312 playgroundScene->addItem(hokuyoScan);
316 void RobomonAtlantis::createMap()
318 mapImage = new Map();
319 mapImage->setZValue(3);
320 mapImage->setTransform(QTransform().scale(MAP_CELL_SIZE_MM, MAP_CELL_SIZE_MM), true);
323 playgroundScene->addItem(mapImage);
326 /**********************************************************************
328 **********************************************************************/
329 void RobomonAtlantis::createActions()
331 /* power management */
332 connect(voltage33CheckBox, SIGNAL(stateChanged(int)),
333 this, SLOT(setVoltage33(int)));
334 connect(voltage50CheckBox, SIGNAL(stateChanged(int)),
335 this, SLOT(setVoltage50(int)));
336 connect(voltage80CheckBox, SIGNAL(stateChanged(int)),
337 this, SLOT(setVoltage80(int)));
340 // connect(leftMotorSlider, SIGNAL(valueChanged(int)),
341 // this, SLOT(setLeftMotor(int)));
342 // connect(rightMotorSlider, SIGNAL(valueChanged(int)),
343 // this, SLOT(setRightMotor(int)));
344 // connect(stopMotorsPushButton, SIGNAL(clicked()),
345 // this, SLOT(stopMotors()));
347 // connect(startPlug, SIGNAL(stateChanged(int)), this, SLOT(sendStart(int)));
349 /* obstacle simulation */
350 simulationEnabled = 0;
351 connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
352 this, SLOT(setSimulation(int)));
353 connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
354 this, SLOT(setObstacleSimulation(int)));
355 connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
356 playgroundScene, SLOT(showObstacle(int)));
357 connect(playgroundScene, SIGNAL(obstacleChanged(QPointF)),
358 this, SLOT(changeObstacle(QPointF)));
361 void RobomonAtlantis::setVoltage33(int state)
364 orte.pwr_ctrl.voltage33 = true;
366 orte.pwr_ctrl.voltage33 = false;
369 void RobomonAtlantis::setVoltage50(int state)
372 orte.pwr_ctrl.voltage50 = true;
374 orte.pwr_ctrl.voltage50 = false;
377 void RobomonAtlantis::setVoltage80(int state)
380 orte.pwr_ctrl.voltage80 = true;
382 orte.pwr_ctrl.voltage80 = false;
385 // void RobomonAtlantis::setLeftMotor(int value)
387 // short int leftMotor;
388 // short int rightMotor;
390 // if(bothMotorsCheckBox->isChecked())
391 // rightMotorSlider->setValue(value);
393 // leftMotor = (short int)(MOTOR_LIMIT * (leftMotorSlider->value()/100.0));
394 // rightMotor = (short int)(MOTOR_LIMIT * (rightMotorSlider->value()/100.0));
396 // orte.motion_speed.left = leftMotor;
397 // orte.motion_speed.right = rightMotor;
401 // void RobomonAtlantis::setRightMotor(int value)
403 // short int leftMotor;
404 // short int rightMotor;
406 // if(bothMotorsCheckBox->isChecked())
407 // leftMotorSlider->setValue(value);
409 // leftMotor = (short int)(MOTOR_LIMIT * (leftMotorSlider->value()/100.0));
410 // rightMotor = (short int)(MOTOR_LIMIT * (rightMotorSlider->value()/100.0));
412 // orte.motion_speed.left = leftMotor;
413 // orte.motion_speed.right = rightMotor;
417 // void RobomonAtlantis::stopMotors()
419 // leftMotorSlider->setValue(0);
420 // rightMotorSlider->setValue(0);
423 void RobomonAtlantis::useOpenGL(bool use)
425 playgroundSceneView->useOpenGL(&use);
428 void RobomonAtlantis::showMap(bool show)
432 if (sharedMemoryOpened == false)
436 mapTimer = new QTimer(this);
437 connect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
438 mapTimer->start(200);
440 if(mapTimer != NULL) {
442 disconnect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
445 mapImage->setVisible(show);
448 void RobomonAtlantis::paintMap()
451 struct map *map = ShmapIsMapInit();
455 for(int i = 0; i < MAP_WIDTH; i++) {
456 for(int j = 0; j < MAP_HEIGHT; j++) {
459 struct map_cell *cell = &map->cells[j][i];
462 if (cell->flags & MAP_FLAG_WALL)
464 if (cell->flags & MAP_FLAG_IGNORE_OBST)
466 if (cell->flags & MAP_FLAG_SIMULATED_WALL)
468 if (cell->flags & MAP_FLAG_PATH)
470 if (cell->flags & MAP_FLAG_START)
472 if (cell->flags & MAP_FLAG_GOAL)
474 if (cell->flags & MAP_FLAG_PLAN_MARGIN) {
475 QColor c(240, 170, 50); /* orange */
478 if (cell->detected_obstacle) {
479 QColor c1(color), c2(blue);
480 double f = (double)cell->detected_obstacle/MAP_NEW_OBSTACLE*0.7;
481 QColor c(c1.red() + (int)(f*(c2.red() - c1.red())),
482 c1.green() + (int)(f*(c2.green() - c1.green())),
483 c1.blue() + (int)(f*(c2.blue() - c1.blue())));
486 if (cell->flags & MAP_FLAG_DET_OBST)
490 mapImage->setPixelColor(i, MAP_HEIGHT - j - 1, color);
495 void RobomonAtlantis::setSimulation(int state)
498 robottype_publisher_hokuyo_scan_create(&orte, NULL, this);
500 if (!simulationEnabled)
502 robottype_publisher_hokuyo_scan_destroy(&orte);
504 simulationEnabled = state;
508 \fn RobomonAtlantis::setObstacleSimulation(int state)
510 void RobomonAtlantis::setObstacleSimulation(int state)
513 /* TODO Maybe it is possible to attach only once to Shmap */
515 obstacleSimulationTimer = new QTimer(this);
516 connect(obstacleSimulationTimer, SIGNAL(timeout()),
517 this, SLOT(simulateObstaclesHokuyo()));
518 obstacleSimulationTimer->start(100);
519 setMouseTracking(true);
520 hokuyoScan->setVisible(true);
524 if (obstacleSimulationTimer)
525 delete obstacleSimulationTimer;
527 hokuyoScan->setVisible(false); /* hide hokuyo scan*/
533 void RobomonAtlantis::simulateObstaclesHokuyo()
535 double distance, wall_distance;
537 uint16_t *hokuyo = orte.hokuyo_scan.data;
539 for (i=0; i<HOKUYO_ARRAY_SIZE; i++) {
540 wall_distance = distanceToWallHokuyo(i);
541 distance = distanceToObstacleHokuyo(i, simulatedObstacle, SIM_OBST_SIZE_M/*meters*/);
542 if (wall_distance < distance)
543 distance = wall_distance;
544 hokuyo[i] = distance*1000;
546 ORTEPublicationSend(orte.publication_hokuyo_scan);
550 void RobomonAtlantis::changeObstacle(QPointF position)
552 if (!simulationEnabled) {
553 simulationEnabled = 1;
554 obstacleSimulationCheckBox->setChecked(true);
557 simulatedObstacle.x = position.x();
558 simulatedObstacle.y = position.y();
559 simulateObstaclesHokuyo();
562 /**********************************************************************
564 **********************************************************************/
565 bool RobomonAtlantis::event(QEvent *event)
567 switch (event->type()) {
568 case QEVENT(QEV_MOTION_STATUS):
569 emit motionStatusReceivedSignal();
571 case QEVENT(QEV_HOKUYO_SCAN):
572 hokuyoScan->newScan(&orte.hokuyo_scan);
574 case QEVENT(QEV_CRANE_CMD):
575 robotEstPosBest->setCrane(orte.crane_cmd.req_pos);
577 case QEVENT(QEV_REFERENCE_POSITION):
578 emit actualPositionReceivedSignal();
580 case QEVENT(QEV_ESTIMATED_POSITION_INDEP_ODO):
581 estPosX->setText(QString("%1").arg(orte.est_pos_indep_odo.x, 0, 'f', 3));
582 estPosY->setText(QString("%1").arg(orte.est_pos_indep_odo.y, 0, 'f', 3));
583 estPosPhi->setText(QString("%1(%2)")
584 .arg(DEGREES(orte.est_pos_indep_odo.phi), 0, 'f', 0)
585 .arg(orte.est_pos_indep_odo.phi, 0, 'f', 1));
586 robotEstPosIndepOdo->moveRobot(orte.est_pos_indep_odo.x,
587 orte.est_pos_indep_odo.y, orte.est_pos_indep_odo.phi);
588 trailPosIndepOdo->addPoint(QPointF(orte.est_pos_indep_odo.x,
589 orte.est_pos_indep_odo.y));
591 case QEVENT(QEV_ESTIMATED_POSITION_ODO):
592 robotEstPosOdo->moveRobot(orte.est_pos_odo.x,
593 orte.est_pos_odo.y, orte.est_pos_odo.phi);
594 trailOdoPos->addPoint(QPointF(orte.est_pos_odo.x,
595 orte.est_pos_odo.y));
597 case QEVENT(QEV_ESTIMATED_POSITION_BEST):
598 robotEstPosBest->moveRobot(orte.est_pos_best.x,
599 orte.est_pos_best.y, orte.est_pos_best.phi);
600 trailEstPosBest->addPoint(QPointF(orte.est_pos_best.x,
601 orte.est_pos_best.y));
602 hokuyoScan->setPosition(orte.est_pos_best.x,
604 orte.est_pos_best.phi);
606 case QEVENT(QEV_POWER_VOLTAGE):
607 emit powerVoltageReceivedSignal();
609 case QEVENT(QEV_FSM_MAIN):
610 fsm_main_state->setText(orte.fsm_main.state_name);
612 case QEVENT(QEV_FSM_ACT):
613 fsm_act_state->setText(orte.fsm_act.state_name);
615 case QEVENT(QEV_FSM_MOTION):
616 fsm_motion_state->setText(orte.fsm_motion.state_name);
619 if (event->type() == QEvent::Close)
620 closeEvent((QCloseEvent *)event);
621 else if (event->type() == QEvent::KeyPress)
622 keyPressEvent((QKeyEvent *)event);
623 else if (event->type() == QEvent::KeyRelease)
624 keyReleaseEvent((QKeyEvent *)event);
625 else if (event->type() == QEvent::FocusIn)
627 else if (event->type() == QEvent::FocusOut)
639 void RobomonAtlantis::keyPressEvent(QKeyEvent *event)
641 // double peak, gain;
643 if (event->isAutoRepeat()) {
644 switch (event->key()) {
645 // case Qt::Key_Down:
646 // peak = leftMotorSlider->minimum()/2;
647 // if (leftMotorValue < peak ||
648 // rightMotorValue < peak)
652 // leftMotorValue *= gain;
653 // rightMotorValue *= gain;
654 // leftMotorSlider->setValue((int)leftMotorValue);
655 // rightMotorSlider->setValue((int)rightMotorValue);
659 // case Qt::Key_Left:
660 // case Qt::Key_Right:
661 // peak = leftMotorSlider->maximum()/2;
662 // if (leftMotorValue > peak ||
663 // rightMotorValue > peak)
667 // leftMotorValue *= gain;
668 // rightMotorValue *= gain;
669 // leftMotorSlider->setValue((int)leftMotorValue);
670 // rightMotorSlider->setValue((int)rightMotorValue);
680 switch (event->key()) {
682 // leftMotorValue = 1;
683 // rightMotorValue = 1;
684 // bothMotorsCheckBox->setChecked(true);
685 // leftMotorSlider->setValue((int)leftMotorValue);
686 // setLeftMotor((int)leftMotorValue);
688 // case Qt::Key_Down:
689 // leftMotorValue = -1;
690 // rightMotorValue = -1;
691 // bothMotorsCheckBox->setChecked(true);
692 // leftMotorSlider->setValue((int)leftMotorValue);
693 // setLeftMotor((int)leftMotorValue);
695 // case Qt::Key_Left:
696 // leftMotorValue = -1;
697 // rightMotorValue = 1;
698 // leftMotorSlider->setValue((int)leftMotorValue);
699 // rightMotorSlider->setValue((int)rightMotorValue);
700 // setLeftMotor((int)leftMotorValue);
701 // setRightMotor((int)leftMotorValue);
703 // case Qt::Key_Right:
704 // leftMotorValue = 1;
705 // rightMotorValue = -1;
706 // leftMotorSlider->setValue((int)leftMotorValue);
707 // rightMotorSlider->setValue((int)rightMotorValue);
708 // setLeftMotor((int)leftMotorValue);
709 // setRightMotor((int)rightMotorValue);
718 void RobomonAtlantis::keyReleaseEvent(QKeyEvent *event)
720 if (event->isAutoRepeat()) {
725 switch (event->key()) {
727 // case Qt::Key_Down:
728 // case Qt::Key_Left:
729 // case Qt::Key_Right:
730 // leftMotorValue = 0;
731 // rightMotorValue = 0;
732 // bothMotorsCheckBox->setChecked(false);
733 // leftMotorSlider->setValue((int)leftMotorValue);
734 // rightMotorSlider->setValue((int)rightMotorValue);
743 void RobomonAtlantis::closeEvent(QCloseEvent *)
745 robottype_roboorte_destroy(&orte);
748 /**********************************************************************
750 **********************************************************************/
751 void RobomonAtlantis::createOrte()
757 memset(&orte, 0, sizeof(orte));
758 rv = robottype_roboorte_init(&orte);
760 printf("RobomonAtlantis: Unable to initialize ORTE\n");
764 robottype_publisher_motion_speed_create(&orte, dummy_publisher_callback, NULL);
766 robottype_publisher_pwr_ctrl_create(&orte, dummy_publisher_callback, NULL);
767 robottype_publisher_robot_cmd_create(&orte, NULL, &orte);
768 robottype_publisher_robot_switches_create(&orte, dummy_publisher_callback, &orte);
771 robottype_subscriber_pwr_voltage_create(&orte,
772 receivePowerVoltageCallBack, this);
773 robottype_subscriber_motion_status_create(&orte,
774 receiveMotionStatusCallBack, this);
775 robottype_subscriber_ref_pos_create(&orte,
776 receiveActualPositionCallBack, this);
777 robottype_subscriber_est_pos_odo_create(&orte,
778 generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_ODO));
779 robottype_subscriber_est_pos_indep_odo_create(&orte,
780 generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_INDEP_ODO));
781 robottype_subscriber_est_pos_best_create(&orte,
782 generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_BEST));
783 robottype_subscriber_hokuyo_scan_create(&orte,
784 generic_rcv_cb, new OrteCallbackInfo(this, QEV_HOKUYO_SCAN));
785 robottype_subscriber_crane_cmd_create(&orte,
786 generic_rcv_cb, new OrteCallbackInfo(this, QEV_CRANE_CMD));
787 robottype_subscriber_fsm_main_create(&orte,
788 rcv_fsm_main_cb, this);
789 robottype_subscriber_fsm_motion_create(&orte,
790 rcv_fsm_motion_cb, this);
791 robottype_subscriber_fsm_act_create(&orte,
792 rcv_fsm_act_cb, this);
795 orte.motion_speed.left = 0xffff;
796 orte.motion_speed.right = 0xffff;
798 /* power management */
799 orte.pwr_ctrl.voltage33 = true;
800 orte.pwr_ctrl.voltage50 = true;
801 orte.pwr_ctrl.voltage80 = true;
802 voltage33CheckBox->setChecked(true);
803 voltage50CheckBox->setChecked(true);
804 voltage80CheckBox->setChecked(true);
808 /* set actions to do when we receive data from orte */
809 connect(this, SIGNAL(motionStatusReceivedSignal()),
810 this, SLOT(motionStatusReceived()));
811 connect(this, SIGNAL(actualPositionReceivedSignal()),
812 this, SLOT(actualPositionReceived()));
813 connect(this, SIGNAL(powerVoltageReceivedSignal()),
814 this, SLOT(powerVoltageReceived()));
817 void RobomonAtlantis::motionStatusReceived()
819 WDBG("ORTE received: motion status");
822 void RobomonAtlantis::actualPositionReceived()
824 actPosX->setText(QString("%1").arg(orte.ref_pos.x, 0, 'f', 3));
825 actPosY->setText(QString("%1").arg(orte.ref_pos.y, 0, 'f', 3));
826 actPosPhi->setText(QString("%1(%2)")
827 .arg(DEGREES(orte.ref_pos.phi), 0, 'f', 0)
828 .arg(orte.ref_pos.phi, 0, 'f', 1));
829 robotRefPos->moveRobot(orte.ref_pos.x,
830 orte.ref_pos.y, orte.ref_pos.phi);
831 trailRefPos->addPoint(QPointF(orte.ref_pos.x, orte.ref_pos.y));
834 void RobomonAtlantis::powerVoltageReceived()
836 voltage33LineEdit->setText(QString("%1").arg(
837 orte.pwr_voltage.voltage33, 0, 'f', 3));
838 voltage50LineEdit->setText(QString("%1").arg(
839 orte.pwr_voltage.voltage50, 0, 'f', 3));
840 voltage80LineEdit->setText(QString("%1").arg(
841 orte.pwr_voltage.voltage80, 0, 'f', 3));
842 voltageBATLineEdit->setText(QString("%1").arg(
843 orte.pwr_voltage.voltageBAT, 0, 'f', 3));
847 /**********************************************************************
849 **********************************************************************/
850 void RobomonAtlantis::openSharedMemory()
853 int sharedSegmentSize;
855 if (sharedMemoryOpened)
858 sharedSegmentSize = sizeof(unsigned int) * MAP_WIDTH * MAP_HEIGHT;
860 /* Get segment identificator in a read only mode */
861 segmentId = shmget(SHM_MAP_KEY, sharedSegmentSize, S_IRUSR);
862 if(segmentId == -1) {
863 statusBar->showMessage("No external map found - creating a new map.");
869 /* Attach the shared memory segment */
870 //map = (_Map*)shmat (segmentId, (void*) 0, 0);
872 sharedMemoryOpened = true;
875 double RobomonAtlantis::distanceToWallHokuyo(int beamnum)
877 double distance=4.0, min_distance=4.0;
880 struct map *map = ShmapIsMapInit();
882 if (!map) return min_distance;
884 // Simulate obstacles
885 for(j=0;j<MAP_HEIGHT;j++) {
886 for (i=0;i<MAP_WIDTH;i++) {
887 struct map_cell *cell = &map->cells[j][i];
888 if( cell->flags & MAP_FLAG_SIMULATED_WALL) {
890 ShmapCell2Point(i, j, &wall.x, &wall.y);
892 distance = distanceToObstacleHokuyo(beamnum, wall, MAP_CELL_SIZE_M);
893 if (distance<min_distance) min_distance = distance;
902 * Calculation for Hokuyo simulation. Calculates distance that would
903 * be returned by Hokuyo sensors, if there is only one obstacle (as
904 * specified by parameters).
906 * @param beamnum Hokuyo's bean number [0..HOKUYO_CLUSTER_CNT]
907 * @param obstacle Position of the obstacle (x, y in meters).
908 * @param obstacleSize Size (diameter) of the obstacle in meters.
910 * @return Distance measured by sensors in meters.
912 double RobomonAtlantis::distanceToObstacleHokuyo(int beamnum, Point obstacle, double obstacleSize)
914 struct robot_pos_type e = orte.est_pos_best;
916 struct robot_pos_type s;
918 s.x = HOKUYO_CENTER_OFFSET_M;
920 s.phi = HOKUYO_INDEX_TO_RAD(beamnum);
922 Point sensor(e.x + s.x*cos(e.phi) - s.y*sin(e.phi),
923 e.y + s.x*sin(e.phi) + s.y*cos(e.phi));
924 sensor_a = e.phi + s.phi;
926 const double sensorRange = 4.0; /*[meters]*/
928 double distance, angle;
930 angle = sensor.angleTo(obstacle) - sensor_a;
931 angle = fmod(angle, 2.0*M_PI);
932 if (angle > +M_PI) angle -= 2.0*M_PI;
933 if (angle < -M_PI) angle += 2.0*M_PI;
935 distance = sensor.distanceTo(obstacle) - obstacleSize/2.0;
936 if (angle < atan(obstacleSize/2.0 / distance)) {
937 // We can see the obstackle from here.
938 if (angle < M_PI/2.0) {
939 distance = distance/cos(angle);
941 if (distance > sensorRange)
942 distance = sensorRange;
944 distance = sensorRange;
950 void RobomonAtlantis::sendStart(int plug)
952 orte.robot_cmd.start_condition = plug ? 0 : 1;
953 ORTEPublicationSend(orte.publication_robot_cmd);
956 void RobomonAtlantis::resetTrails()
958 trailRefPos->reset();
959 trailEstPosBest->reset();
960 trailPosIndepOdo->reset();
961 trailOdoPos->reset();
964 void RobomonAtlantis::showTrails(bool show)
966 trailRefPos->setVisible(show && robotRefPos->isVisible());
967 trailEstPosBest->setVisible(show && robotEstPosBest->isVisible());
968 trailPosIndepOdo->setVisible(show && robotEstPosIndepOdo->isVisible());
969 trailOdoPos->setVisible(show && robotEstPosOdo->isVisible());
972 void RobomonAtlantis::showShapeDetect(bool show)
974 hokuyoScan->showShapeDetect = show;