/** * \brief Entering the robot into the "Attachement mode" * \detailed In this mode, the robot will look for a source of high heat and will follow it. If the robot doesn't find a source * after a period of time, it goes into a panic mode, which is turning around itself forever until it detects a heat source and follows it. * \param pvParameters - pointer to parameters */ static void attachmentMode(void * pvParameters) { TickType_t xLastWakeTime = xTaskGetTickCount(); uint8_t distance = 0, panicModeCounter = 0, panicModeEnabledCount = 250; uint16_t currentPulseWidthTicks = INITIAL_PULSE_WIDTH_TICKS; // Initialize as search mode ATTACHMENT_MODE = SEARCH_MODE; // Head needs to be facing forward motion_servo_start(MOTION_SERVO_CENTER); rotateHead(¤tPulseWidthTicks); while (1) { // If we have new temperature data if(hasNewValues == 1){ hasNewValues = 0; // the highest temperature sensed is greater than the trigger temperature if ((uint8_t) TRIGGER_TEMPERATURE < temperatures[indexOfHighestTemperature]) { // We are tracking a heat source! ATTACHMENT_MODE = TRACKING_MODE; // reset panic mode counter panicModeCounter = 0; // get the distance to the heat source distance = getDistance(); // if the highest heat source is not in the center if (indexOfHighestTemperature != 4 || indexOfHighestTemperature != 5) { // turn towards the heat source turnToAngle(45 - 10 * indexOfHighestTemperature); } // get as close to target as possible moveToTarget(distance); // no temperature is higher than the trigger temperature // increment the panic mode counter and check if we have reached the panic mode enabled count } else if (panicModeEnabledCount <= panicModeCounter) { ATTACHMENT_MODE = PANIC_MODE; setMovementType(ROTATE_RIGHT_MOVEMENT); } else { ++panicModeCounter; // Stop movement because we're no longer tracking a heat source setMovementType(STOP_MOVEMENT); // No longer in tracking or panic mode ATTACHMENT_MODE = SEARCH_MODE; } } vTaskDelayUntil(&xLastWakeTime, ((30000 / panicModeEnabledCount) / portTICK_PERIOD_MS)); } }
// Constructor AboutWindow::AboutWindow(QWidget *parent) : QDialog(parent) { QGridLayout* layout = new QGridLayout( this ); // Make the graphics view fixed size QGraphicsView* graphicsView = new QGraphicsView; graphicsView->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); graphicsView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); graphicsView->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); // Make the version text bold QLabel* appVersion = new QLabel( "Cache Simulator, Version 0.0.2" ); QFont font; font.setPointSize( 10 ); font.setBold( true ); font.setWeight( 75 ); appVersion->setFont( font ); QLabel* descrip = new QLabel( HELP_TEXT ); descrip->setWordWrap( true ); QSpacerItem* vSpace = new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding ); // Add widgets to the layout layout->addWidget( graphicsView, 0, 0, 2, 1 ); layout->addWidget( appVersion, 0, 2, 1, 1 ); layout->addWidget( descrip, 1, 2, 1, 1 ); layout->addItem( vSpace, 1, 1, 1, 1 ); // Position a picture of Dr. Plassmann's head over his shoulders _plassHead = new QGraphicsPixmapItem; _plassHead->setPixmap( QPixmap("PlassHead.png") ); _plassHead->setTransformOriginPoint( _plassHead->pixmap().width()/2, _plassHead->pixmap().height()/2 ); _plassHead->setPos( 30, 8 ); _angle = 0; // Tell the view which scene to show QGraphicsScene* scene = new QGraphicsScene; scene->addPixmap( QPixmap("PlassGround.png") ); scene->addItem( _plassHead ); graphicsView->setScene( scene ); // Set a timer to rotate Dr. Plassmann's head every 20 ms _rotateTimer = new QTimer( this ); connect( _rotateTimer, SIGNAL(timeout()), this, SLOT(rotateHead()) ); _angle = 720; _rotateTimer->start( 20 ); // Do not allow resizing setFixedSize( this->sizeHint() ); }
/** * \brief Make the head scan left to right, then right to left * \param pvParameters - pointer to parameters */ static void moveHead(void *pvParameters) { TickType_t xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); uint16_t currentPulseWidthTicks = INITIAL_PULSE_WIDTH_TICKS; //init head motor motion_servo_start(MOTION_SERVO_CENTER); while (1) { // Rotate the head to the next logical position given its current position rotateHead(¤tPulseWidthTicks); // Execute every x milliseconds vTaskDelayUntil(&xLastWakeTime, (10 / portTICK_PERIOD_MS)); } }
void callMotionFunc(int x, int y) { switch(g_mouseCurrentButton) { case LEFT : rotateHead ((g_mousePreviousX - x) / 10.0); nodHead ((g_mousePreviousY - y) / 10.0); break; case MIDDLE : rotateZ ((g_mousePreviousX - x) / 10.0); zoom ((g_mousePreviousY - y) / 10.0); break; case RIGHT : translateY ((g_mousePreviousX - x) / 10.0); translateX ((g_mousePreviousY - y) / 10.0); break; default: break; } g_mousePreviousX = x; g_mousePreviousY = y; }
void callSpecialFunc(int key, int x, int y) { int sens; /* sens positif ou negatif */ if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) { sens = -1; } else { sens = 1; } // Global modifications switch(key) { case GLUT_KEY_LEFT: rotateHead(OBS_ROTATING_HEAD); break; case GLUT_KEY_RIGHT: rotateHead(-OBS_ROTATING_HEAD); break; case GLUT_KEY_UP: nodHead(-OBS_NODING_HEAD); break; case GLUT_KEY_DOWN: nodHead(OBS_NODING_HEAD); break; case GLUT_KEY_F7: if(scene->tabsource[0].allume == 0) { scene->tabsource[0].allume = 1; } else { scene->tabsource[0].allume = 0; } break; case GLUT_KEY_F8: /* switch lighting */ g_switchLight ^= 1; break; case GLUT_KEY_F9: /* turn on or off infinite light */ if(g_dayTime == DAY) { g_dayTime = NIGHT; charger_skybox(NIGHT); scene->tabsource[0].allume = 0; turnOnLight(g_scenes3DS[ANIMATED_KART_ID].lights[0]); turnOnLight(g_scenes3DS[ANIMATED_KART_ID].lights[1]); } else if(g_dayTime == NIGHT) { g_dayTime = DAY; charger_skybox(DAY); scene->tabsource[0].allume = 1; turnOffLight(g_scenes3DS[ANIMATED_KART_ID].lights[0]); turnOffLight(g_scenes3DS[ANIMATED_KART_ID].lights[1]); } redefineLights(); break; case GLUT_KEY_F10: switchLight(g_scenes3DS[ANIMATED_KART_ID].lights[0]); switchLight(g_scenes3DS[ANIMATED_KART_ID].lights[1]); redefineLights(); break; case GLUT_KEY_F11: /* turn on or off kart's lights */ switchLight(g_scenes3DS[KART_ID].lights[0]); switchLight(g_scenes3DS[KART_ID].lights[1]); redefineLights(); break; case GLUT_KEY_F12: /* rotate selon direction axe z */ rotateZ(sens * OBS_ROTATING_Z); break; } // Is an object currently selected ? if(g_currentObj < 0) { return ; } // Local modification ==> On an object switch (key) { case GLUT_KEY_F1: /* avance selon direction axe x */ translate(&(scene->tabobj[g_currentObj]), TRANSLATING * sens, 0.0, 0.0); break; case GLUT_KEY_F2: /* avance selon direction axe y */ if(g_currentObj < 0) { return ; } translate(&(scene->tabobj[g_currentObj]), 0.0, TRANSLATING * sens, 0.0); break; case GLUT_KEY_F3: /* avance selon direction axe z */ if(g_currentObj < 0) { return ; } translate(&(scene->tabobj[g_currentObj]), 0.0, 0.0, TRANSLATING * sens); break; case GLUT_KEY_F4: /* rotate selon direction axe x */ if(g_currentObj < 0) { return ; } rotate(&(scene->tabobj[g_currentObj]), ROTATING * sens, 0.0, 0.0); break; case GLUT_KEY_F5: /* rotate selon direction axe y */ if(g_currentObj < 0) { return ; } rotate(&(scene->tabobj[g_currentObj]), 0.0, ROTATING * sens, 0.0); break; case GLUT_KEY_F6: /* rotate selon direction axe z */ if(g_currentObj < 0) { return ; } rotate(&(scene->tabobj[g_currentObj]), 0.0, 0.0, ROTATING * sens); break; } glutPostRedisplay(); }