]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robomon/RobomonAtlantis.cpp
robomon: Remove dead code
[eurobot/public.git] / src / robomon / RobomonAtlantis.cpp
index db8f1ebbeb43ff9f7160a51f19117910151742ca..3fa77df50fe2184b4dc5ed640042b38e9e6e05fc 100644 (file)
@@ -30,7 +30,7 @@
 #include <trgen.h>
 #include <map.h>
 #include <robomath.h>
-#include <hokuyo.h>
+#include <lidar_params.h>
 #include <actuators.h>
 #include "PlaygroundScene.h"
 #include "MiscGui.h"
@@ -45,8 +45,8 @@
 #include <QDebug>
 #include <QMessageBox>
 
-RobomonAtlantis::RobomonAtlantis(QWidget *parent)
-       : QWidget(parent)
+RobomonAtlantis::RobomonAtlantis(QStatusBar *_statusBar)
+       : QWidget(0), statusBar(_statusBar)
 {
        QFont font;
        font.setPointSize(7);
@@ -65,6 +65,7 @@ RobomonAtlantis::RobomonAtlantis(QWidget *parent)
        createOrte();
        createRobots();
        createActions();
+       createMap();
 
        setFocusPolicy(Qt::StrongFocus);
        sharedMemoryOpened = false;
@@ -77,7 +78,7 @@ RobomonAtlantis::RobomonAtlantis(QWidget *parent)
 void RobomonAtlantis::createLeftLayout()
 {
        leftLayout = new QVBoxLayout();
-       
+
        createDebugGroupBox();
        debugWindowEnabled = true;
        createPlaygroundGroupBox();
@@ -88,17 +89,18 @@ void RobomonAtlantis::createLeftLayout()
 void RobomonAtlantis::createRightLayout()
 {
        rightLayout = new QVBoxLayout();
-       
+
        createPositionGroupBox();
+       createObstSimGroupBox();
        createMiscGroupBox();
        createFSMGroupBox();
        createActuatorsGroupBox();
        createPowerGroupBox();
 
        rightLayout->addWidget(positionGroupBox);
+       rightLayout->addWidget(obstSimGroupBox);
        rightLayout->addWidget(miscGroupBox);
        rightLayout->addWidget(fsmGroupBox);
-       rightLayout->addWidget(powerGroupBox);
        rightLayout->addWidget(actuatorsGroupBox);
 }
 
@@ -109,11 +111,10 @@ void RobomonAtlantis::createPlaygroundGroupBox()
 
        playgroundScene = new PlaygroundScene();
        playgroundSceneView = new PlaygroundView(playgroundScene);
-       //playgroundSceneView->setMinimumWidth(630);
-       //playgroundSceneView->setMinimumHeight(445);
-        playgroundSceneView->setMatrix(QMatrix(1,0,0,-1,0,0), true);
+       playgroundSceneView->setMatrix(QMatrix(1,0,0,-1,0,0), true);
        playgroundSceneView->fitInView(playgroundScene->itemsBoundingRect());
        playgroundSceneView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+       playgroundSceneView->setMouseTracking(true);
        layout->addWidget(playgroundSceneView);
 
        playgroundGroupBox->setLayout(layout);
@@ -122,9 +123,9 @@ void RobomonAtlantis::createPlaygroundGroupBox()
 void RobomonAtlantis::createPositionGroupBox()
 {
        positionGroupBox = new QGroupBox(tr("Position state"));
-       positionGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+       positionGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        QGridLayout *layout = new QGridLayout();
-       
+
        actPosX = new QLineEdit();
        actPosY = new QLineEdit();
        actPosPhi = new QLineEdit();
@@ -132,7 +133,7 @@ void RobomonAtlantis::createPositionGroupBox()
        estPosX = new QLineEdit();
        estPosY = new QLineEdit();
        estPosPhi = new QLineEdit();
-       
+
        actPosX->setReadOnly(true);
        actPosY->setReadOnly(true);
        actPosPhi->setReadOnly(true);
@@ -154,7 +155,7 @@ void RobomonAtlantis::createPositionGroupBox()
        layout->addWidget(actPosY, 2, 1);
        layout->addWidget(actPosPhi, 3, 1);
 
-       layout->addWidget(MiscGui::createLabel("Estimated", Qt::AlignLeft), 4, 1);
+       layout->addWidget(MiscGui::createLabel("Estimated (indep. odo.)", Qt::AlignLeft), 4, 1);
        layout->addWidget(estPosX, 5, 1);
        layout->addWidget(estPosY, 6, 1);
        layout->addWidget(estPosPhi, 7, 1);
@@ -168,19 +169,39 @@ void RobomonAtlantis::createMiscGroupBox()
        miscGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        QGridLayout *layout = new QGridLayout();
 
-       obstacleSimulationCheckBox = new QCheckBox(tr("&Obstacle simulation"));
-       obstacleSimulationCheckBox->setShortcut(tr("o"));
-       layout->addWidget(obstacleSimulationCheckBox);
-
-       startPlug = new QCheckBox("Start plug");
+       startPlug = new QCheckBox("&Start plug");
        layout->addWidget(startPlug);
-       
-       puckInside = new QCheckBox("Puck inside");
-       layout->addWidget(puckInside);
-       
+
+       colorChoser = new QCheckBox("&Team color");
+       layout->addWidget(colorChoser);
+
+       strategyButton= new QPushButton(tr("Strategy"));
+       layout->addWidget(strategyButton);
+
        miscGroupBox->setLayout(layout);
 }
 
+void RobomonAtlantis::createObstSimGroupBox()
+{
+       obstSimGroupBox = new QGroupBox(tr("Obstacle simulation"));
+       obstSimGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+       QGridLayout *layout = new QGridLayout();
+
+       hokuyoSimCheckBox = new QCheckBox(tr("&Hokuyo lidar simulation"));
+       hokuyoSimCheckBox->setShortcut(tr("h"));
+       layout->addWidget(hokuyoSimCheckBox);
+
+       sick331SimCheckBox = new QCheckBox(tr("Sick Tim &331 lidar simulation"));
+       sick331SimCheckBox->setShortcut(tr("3"));
+       layout->addWidget(sick331SimCheckBox);
+
+       sick551SimCheckBox = new QCheckBox(tr("Sick Tim &551 lidar simulation"));
+       sick551SimCheckBox->setShortcut(tr("5"));
+       layout->addWidget(sick551SimCheckBox);
+
+       obstSimGroupBox->setLayout(layout);
+}
+
 void RobomonAtlantis::createFSMGroupBox()
 {
        fsmGroupBox = new QGroupBox(tr("FSM"));
@@ -223,10 +244,7 @@ void RobomonAtlantis::createActuatorsGroupBox()
        actuatorsGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
        QHBoxLayout *layout = new QHBoxLayout();
 
-       createMotorsGroupBox();
-
        layout->setAlignment(Qt::AlignLeft);
-       layout->addWidget(enginesGroupBox);
        actuatorsGroupBox->setLayout(layout);
 }
 
@@ -267,74 +285,59 @@ void RobomonAtlantis::createPowerGroupBox()
        powerGroupBox->setLayout(layout);
 }
 
-void RobomonAtlantis::createMotorsGroupBox()
-{
-       enginesGroupBox = new QGroupBox(tr("Motors"));
-       QVBoxLayout *layout = new QVBoxLayout();
-       QHBoxLayout *layout1 = new QHBoxLayout();
-       QHBoxLayout *layout2 = new QHBoxLayout();
-
-       leftMotorSlider = new QSlider(Qt::Vertical);
-       rightMotorSlider = new QSlider(Qt::Vertical);
-       bothMotorsCheckBox = new QCheckBox(tr("Lock both"));
-       stopMotorsPushButton = new QPushButton(tr("Stop Motors"));
-
-       leftMotorSlider->setMinimum(-100);
-       leftMotorSlider->setMaximum(100);
-       leftMotorSlider->setTracking(false);
-       leftMotorSlider->setTickPosition(QSlider::TicksLeft);
-
-       rightMotorSlider->setMinimum(-100);
-       rightMotorSlider->setMaximum(100);
-       rightMotorSlider->setTracking(false);
-       rightMotorSlider->setTickPosition(QSlider::TicksRight);
-
-       stopMotorsPushButton->setMaximumWidth(90);
-
-       layout1->addWidget(leftMotorSlider);
-       layout1->addWidget(MiscGui::createLabel("0"));
-       layout1->addWidget(rightMotorSlider);
-
-       layout2->addWidget(bothMotorsCheckBox);
-
-       layout->addWidget(MiscGui::createLabel("100"));
-       layout->addLayout(layout1);
-       layout->addWidget(MiscGui::createLabel("-100"));
-       layout->addLayout(layout2);
-       layout->addWidget(stopMotorsPushButton);
-       enginesGroupBox->setLayout(layout);
-}
-
 void RobomonAtlantis::createRobots()
 {
        robotRefPos = new Robot("Ref", QPen(Qt::darkBlue), QBrush(Qt::NoBrush));
        robotRefPos->setZValue(11);
        trailRefPos = new Trail(QPen(Qt::darkBlue));
        trailRefPos->setZValue(11);
-       
+
+       robotEstPosBest = new Robot("Est", QPen(), QBrush(Qt::darkGray));
+       robotEstPosBest->setZValue(10);
+       trailEstPosBest = new Trail(QPen());
+       trailEstPosBest->setZValue(10);
+
        robotEstPosOdo = new Robot("Mot", QPen(Qt::white), QBrush(Qt::darkRed));
        robotEstPosOdo->setZValue(10);
-       trailOdoPos = new Trail(QPen(Qt::white));
+       trailOdoPos = new Trail(QPen(Qt::red));
        trailOdoPos->setZValue(10);
-       robotEstPosIndepOdo = new Robot("Odo", QPen(), QBrush(Qt::darkGray));
+
+       robotEstPosIndepOdo = new Robot("Odo", QPen(Qt::white), QBrush(Qt::darkGreen));
        robotEstPosIndepOdo->setZValue(10);
-       trailPosIndepOdo = new Trail(QPen());
+       trailPosIndepOdo = new Trail(QPen(Qt::green));
        trailPosIndepOdo->setZValue(10);
 
        playgroundScene->addItem(robotRefPos);
+       playgroundScene->addItem(robotEstPosBest);
        playgroundScene->addItem(robotEstPosIndepOdo);
        playgroundScene->addItem(robotEstPosOdo);
-       
+
        showTrails(false);
-       
+
        playgroundScene->addItem(trailRefPos);
        playgroundScene->addItem(trailPosIndepOdo);
        playgroundScene->addItem(trailOdoPos);
 
-       hokuyoScan = new HokuyoScan();
+       hokuyoScan = new LidarScan(hokuyo_params);
        hokuyoScan->setZValue(10);
        playgroundScene->addItem(hokuyoScan);
-       
+
+       sickScan = new LidarScan(sick_params);
+       sickScan->setZValue(10);
+       playgroundScene->addItem(sickScan);
+
+       sick551Scan = new LidarScan(sick551_params);
+       sick551Scan->setZValue(10);
+       playgroundScene->addItem(sick551Scan);
+}
+
+void RobomonAtlantis::createMap()
+{
+       mapImage = new Map();
+       mapImage->setZValue(5);
+       mapImage->setTransform(QTransform().scale(MAP_CELL_SIZE_MM, MAP_CELL_SIZE_MM), true);
+
+       playgroundScene->addItem(mapImage);
 }
 
 /**********************************************************************
@@ -343,35 +346,54 @@ void RobomonAtlantis::createRobots()
 void RobomonAtlantis::createActions()
 {
        /* power management */
-       connect(voltage33CheckBox, SIGNAL(stateChanged(int)), 
+       connect(voltage33CheckBox, SIGNAL(stateChanged(int)),
                        this, SLOT(setVoltage33(int)));
-       connect(voltage50CheckBox, SIGNAL(stateChanged(int)), 
+       connect(voltage50CheckBox, SIGNAL(stateChanged(int)),
                        this, SLOT(setVoltage50(int)));
-       connect(voltage80CheckBox, SIGNAL(stateChanged(int)), 
+       connect(voltage80CheckBox, SIGNAL(stateChanged(int)),
                        this, SLOT(setVoltage80(int)));
 
-       /* motors */
-       connect(leftMotorSlider, SIGNAL(valueChanged(int)), 
-                       this, SLOT(setLeftMotor(int)));
-       connect(rightMotorSlider, SIGNAL(valueChanged(int)), 
-                       this, SLOT(setRightMotor(int)));
-       connect(stopMotorsPushButton, SIGNAL(clicked()), 
-                       this, SLOT(stopMotors()));
-
        connect(startPlug, SIGNAL(stateChanged(int)), this, SLOT(sendStart(int)));
-       
+       connect(colorChoser, SIGNAL(stateChanged(int)), this, SLOT(setTeamColor(int)));
+       connect(strategyButton, SIGNAL(pressed()), this, SLOT(changeStrategy_1()));
+       connect(strategyButton, SIGNAL(released()), this, SLOT(changeStrategy_0()));
+
        /* obstacle simulation */
-       simulationEnabled = 0;
-       connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
-                       this, SLOT(setSimulation(int)));
-       connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
-                       this, SLOT(setObstacleSimulation(int)));
-       connect(obstacleSimulationCheckBox, SIGNAL(stateChanged(int)),
-                       playgroundScene, SLOT(showObstacle(int)));
-       connect(playgroundScene, SIGNAL(obstacleChanged(QPointF)), 
+       hokuyoSimEnabled = 0;
+       sickSimEnabled = 0;
+       sick551SimEnabled = 0;
+
+       connect(hokuyoSimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setHokuyoSimulation(int)));
+       connect(hokuyoSimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setHokuyoObstacleSimulation(int)));
+
+       connect(sick331SimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setSick331Simulation(int)));
+       connect(sick331SimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setSick331ObstacleSimulation(int)));
+
+       connect(sick551SimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setSick551Simulation(int)));
+       connect(sick551SimCheckBox, SIGNAL(stateChanged(int)),
+                       this, SLOT(setSick551ObstacleSimulation(int)));
+
+       connect(playgroundScene, SIGNAL(obstacleChanged(QPointF)),
                        this, SLOT(changeObstacle(QPointF)));
 }
 
+void RobomonAtlantis::changeStrategy_1()
+{
+               orte.robot_switches.strategy = true;
+               ORTEPublicationSend(orte.publication_robot_switches);
+}
+
+void RobomonAtlantis::changeStrategy_0()
+{
+               orte.robot_switches.strategy = false;
+               ORTEPublicationSend(orte.publication_robot_switches);
+}
+
 void RobomonAtlantis::setVoltage33(int state)
 {
        if (state)
@@ -396,42 +418,9 @@ void RobomonAtlantis::setVoltage80(int state)
                orte.pwr_ctrl.voltage80 = false;
 }
 
-void RobomonAtlantis::setLeftMotor(int value)
-{
-       short int leftMotor;
-       short int rightMotor;
-       
-       if(bothMotorsCheckBox->isChecked())
-               rightMotorSlider->setValue(value);
-
-       leftMotor = (short int)(MOTOR_LIMIT * (leftMotorSlider->value()/100.0));
-       rightMotor = (short int)(MOTOR_LIMIT * (rightMotorSlider->value()/100.0));
-       
-       orte.motion_speed.left = leftMotor;
-       orte.motion_speed.right = rightMotor;
-       
-}
-
-void RobomonAtlantis::setRightMotor(int value)
-{
-       short int leftMotor;
-       short int rightMotor;
-       
-       if(bothMotorsCheckBox->isChecked())
-               leftMotorSlider->setValue(value);
-
-       leftMotor = (short int)(MOTOR_LIMIT * (leftMotorSlider->value()/100.0));
-       rightMotor = (short int)(MOTOR_LIMIT * (rightMotorSlider->value()/100.0));
-       
-       orte.motion_speed.left = leftMotor;
-       orte.motion_speed.right = rightMotor;
-       
-}
-
-void RobomonAtlantis::stopMotors()
+void RobomonAtlantis::useOpenGL(bool use)
 {
-       leftMotorSlider->setValue(0);
-       rightMotorSlider->setValue(0);
+       playgroundSceneView->useOpenGL(&use);
 }
 
 void RobomonAtlantis::showMap(bool show)
@@ -440,123 +429,241 @@ void RobomonAtlantis::showMap(bool show)
 
        if (sharedMemoryOpened == false)
                return;
-       
+
        if (show) {
                mapTimer = new QTimer(this);
                connect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
                mapTimer->start(200);
        } else {
-               mapTimer->stop();
-               disconnect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
+               if(mapTimer != NULL) {
+                       mapTimer->stop();
+                       disconnect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
+               }
        }
-       playgroundScene->showMap(show);
+       mapImage->setVisible(show);
 }
 
 void RobomonAtlantis::paintMap()
 {
-       using namespace Qt;
-        struct map *map = ShmapIsMapInit();
-
-        if (!map) return;
-       
-       for(int i=0; i < MAP_WIDTH; i++) {
-               for(int j=0; j<MAP_HEIGHT; j++) {
-                        QColor color;
-                               
-                        struct map_cell *cell = &map->cells[j][i];
-                        color = lightGray;
-
-                        if ((cell->flags & MAP_FLAG_WALL) &&
-                           (cell->flags & MAP_FLAG_INVALIDATE_WALL) == 0)
-                                color = darkYellow;
-                        if (cell->flags & MAP_FLAG_IGNORE_OBST)
-                                color = darkGreen;
-                        if (cell->flags & MAP_FLAG_SIMULATED_WALL)
-                                color = yellow;
-                        if (cell->flags & MAP_FLAG_PATH)
-                                color = darkRed;
-                        if (cell->flags & MAP_FLAG_START)
-                                color = red;
-                        if (cell->flags & MAP_FLAG_GOAL)
-                                color = green;
-                        if (cell->detected_obstacle) {
-                                QColor c1(color), c2(blue);
-                                double f = (double)cell->detected_obstacle/MAP_NEW_OBSTACLE*0.7;
-                                QColor c(c1.red()   + (int)(f*(c2.red()   - c1.red())),
-                                         c1.green() + (int)(f*(c2.green() - c1.green())),
-                                         c1.blue()  + (int)(f*(c2.blue()  - c1.blue())));
-                                color = c;
-                        }
-                        if (cell->flags & MAP_FLAG_DET_OBST)
-                                color = cyan;
-                        
-                        playgroundScene->setMapColor(i, j, color);
-                }
+               using namespace Qt;
+               struct map *map = ShmapIsMapInit();
+
+               if (!map) return;
+
+       for(int i = 0; i < MAP_WIDTH; i++) {
+               for(int j = 0; j < MAP_HEIGHT; j++) {
+                                               QColor color;
+
+                                               struct map_cell *cell = &map->cells[j][i];
+                                               color = lightGray;
+
+                                               if (cell->flags & MAP_FLAG_WALL)
+                                                               color = darkYellow;
+                                               if (cell->flags & MAP_FLAG_IGNORE_OBST)
+                                                               color = darkGreen;
+                                               if (cell->flags & MAP_FLAG_SIMULATED_WALL)
+                                                               color = yellow;
+                                               if (cell->flags & MAP_FLAG_PATH)
+                                                               color = darkRed;
+                                               if (cell->flags & MAP_FLAG_START)
+                                                               color = red;
+                                               if (cell->flags & MAP_FLAG_GOAL)
+                                                               color = green;
+                       if (cell->flags & MAP_FLAG_PLAN_MARGIN) {
+                               QColor c(240, 170, 50); /* orange */
+                               color = c;
+                       }
+                                               if (cell->detected_obstacle) {
+                                                               QColor c1(color), c2(blue);
+                                                               double f = (double)cell->detected_obstacle/MAP_NEW_OBSTACLE*0.7;
+                                                               QColor c(c1.red()   + (int)(f*(c2.red()   - c1.red())),
+                                                                                c1.green() + (int)(f*(c2.green() - c1.green())),
+                                                                                c1.blue()  + (int)(f*(c2.blue()  - c1.blue())));
+                                                               color = c;
+                                               }
+                                               if (cell->flags & MAP_FLAG_DET_OBST)
+                                                               color = cyan;
+
+                       color.setAlpha(200);
+                                               mapImage->setPixelColor(i, MAP_HEIGHT - j - 1, color);
+                               }
        }
 }
 
-void RobomonAtlantis::setSimulation(int state)
+void RobomonAtlantis::setHokuyoSimulation(int state)
 {
-       if(state) { 
-               robottype_publisher_hokuyo_scan_create(&orte, 
-                                                      dummy_publisher_callback, this);
+       if(state) {
+               robottype_publisher_hokuyo_scan_create(&orte, NULL, this);
        } else {
-               if (!simulationEnabled)
+               if (!hokuyoSimEnabled)
                        return;
                robottype_publisher_hokuyo_scan_destroy(&orte);
        }
-       simulationEnabled = state;
+       hokuyoSimEnabled = state;
 }
 
-/*!     
-       \fn RobomonAtlantis::setObstacleSimulation(int state)
- */
-void RobomonAtlantis::setObstacleSimulation(int state)
+void RobomonAtlantis::setSick331Simulation(int state)
+{
+       if(state) {
+               robottype_publisher_sick_scan_create(&orte, NULL, this);
+       } else {
+               if (!sickSimEnabled)
+                       return;
+               robottype_publisher_sick_scan_destroy(&orte);
+       }
+       sickSimEnabled = state;
+}
+
+void RobomonAtlantis::setSick551Simulation(int state)
+{
+       if(state) {
+               robottype_publisher_sick551_scan_create(&orte, NULL, this);
+       } else {
+               if (!sick551SimEnabled)
+                       return;
+               robottype_publisher_sick551_scan_destroy(&orte);
+       }
+       sick551SimEnabled = state;
+}
+
+void RobomonAtlantis::setHokuyoObstacleSimulation(int state)
 {
        if (state) {
-               /* TODO Maybe it is possible to attach only once to Shmap */
-               ShmapInit(0);
-               obstacleSimulationTimer = new QTimer(this);
-               connect(obstacleSimulationTimer, SIGNAL(timeout()), 
+               /* TODO Maybe it is possible to attach only once to Shmap */
+               ShmapInit(0);
+               obstacleSimulationTimerHokuyo = new QTimer(this);
+               connect(obstacleSimulationTimerHokuyo, SIGNAL(timeout()),
                        this, SLOT(simulateObstaclesHokuyo()));
-               obstacleSimulationTimer->start(100);
-               setMouseTracking(true);
+               obstacleSimulationTimerHokuyo->start(100);
+               setMouseTracking(true);
+               hokuyoScan->setVisible(true);
        } else {
-               if (obstacleSimulationTimer) 
-                       delete obstacleSimulationTimer;
-               //double distance = 0.8;
+               if (obstacleSimulationTimerHokuyo)
+                       delete obstacleSimulationTimerHokuyo;
+               // Hide scans of lidars
+               hokuyoScan->setVisible(false);
        }
 }
 
+void RobomonAtlantis::setSick331ObstacleSimulation(int state)
+{
+       if (state) {
+               /* TODO Maybe it is possible to attach only once to Shmap */
+               ShmapInit(0);
+               obstacleSimulationTimerSick331 = new QTimer(this);
+               connect(obstacleSimulationTimerSick331, SIGNAL(timeout()),
+                       this, SLOT(simulateObstaclesSick()));
+               obstacleSimulationTimerSick331->start(100);
+               setMouseTracking(true);
+               sickScan->setVisible(true);
+       } else {
+               if (obstacleSimulationTimerSick331)
+                       delete obstacleSimulationTimerSick331;
+               // Hide scans of lidars
+               sickScan->setVisible(false);
+       }
+}
 
-void RobomonAtlantis::simulateObstaclesHokuyo()
+void RobomonAtlantis::setSick551ObstacleSimulation(int state)
+{
+       if (state) {
+               /* TODO Maybe it is possible to attach only once to Shmap */
+               ShmapInit(0);
+               obstacleSimulationTimerSick551 = new QTimer(this);
+               connect(obstacleSimulationTimerSick551, SIGNAL(timeout()),
+                       this, SLOT(simulateObstaclesSick551()));
+               obstacleSimulationTimerSick551->start(100);
+               setMouseTracking(true);
+               sick551Scan->setVisible(true);
+       } else {
+               if (obstacleSimulationTimerSick551)
+                       delete obstacleSimulationTimerSick551;
+               // Hide scans of lidars
+               sick551Scan->setVisible(false);
+       }
+}
+
+void RobomonAtlantis::simulateObstaclesLidar(const struct lidar_params lidar)
 {
        double distance, wall_distance;
        unsigned int i;
-       uint16_t *hokuyo = orte.hokuyo_scan.data;
-       
-       for (i=0; i<HOKUYO_ARRAY_SIZE; i++) {
-               wall_distance = distanceToWallHokuyo(i);
-               distance = distanceToObstacleHokuyo(i, simulatedObstacle, SIM_OBST_SIZE_M/*meters*/);
-               if (wall_distance < distance) 
+       unsigned int data_lenght = 0;
+       uint16_t *lidar_data = NULL;
+       switch (lidar.type) {
+               case HOKUYO:
+                       lidar_data = orte.hokuyo_scan.data;
+                       data_lenght = hokuyo_params.data_lenght;
+                       break;
+               case SICK_TIM3XX:
+                       lidar_data = orte.sick_scan.data;
+                       data_lenght = sick_params.data_lenght;
+                       break;
+               case SICK_TIM551:
+                       lidar_data = orte.sick551_scan.data;
+                       data_lenght = sick551_params.data_lenght;
+                       break;
+               default:
+                       return;
+       }
+
+       for (i = 0; i < data_lenght; i++) {
+               wall_distance = distanceToWallLidar(lidar, i);
+               distance = distanceToCircularObstacleLidar(lidar, i, simulatedObstacle, SIM_OBST_SIZE_M);
+               if (wall_distance < distance)
                        distance = wall_distance;
-               hokuyo[i] = distance*1000;
+               lidar_data[i] = distance*1000;
+       }
+
+       switch (lidar.type) {
+               case HOKUYO:
+                       orte.hokuyo_scan.data_lenght = hokuyo_params.data_lenght;
+                       orte.hokuyo_scan.lidar_type = hokuyo_params.type;
+                       ORTEPublicationSend(orte.publication_hokuyo_scan);
+                       break;
+               case SICK_TIM3XX:
+                       orte.sick_scan.data_lenght = sick_params.data_lenght;
+                       orte.sick_scan.lidar_type = sick_params.type;
+                       ORTEPublicationSend(orte.publication_sick_scan);
+                       break;
+               case SICK_TIM551:
+                       orte.sick551_scan.data_lenght = sick551_params.data_lenght;
+                       orte.sick551_scan.lidar_type = sick551_params.type;
+                       ORTEPublicationSend(orte.publication_sick551_scan);
+                       break;
+               default:
+                       return;
        }
-       ORTEPublicationSend(orte.publication_hokuyo_scan);
-       
+}
+
+void RobomonAtlantis::simulateObstaclesHokuyo()
+{
+       simulateObstaclesLidar(hokuyo_params);
+}
+
+void RobomonAtlantis::simulateObstaclesSick()
+{
+       simulateObstaclesLidar(sick_params);
+}
+
+void RobomonAtlantis::simulateObstaclesSick551()
+{
+       simulateObstaclesLidar(sick551_params);
 }
 
 void RobomonAtlantis::changeObstacle(QPointF position)
 {
-       if (!simulationEnabled) {
-               simulationEnabled = 1;
-               obstacleSimulationCheckBox->setChecked(true);
+       if (!hokuyoSimEnabled && !sickSimEnabled && !sick551SimEnabled) {
+               hokuyoSimEnabled = 1;
+               sickSimEnabled = 1;
+               sick551SimEnabled = 1;
+               hokuyoSimCheckBox->setChecked(true);
+               sick331SimCheckBox->setChecked(true);
+               sick551SimCheckBox->setChecked(true);
        }
 
        simulatedObstacle.x = position.x();
        simulatedObstacle.y = position.y();
-       simulateObstaclesHokuyo();
-}       
+}
 
 /**********************************************************************
  * EVENTS
@@ -567,6 +674,12 @@ bool RobomonAtlantis::event(QEvent *event)
                case QEVENT(QEV_MOTION_STATUS):
                        emit motionStatusReceivedSignal();
                        break;
+               case QEVENT(QEV_SICK_SCAN):
+                       sickScan->newScan(&orte.sick_scan);
+                       break;
+               case QEVENT(QEV_SICK551_SCAN):
+                       sick551Scan->newScan(&orte.sick551_scan);
+                       break;
                case QEVENT(QEV_HOKUYO_SCAN):
                        hokuyoScan->newScan(&orte.hokuyo_scan);
                        break;
@@ -579,20 +692,31 @@ bool RobomonAtlantis::event(QEvent *event)
                        estPosPhi->setText(QString("%1(%2)")
                                        .arg(DEGREES(orte.est_pos_indep_odo.phi), 0, 'f', 0)
                                        .arg(orte.est_pos_indep_odo.phi, 0, 'f', 1));
-                       robotEstPosIndepOdo->moveRobot(orte.est_pos_indep_odo.x, 
+                       robotEstPosIndepOdo->moveRobot(orte.est_pos_indep_odo.x,
                                orte.est_pos_indep_odo.y, orte.est_pos_indep_odo.phi);
-                       trailPosIndepOdo->addPoint(QPointF(orte.est_pos_indep_odo.x, 
-                                             orte.est_pos_indep_odo.y));
-
-//                     hokuyoScan->setPosition(orte.est_pos_indep_odo.x, 
-//                                             orte.est_pos_indep_odo.y,
-//                                             orte.est_pos_indep_odo.phi); 
+                       trailPosIndepOdo->addPoint(QPointF(orte.est_pos_indep_odo.x,
+                                                 orte.est_pos_indep_odo.y));
                        break;
                case QEVENT(QEV_ESTIMATED_POSITION_ODO):
-                       robotEstPosOdo->moveRobot(orte.est_pos_odo.x, 
+                       robotEstPosOdo->moveRobot(orte.est_pos_odo.x,
                                        orte.est_pos_odo.y, orte.est_pos_odo.phi);
-                       trailOdoPos->addPoint(QPointF(orte.est_pos_odo.x, 
-                                             orte.est_pos_odo.y));
+                       trailOdoPos->addPoint(QPointF(orte.est_pos_odo.x,
+                                                 orte.est_pos_odo.y));
+                       break;
+               case QEVENT(QEV_ESTIMATED_POSITION_BEST):
+                       robotEstPosBest->moveRobot(orte.est_pos_best.x,
+                                       orte.est_pos_best.y, orte.est_pos_best.phi);
+                       trailEstPosBest->addPoint(QPointF(orte.est_pos_best.x,
+                                                 orte.est_pos_best.y));
+                       hokuyoScan->setPosition(orte.est_pos_best.x,
+                                               orte.est_pos_best.y,
+                                               orte.est_pos_best.phi);
+                       sickScan->setPosition(orte.est_pos_best.x,
+                                               orte.est_pos_best.y,
+                                               orte.est_pos_best.phi);
+                       sick551Scan->setPosition(orte.est_pos_best.x,
+                                               orte.est_pos_best.y,
+                                               orte.est_pos_best.phi);
                        break;
                case QEVENT(QEV_POWER_VOLTAGE):
                        emit powerVoltageReceivedSignal();
@@ -629,37 +753,37 @@ bool RobomonAtlantis::event(QEvent *event)
 
 void RobomonAtlantis::keyPressEvent(QKeyEvent *event)
 {
-       double peak, gain;
+//     double peak, gain;
 
        if (event->isAutoRepeat()) {
                switch (event->key()) {
-                       case Qt::Key_Down:
-                               peak = leftMotorSlider->minimum()/2;
-                               if (leftMotorValue < peak ||
-                                       rightMotorValue < peak)
-                                       gain = 1.01;
-                               else
-                                       gain = 1.3;
-                               leftMotorValue *= gain;
-                               rightMotorValue *= gain;
-                               leftMotorSlider->setValue((int)leftMotorValue);
-                               rightMotorSlider->setValue((int)rightMotorValue);
-                               break;
-
-                       case Qt::Key_Up:
-                       case Qt::Key_Left:
-                       case Qt::Key_Right:
-                               peak = leftMotorSlider->maximum()/2;
-                               if (leftMotorValue > peak ||
-                                       rightMotorValue > peak)
-                                       gain = 1.01;
-                               else
-                                       gain = 1.3;
-                               leftMotorValue *= gain;
-                               rightMotorValue *= gain;
-                               leftMotorSlider->setValue((int)leftMotorValue);
-                               rightMotorSlider->setValue((int)rightMotorValue);
-                               break;
+//                     case Qt::Key_Down:
+//                             peak = leftMotorSlider->minimum()/2;
+//                             if (leftMotorValue < peak ||
+//                                     rightMotorValue < peak)
+//                                     gain = 1.01;
+//                             else
+//                                     gain = 1.3;
+//                             leftMotorValue *= gain;
+//                             rightMotorValue *= gain;
+//                             leftMotorSlider->setValue((int)leftMotorValue);
+//                             rightMotorSlider->setValue((int)rightMotorValue);
+//                             break;
+
+//                     case Qt::Key_Up:
+//                     case Qt::Key_Left:
+//                     case Qt::Key_Right:
+//                             peak = leftMotorSlider->maximum()/2;
+//                             if (leftMotorValue > peak ||
+//                                     rightMotorValue > peak)
+//                                     gain = 1.01;
+//                             else
+//                                     gain = 1.3;
+//                             leftMotorValue *= gain;
+//                             rightMotorValue *= gain;
+//                             leftMotorSlider->setValue((int)leftMotorValue);
+//                             rightMotorSlider->setValue((int)rightMotorValue);
+//                             break;
 
                        default:
                                event->ignore();
@@ -669,36 +793,36 @@ void RobomonAtlantis::keyPressEvent(QKeyEvent *event)
        }
 
        switch (event->key()) {
-               case Qt::Key_Up:
-                       leftMotorValue = 1;
-                       rightMotorValue = 1;
-                       bothMotorsCheckBox->setChecked(true);
-                       leftMotorSlider->setValue((int)leftMotorValue);
-                       setLeftMotor((int)leftMotorValue);
-                       break;
-               case Qt::Key_Down:
-                       leftMotorValue = -1;
-                       rightMotorValue = -1;
-                       bothMotorsCheckBox->setChecked(true);
-                       leftMotorSlider->setValue((int)leftMotorValue);
-                       setLeftMotor((int)leftMotorValue);
-                       break;
-               case Qt::Key_Left:
-                       leftMotorValue = -1;
-                       rightMotorValue = 1;
-                       leftMotorSlider->setValue((int)leftMotorValue);
-                       rightMotorSlider->setValue((int)rightMotorValue);
-                       setLeftMotor((int)leftMotorValue);
-                       setRightMotor((int)leftMotorValue);
-                       break;
-               case Qt::Key_Right:
-                       leftMotorValue = 1;
-                       rightMotorValue = -1;
-                       leftMotorSlider->setValue((int)leftMotorValue);
-                       rightMotorSlider->setValue((int)rightMotorValue);
-                       setLeftMotor((int)leftMotorValue);
-                       setRightMotor((int)rightMotorValue);
-                       break;
+//             case Qt::Key_Up:
+//                     leftMotorValue = 1;
+//                     rightMotorValue = 1;
+//                     bothMotorsCheckBox->setChecked(true);
+//                     leftMotorSlider->setValue((int)leftMotorValue);
+//                     setLeftMotor((int)leftMotorValue);
+//                     break;
+//             case Qt::Key_Down:
+//                     leftMotorValue = -1;
+//                     rightMotorValue = -1;
+//                     bothMotorsCheckBox->setChecked(true);
+//                     leftMotorSlider->setValue((int)leftMotorValue);
+//                     setLeftMotor((int)leftMotorValue);
+//                     break;
+//             case Qt::Key_Left:
+//                     leftMotorValue = -1;
+//                     rightMotorValue = 1;
+//                     leftMotorSlider->setValue((int)leftMotorValue);
+//                     rightMotorSlider->setValue((int)rightMotorValue);
+//                     setLeftMotor((int)leftMotorValue);
+//                     setRightMotor((int)leftMotorValue);
+//                     break;
+//             case Qt::Key_Right:
+//                     leftMotorValue = 1;
+//                     rightMotorValue = -1;
+//                     leftMotorSlider->setValue((int)leftMotorValue);
+//                     rightMotorSlider->setValue((int)rightMotorValue);
+//                     setLeftMotor((int)leftMotorValue);
+//                     setRightMotor((int)rightMotorValue);
+//                     break;
                default:
                        event->ignore();
                        break;
@@ -714,16 +838,16 @@ void RobomonAtlantis::keyReleaseEvent(QKeyEvent *event)
        }
 
        switch (event->key()) {
-               case Qt::Key_Up:
-               case Qt::Key_Down:
-               case Qt::Key_Left:
-               case Qt::Key_Right:
-                       leftMotorValue = 0;
-                       rightMotorValue = 0;
-                       bothMotorsCheckBox->setChecked(false);
-                       leftMotorSlider->setValue((int)leftMotorValue);
-                       rightMotorSlider->setValue((int)rightMotorValue);
-                       break;
+//             case Qt::Key_Up:
+//             case Qt::Key_Down:
+//             case Qt::Key_Left:
+//             case Qt::Key_Right:
+//                     leftMotorValue = 0;
+//                     rightMotorValue = 0;
+//                     bothMotorsCheckBox->setChecked(false);
+//                     leftMotorSlider->setValue((int)leftMotorValue);
+//                     rightMotorSlider->setValue((int)rightMotorValue);
+//                     break;
                default:
                        event->ignore();
                        break;
@@ -743,8 +867,7 @@ void RobomonAtlantis::createOrte()
 {
        int rv;
 
-       orte.strength = 11;
-       
+       memset(&orte, 0, sizeof(orte));
        rv = robottype_roboorte_init(&orte);
        if (rv) {
                printf("RobomonAtlantis: Unable to initialize ORTE\n");
@@ -755,35 +878,42 @@ void RobomonAtlantis::createOrte()
 
        robottype_publisher_pwr_ctrl_create(&orte, dummy_publisher_callback, NULL);
        robottype_publisher_robot_cmd_create(&orte, NULL, &orte);
+       robottype_publisher_robot_switches_create(&orte, dummy_publisher_callback, &orte);
 
        /* subscribers */
-       robottype_subscriber_pwr_voltage_create(&orte, 
+       robottype_subscriber_pwr_voltage_create(&orte,
                                receivePowerVoltageCallBack, this);
-       robottype_subscriber_motion_status_create(&orte, 
+       robottype_subscriber_motion_status_create(&orte,
                                receiveMotionStatusCallBack, this);
-       robottype_subscriber_ref_pos_create(&orte, 
+       robottype_subscriber_ref_pos_create(&orte,
                                receiveActualPositionCallBack, this);
-       robottype_subscriber_est_pos_odo_create(&orte, 
+       robottype_subscriber_est_pos_odo_create(&orte,
                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_ODO));
-       robottype_subscriber_est_pos_indep_odo_create(&orte, 
+       robottype_subscriber_est_pos_indep_odo_create(&orte,
                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_INDEP_ODO));
-       robottype_subscriber_hokuyo_scan_create(&orte, 
-                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_HOKUYO_SCAN));
-       robottype_subscriber_fsm_main_create(&orte, 
-                                            rcv_fsm_main_cb, this);
-       robottype_subscriber_fsm_motion_create(&orte, 
-                                            rcv_fsm_motion_cb, this);
-       robottype_subscriber_fsm_act_create(&orte, 
-                                            rcv_fsm_act_cb, this);
+       robottype_subscriber_est_pos_best_create(&orte,
+                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_BEST));
+       robottype_subscriber_sick_scan_create(&orte,
+                                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_SICK_SCAN));
+       robottype_subscriber_sick551_scan_create(&orte,
+                                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_SICK551_SCAN));
+       robottype_subscriber_hokuyo_scan_create(&orte,
+                                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_HOKUYO_SCAN));
+       robottype_subscriber_fsm_main_create(&orte,
+                                                rcv_fsm_main_cb, this);
+       robottype_subscriber_fsm_motion_create(&orte,
+                                                rcv_fsm_motion_cb, this);
+       robottype_subscriber_fsm_act_create(&orte,
+                                                rcv_fsm_act_cb, this);
 
        /* motors */
        orte.motion_speed.left = 0;
        orte.motion_speed.right = 0;
 
        /* power management */
-        orte.pwr_ctrl.voltage33 = true;
-        orte.pwr_ctrl.voltage50 = true;
-        orte.pwr_ctrl.voltage80 = true;
+               orte.pwr_ctrl.voltage33 = true;
+               orte.pwr_ctrl.voltage50 = true;
+               orte.pwr_ctrl.voltage80 = true;
        voltage33CheckBox->setChecked(true);
        voltage50CheckBox->setChecked(true);
        voltage80CheckBox->setChecked(true);
@@ -791,11 +921,11 @@ void RobomonAtlantis::createOrte()
        act_init(&orte);
 
        /* set actions to do when we receive data from orte */
-       connect(this, SIGNAL(motionStatusReceivedSignal()), 
+       connect(this, SIGNAL(motionStatusReceivedSignal()),
                        this, SLOT(motionStatusReceived()));
-       connect(this, SIGNAL(actualPositionReceivedSignal()), 
+       connect(this, SIGNAL(actualPositionReceivedSignal()),
                        this, SLOT(actualPositionReceived()));
-       connect(this, SIGNAL(powerVoltageReceivedSignal()), 
+       connect(this, SIGNAL(powerVoltageReceivedSignal()),
                        this, SLOT(powerVoltageReceived()));
 }
 
@@ -811,7 +941,7 @@ void RobomonAtlantis::actualPositionReceived()
        actPosPhi->setText(QString("%1(%2)")
                        .arg(DEGREES(orte.ref_pos.phi), 0, 'f', 0)
                        .arg(orte.ref_pos.phi, 0, 'f', 1));
-       robotRefPos->moveRobot(orte.ref_pos.x, 
+       robotRefPos->moveRobot(orte.ref_pos.x,
                orte.ref_pos.y, orte.ref_pos.phi);
        trailRefPos->addPoint(QPointF(orte.ref_pos.x, orte.ref_pos.y));
 }
@@ -841,43 +971,43 @@ void RobomonAtlantis::openSharedMemory()
                return;
 
        sharedSegmentSize = sizeof(unsigned int) * MAP_WIDTH * MAP_HEIGHT;
-       
+
        /* Get segment identificator in a read only mode  */
        segmentId = shmget(SHM_MAP_KEY, sharedSegmentSize, S_IRUSR);
        if(segmentId == -1) {
-               QMessageBox::critical(this, "robomon",
-                               "Unable to open shared memory segment!");
-               return;
+               statusBar->showMessage("No external map found - creating a new map.");
        }
-       
+
        /* Init Shmap */
        ShmapInit(0);
-       
+
        /* Attach the shared memory segment */
        //map =  (_Map*)shmat (segmentId, (void*) 0, 0);
 
        sharedMemoryOpened = true;
 }
 
-double RobomonAtlantis::distanceToWallHokuyo(int beamnum)
+double RobomonAtlantis::distanceToWallLidar(const struct lidar_params lidar, int beamnum)
 {
-       double distance=4.0, min_distance=4.0;
-       int i,j;
+       double distance = 4.0, min_distance = 4.0;
+       int i, j;
        Point wall;
        struct map *map = ShmapIsMapInit();
 
-       if (!map) return min_distance;
-       
+       if (!map)
+               return min_distance;
+
        // Simulate obstacles
-       for(j=0;j<MAP_HEIGHT;j++) {
-               for (i=0;i<MAP_WIDTH;i++) {
+       for(j = 0; j < MAP_HEIGHT; j++) {
+               for (i = 0; i < MAP_WIDTH; i++) {
                        struct map_cell *cell = &map->cells[j][i];
                        if( cell->flags & MAP_FLAG_SIMULATED_WALL) {
                                // WALL
                                ShmapCell2Point(i, j, &wall.x, &wall.y);
-                               
-                               distance = distanceToObstacleHokuyo(beamnum, wall, MAP_CELL_SIZE_M);
-                               if (distance<min_distance) min_distance = distance;
+
+                               distance = distanceToObstacleLidar(lidar, beamnum, wall, MAP_CELL_SIZE_M);
+                               if (distance < min_distance)
+                                       min_distance = distance;
                        }
                }
        }
@@ -885,47 +1015,110 @@ double RobomonAtlantis::distanceToWallHokuyo(int beamnum)
        return min_distance;
 }
 
-/** 
- * Calculation for Hokuyo simulation. Calculates distance that would
- * be returned by Hokuyo sensors, if there is only one obstacle (as
+double RobomonAtlantis::distanceToCircularObstacleLidar(const struct lidar_params lidar, int beamnum, Point center, double diameter)
+{
+       struct robot_pos_type e = orte.est_pos_best;
+       double sensor_a;
+       struct sharp_pos s;
+
+       s.x = lidar.center_offset_m;
+       s.y = 0.0;
+       s.ang = index2rad(lidar, beamnum);
+
+       Point sensor(e.x + s.x*cos(e.phi) - s.y*sin(e.phi),
+                        e.y + s.x*sin(e.phi) + s.y*cos(e.phi));
+       sensor_a = e.phi + s.ang;
+
+       const double sensorRange = 4.0; /*[meters]*/
+
+       double distance = sensorRange;
+       double angle;
+
+       angle = sensor.angleTo(center) - sensor_a;
+       angle = fmod(angle, 2.0 * M_PI);
+       if (angle > +M_PI) angle -= 2.0 * M_PI;
+       if (angle < -M_PI) angle += 2.0 * M_PI;
+       angle = fabs(angle);
+
+       double k = tan(sensor_a);
+       double r = diameter / 2.0;
+
+       double A = 1 + k * k;
+       double B = 2 * (sensor.y * k - center.x - k * k * sensor.x - center.y * k);
+       double C = center.x * center.x + center.y * center.y +
+               k * k * sensor.x * sensor.x - 2*sensor.y*k*sensor.x +
+               sensor.y * sensor.y + 2 * k * sensor.x *center.y -
+               2 * sensor.y * center.y - r * r;
+
+       double D = B * B - 4 * A * C;
+       
+       if (D > 0) {
+               Point ob1, ob2;
+
+               ob1.x = (-B + sqrt(D)) / (2 * A);
+               ob2.x = (-B - sqrt(D)) / (2 * A);
+               ob1.y = k * (ob1.x - sensor.x) + sensor.y;
+               ob2.y = k * (ob2.x - sensor.x) + sensor.y;
+
+               double distance1 = sensor.distanceTo(ob1);
+               double distance2 = sensor.distanceTo(ob2);
+               distance = (distance1 < distance2) ? distance1 : distance2;
+       } else if (D == 0) {
+               Point ob;
+               ob.x = -B / (2 * A);
+               ob.y = k * (ob.x - sensor.x) + sensor.y;
+               distance = sensor.distanceTo(ob);
+       }
+       distance = distance + (drand48() - 0.5) * 3.0e-2;
+       if (D < 0 || angle > atan(r / distance))
+               distance = sensorRange;
+       if (distance > sensorRange)
+               distance = sensorRange;
+
+       return distance;
+}
+
+/**
+ * Calculation for Lidar simulation. Calculates distance that would
+ * be returned by Lidar sensors, if there is only one obstacle (as
  * specified by parameters).
  *
- * @param beamnum Hokuyo's bean number [0..HOKUYO_CLUSTER_CNT]
+ * @param beamnum Lidar's bean number [0..LIDAR_CLUSTER_CNT]
  * @param obstacle Position of the obstacle (x, y in meters).
  * @param obstacleSize Size (diameter) of the obstacle in meters.
- * 
+ *
  * @return Distance measured by sensors in meters.
- */    
-double RobomonAtlantis::distanceToObstacleHokuyo(int beamnum, Point obstacle, double obstacleSize)
-{  
-       struct robot_pos_type e = orte.est_pos_indep_odo;
+ */
+double RobomonAtlantis::distanceToObstacleLidar(const struct lidar_params lidar, int beamnum, Point obstacle, double obstacleSize)
+{
+       struct robot_pos_type e = orte.est_pos_best;
        double sensor_a;
        struct sharp_pos s;
 
-       s.x = HOKUYO_CENTER_OFFSET_M;
+       s.x = lidar.center_offset_m;
        s.y = 0.0;
-       s.ang = HOKUYO_INDEX_TO_RAD(beamnum);
+       s.ang = index2rad(lidar, beamnum);
 
-       Point sensor(e.x + s.x*cos(e.phi) - s.y*sin(e.phi),
-                    e.y + s.x*sin(e.phi) + s.y*cos(e.phi));
+       Point sensor(e.x + s.x * cos(e.phi) - s.y * sin(e.phi),
+                        e.y + s.x * sin(e.phi) + s.y * cos(e.phi));
        sensor_a = e.phi + s.ang;
-       
+
        const double sensorRange = 4.0; /*[meters]*/
-       
+
        double distance, angle;
-           
+
        angle = sensor.angleTo(obstacle) - sensor_a;
-       angle = fmod(angle, 2.0*M_PI);
-       if (angle > +M_PI) angle -= 2.0*M_PI;
-       if (angle < -M_PI) angle += 2.0*M_PI;
+       angle = fmod(angle, 2.0 * M_PI);
+       if (angle > +M_PI) angle -= 2.0 * M_PI;
+       if (angle < -M_PI) angle += 2.0 * M_PI;
        angle = fabs(angle);
-       distance = sensor.distanceTo(obstacle)-0.11;
-       if (angle < atan(obstacleSize/2.0 / (distance+0.001))) {
+       distance = sensor.distanceTo(obstacle) - obstacleSize/2.0;
+       if (angle < atan(obstacleSize/2.0 / distance)) {
                // We can see the obstackle from here.
                if (angle < M_PI/2.0) {
-                   distance = distance/cos(angle);
+                       distance = distance / cos(angle);
                }
-               if (distance > sensorRange) 
+               if (distance > sensorRange)
                        distance = sensorRange;
        } else {
                distance = sensorRange;
@@ -936,20 +1129,33 @@ double RobomonAtlantis::distanceToObstacleHokuyo(int beamnum, Point obstacle, do
 
 void RobomonAtlantis::sendStart(int plug)
 {
-       orte.robot_cmd.start = plug ? 0 : 1;
+       orte.robot_cmd.start_condition = plug ? 0 : 1;
        ORTEPublicationSend(orte.publication_robot_cmd);
 }
 
+void RobomonAtlantis::setTeamColor(int plug)
+{
+       orte.robot_switches.team_color = plug ? 1 : 0;
+       ORTEPublicationSend(orte.publication_robot_switches);
+}
+
 void RobomonAtlantis::resetTrails()
 {
        trailRefPos->reset();
+       trailEstPosBest->reset();
        trailPosIndepOdo->reset();
        trailOdoPos->reset();
 }
 
 void RobomonAtlantis::showTrails(bool show)
 {
-       trailRefPos->setVisible(show);
-       trailPosIndepOdo->setVisible(show);
-       trailOdoPos->setVisible(show);
+       trailRefPos->setVisible(show && robotRefPos->isVisible());
+       trailEstPosBest->setVisible(show && robotEstPosBest->isVisible());
+       trailPosIndepOdo->setVisible(show && robotEstPosIndepOdo->isVisible());
+       trailOdoPos->setVisible(show && robotEstPosOdo->isVisible());
+}
+
+void RobomonAtlantis::showShapeDetect(bool show)
+{
+       hokuyoScan->showShapeDetect = show;
 }