/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initializeSensors(); P1DIR |= 0x41; // Set P1.0 to output direction for (;;) { checkRightSensor(); if (ADC10MEM < 0x222) { P1OUT &= ~BIT6; // Clear P1.6 LED off } else { P1OUT |= BIT6; // Set P1.6 LED on } _delay_cycles(100000); checkLeftSensor(); if (ADC10MEM < 0x222) { P1OUT &= ~BIT0; // Clear P1.0 LED off } else { P1OUT |= BIT0; // Set P1.0 LED on } _delay_cycles(100000); } }
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initializeSensors(); setUpTimerA(); turnLeftSlight(); for (;;) { int left = checkLeftSensor(), center = checkCenterSensor(), right = checkRightSensor(); if (left > 0x240) { fullStop(); turnRightSlight(); fullStop(); } else if (center > 0x2FF) { fullStop(); __delay_cycles(10000); reverse(); __delay_cycles(10000); fullStop(); __delay_cycles(10000); turnRightSlight(); __delay_cycles(10000); turnRightSlight(); __delay_cycles(10000); fullStop(); } else { turnLeftSlight(); } } }
/* * main.c */ void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer initializeSensors(); P1DIR |= 0x41; // Set P1.0 to output direction for (;;) { //__bis_SR_register(CPUOFF + GIE); // LPM0, ADC10_ISR will force exit checkRightSensor(); if (ADC10MEM < 0x222) { P1OUT &= ~BIT6; // Clear P1.6 LED off } else { P1OUT |= BIT6; // Set P1.6 LED on } _delay_cycles(100000); checkLeftSensor(); if (ADC10MEM < 0x222) { P1OUT &= ~BIT0; // Clear P1.0 LED off } else { P1OUT |= BIT0; // Set P1.0 LED on } _delay_cycles(100000); } }
//Main void main(void) { initBoard(); backlightOn(); //Configure interrupts //Interrupt on RB1 = SW_E OpenRB1INT(PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_OFF & PORTB_INT_PRIO_HIGH); //Interrupt on RB0 = SW_W OpenRB0INT(PORTB_CHANGE_INT_ON & FALLING_EDGE_INT & PORTB_PULLUPS_OFF & PORTB_INT_PRIO_LOW); //Enable button input => not needed, see dwengoBoard.c->initBoard(); TRISB = 0xFF; //Init motors initializeMotors(); initializeSensors(); while (TRUE) { if(SW_N == 0) { mode = 0; clearLCD(); printStringToLCD("Doing moves brah", 1, 0); leftMotor(700); rightMotor(700); delay_s(4); leftMotor(1000); rightMotor(700); delay_s(4); leftMotor(700); rightMotor(1000); delay_s(4); leftMotor(-700); rightMotor(700); delay_s(4); } else if(mode == 1) { //Light eating } else if(SW_S == 0) { //Start light eating //mode = 1; clearLCD(); printStringToLCD("Going to send string", 0, 0); initializeRS232(); sendData(); } else { //printStringToLCD("Cool story bro", 0, 0); } } }
SensorModule::SensorModule():shouldRead(true), readInterval(5){ if ((this->i2cBus = open("/dev/i2c-1", O_RDWR)) < 0) { //TODO log in error log printf("Failed to open the bus. \n"); } initializeSensors(); std::thread reader([this]{this->readWorker();}); reader.detach(); };
ScreenPrivate::ScreenPrivate(Screen *qq) : q_ptr(qq), desktop(QApplication::desktop()), screenRotation(0.0), rotationCorrection(0.0), orientation(Screen::Portrait), orientationLocked(false) { appScreen = desktop->primaryScreen(); screenCount = desktop->screenCount(); QObject::connect(desktop, SIGNAL(screenCountChanged(int)), qq, SLOT(_q_updateScreenCount(int))); initializeSensors(); // emit displayChanged QMetaObject::invokeMethod(q_ptr, "displayChanged", Qt::QueuedConnection); }
int main( void ) { halInit(); moduleInit(); HAL_DISABLE_INTERRUPTS(); printf("\r\n****************************************************\r\n"); printf("Simple Application Example - END DEVICE\r\n"); uint16_t vlo = calibrateVlo(); printf("VLO = %u Hz\r\n", vlo); timerIsr = &handleTimer; clearLeds(); HAL_ENABLE_INTERRUPTS(); /* Most of the of infoMessage are the same, so we can create most of the message ahead of time. */ hdr.sequence = 0; //this will be incremented each message hdr.version = INFO_MESSAGE_VERSION; hdr.flags = INFO_MESSAGE_FLAGS_NONE; initializeSensors(); delayMs(100); stateMachine(); }
//------------[AUTO:RAMP START]------------// //Position: Centered on the ramp // //Orientation: Intake forward, sensor forward// task main() { initializeRobot(); waitForStart(); initializeSensors(); calibrateSensors(); startTask(display); startTask(sensorPoll); startTask(DCControl); startTask(servoControl); //1. Go down Ramp// rampMove(); //2. Move to IR checking Position// spinDeg(-85.0); moveStraight(70.0, 25.0); //3. IR Beacon Position Search// for(int i = 0; i < 20; i++) { /*writeDebugStreamLine("irSeeker.acValues[0]: %d", irSeeker.acValues[0]); wait1Msec(100); writeDebugStreamLine("irSeeker.acValues[1]: %d", irSeeker.acValues[1]); wait1Msec(100); writeDebugStreamLine("irSeeker.acValues[2]: %d", irSeeker.acValues[2]); wait1Msec(100); writeDebugStreamLine("irSeeker.acValues[3]: %d", irSeeker.acValues[3]); wait1Msec(100); writeDebugStreamLine("irSeeker.acValues[4]: %d", irSeeker.acValues[4]); wait1Msec(100);*/ readSensor(&irSeeker); if(irSeeker.acValues[2] >= 40) { irCounter1++; } else if(irSeeker.acValues[2] >= 28 || irSeeker.acValues[3] > 20) { irCounter2++; } else if(irSeeker.acValues[2] < 28) { irCounter3++; } } if(irCounter1 > irCounter3 && irCounter1 > irCounter2) { pos = 3; } else if(irCounter2 > irCounter3 && irCounter2 > irCounter1) { pos = 2; } else if(irCounter3 > irCounter1 && irCounter3 > irCounter2) { pos = 1; } /*writeDebugStreamLine("irCounter1 : %d", irCounter1); writeDebugStreamLine("irCounter2 : %d", irCounter2); writeDebugStreamLine("irCounter3 : %d", irCounter3); writeDebugStreamLine("pos: %d", pos);*/ switch(pos) { //4a. Knock kickstand Down// case 1: spinDeg(-5.0); moveStraight(70.0, 60.0); spinDeg(-87.0); moveStraight(70.0, 20.0); moveStraight(-70.0, 10.0); break; //4b. Knock kickstand Down// case 2: moveStraight(70.0, 45.0); spinDeg(-45.0); moveStraight(70.0, 40.0); moveStraight(-70.0, 20.0); break; //4c. Knock kickstand Down// case 3: spinDeg(-45.0); moveStraight(70.0, 73.0); spinDeg(45.0); moveStraight(70.0, 45.0); moveStraight(-70.0, 20.0); break; //4d. Go to goal// default: moveStraight(70.0, 61.0); spinDeg(90.0); moveStraight(70.0, 61.0); spinDeg(45.0); break; } //5. Tubes Go Up// //plateOpen = true; //intakeDown = true; //tubesUp = true; //Edit this sleep variable with the tubesUp timing// //sleep(6000); //6. Head Goes Up// //headUp = true; while(true){} }
// Declare Global variables int main(void) { // Set up Create and module initializeCommandModule(); powerOnRobot(); // Is the Robot on byteTx(CmdStart); // Start the create baud(Baud57600); // Set the baud rate for the Create and Command Module defineSongs(); // Define some songs so that we know the robot is on. byteTx(CmdControl); // Deprecated form of safe mode. I use it because it will // turn of all LEDs, so it's essentially a reset. byteTx(CmdFull); // We are operating in FULL mode. // Play the reset song and wait while it plays. byteTx(CmdPlay); byteTx(RESET_SONG); delayMs(750); // Turn the power button on to something. initializeSensors(); // Sets up sensors. delayMs(200); // Gives the robot time to process. allowDriving(); // Enables Driving. enableOrders(); // Enables driveOrders() initializePlanner(); // Sets up the planner. decidePlanState(); // Decide on an initial state of the planner. disableIntegral(); // Integral term only used for state MAKETURN. //int16_t speed = DRIVESPEED; // Standard speed. delayMs(500); // Gives the robot time to process all of the above before continuing. // Infinite operation loop while(1) { compileSensors(); // Build the sensor Struct. Automatic Polling. decidePlanState(); delayMs(50); // The above operations are time-consuming, so wait. switch (getPlanState()) { case FINDWALL: debugLEDOff(); delayMs(10); break; case REPOSITION: buildInfrared(); buoyLights(); doDocking(); break; case STOP: driveOrders(0, 0, 50); debugLEDOff(); delayMs(10); break; default: debugLEDOff(); // Turn on the lights. delayMs(10); break; } } }