void ObjMonster::actionWalk(Point des){ if(getState() == EobjState::E_HURT) return; Point destination = getPointInMap(des); assert(rootObj); rootObj->stopAllActions(); setState(EobjState::E_WALK); if((destination.x < rootObj->getPosition().x && dir == EDIR_FORWARD) || (destination.x > rootObj->getPosition().x && dir == EDIR_BACKWARD)){ turnAround(); } Animation* walk = createAnimateWithFileNames("RobotRun%d.png", 6); walk->setDelayPerUnit(0.1); auto action = Animate::create(walk); float distance = sqrtf((destination.x - rootObj->getPositionX()) * (destination.x - rootObj->getPositionX()) + (destination.y - rootObj->getPositionY()) * (destination.y - rootObj->getPositionY())); float dur = distance / speed; auto moveTo = MoveTo::create(dur, destination); rootObj->runAction(RepeatForever::create(action)); rootObj->runAction(CCSequence::create(moveTo, CallFunc::create( CC_CALLBACK_0(ObjMonster::actionStand,this)), NULL)); //target->runAction(Follow::create(rootObj)); }
int main(void) { SYSTEMConfigPerformance(40000000); initLCD(); //initialize the LCD enableInterrupts(); initADC(); //initialize the ADC initPWM(); //initialize the PWM initTimer3(); //initialize the timer TRISDbits.TRISD0 = 0; LATDbits.LATD0 = 0; initUART(); //initialize UART sendByte('M'); while(1) { if(U2STAbits.URXDA) { input = U2RXREG; //saves RX reg buffer sendByte(input); //echos pressed key back to prompt sendByte(':'); //sends : to terminal prompt } switch(input) { case 'w': //forward LEFTMOTORDIRECTION1 = 0; LEFTMOTORDIRECTION2 = 1; RIGHTMOTORDIRECTION1 = 0; RIGHTMOTORDIRECTION2 = 1; RW = 700; LW = 700; break; case 'a': //left LEFTMOTORDIRECTION1 = 0; LEFTMOTORDIRECTION2 = 1; RIGHTMOTORDIRECTION1 = 0; RIGHTMOTORDIRECTION2 = 1; RW = 700; LW = 100; break; case 's': //backward LEFTMOTORDIRECTION1 = 1; LEFTMOTORDIRECTION2 = 0; RIGHTMOTORDIRECTION1 = 1; RIGHTMOTORDIRECTION2 = 0; RW = 700; LW = 700; break; case 'd': //right LEFTMOTORDIRECTION1 = 0; LEFTMOTORDIRECTION2 = 1; RIGHTMOTORDIRECTION1 = 0; RIGHTMOTORDIRECTION2 = 1; RW = 100; LW = 700; break; case 'p': LEFTMOTORDIRECTION1 = 0; LEFTMOTORDIRECTION2 = 1; RIGHTMOTORDIRECTION1 = 0; RIGHTMOTORDIRECTION2 = 1; RW = 0; LW = 0; break; } startRead(0); //starts reading from ADC (POT) adcVal0 = waitToFinish0(); //save digital value of pot startRead(1); //starts reading from ADC (Leftmost) adcVal1 = waitToFinish1(); //save digital value of leftmost phototransistor startRead(2); //starts reading from ADC (Middle) adcVal2 = waitToFinish2(); //save digital value of middle phototransistor startRead(3); //starts reading from ADC (Rightmost) adcVal3 = waitToFinish3(); //save digital value of rightmost phototransistor moveCursorLCD(0,2); sprintf(str, "%d,%d,%d", adcVal1/10, adcVal2/10, adcVal3/10); printStringLCD(str); scan(); //scan three transistors moveCursorLCD(0,1); sprintf(str, "%d, %d, %d", L1, L2, L3); printStringLCD(str); determineState(); switch(jason) { case followLine_detectEnd: followLine(); detectEnd(); break; case turnAroundJason: turnAround(); break; } } return 0; }
void goBack(int *mx,int *my,int *dir) { turnAround(dir); go(mx,my,*dir); }
// This function checks and deals with atn signal commands // // If a command is recieved, the cmd-string is saved in cmd. Only commands // for *this* device are dealt with. // // Return value, see IEC::ATNCheck definition. IEC::ATNCheck IEC::checkATN(ATNCmd& cmd) { ATNCheck ret = ATN_IDLE; byte i = 0; if(not readATN()) { // Attention line is active, go to listener mode and get message writeDATA(true); writeCLOCK(false); #ifdef CONSOLE_DEBUG //Log(Information, FAC_IEC, "ATT.ACTIVE"); #endif delayMicroseconds(TIMING_ATN_PREDELAY); // Get first ATN byte, it is either LISTEN or TALK ATNCommand c = (ATNCommand)receiveByte(); if(m_state bitand errorFlag) return ATN_ERROR; if(c == (ATN_CODE_LISTEN bitor m_deviceNumber)) { // Okay, we will listen. #ifdef CONSOLE_DEBUG //Log(Information, FAC_IEC, "LISTEN"); #endif // Get the first cmd byte, the cmd code c = (ATNCommand)receiveByte(); if (m_state bitand errorFlag) return ATN_ERROR; //Log(Information, FAC_IEC, "CODE"); cmd.code = c; if((c bitand 0xF0) == ATN_CODE_DATA) { // A heapload of data might come now, client handles this //Log(Information, FAC_IEC, "LDATA"); ret = ATN_CMD_LISTEN; } else if(c not_eq ATN_CODE_UNLISTEN) { #ifdef CONSOLE_DEBUG //Log(Information, FAC_IEC, "CMD"); #endif // Some other command. Record the cmd string until UNLISTEN is send for(;;) { c = (ATNCommand)receiveByte(); if(m_state bitand errorFlag) return ATN_ERROR; if((m_state bitand atnFlag) and (c == ATN_CODE_UNLISTEN)) break; if(i >= ATN_CMD_MAX_LENGTH) { // Buffer is going to overflow, this is an error condition return ATN_ERROR; } cmd.str[i++] = c; } ret = ATN_CMD; } } else if (c == (ATN_CODE_TALK bitor m_deviceNumber)) { // Okay, we will talk soon, record cmd string while ATN is active #ifdef CONSOLE_DEBUG //Log(Information, FAC_IEC, "TALK"); #endif // First byte is cmd code c = (ATNCommand)receiveByte(); if(m_state bitand errorFlag) return ATN_ERROR; cmd.code = c; while(not readATN()) { if(readCLOCK()) { c = (ATNCommand)receiveByte(); if(m_state bitand errorFlag) return ATN_ERROR; if(i >= ATN_CMD_MAX_LENGTH) { // Buffer is going to overflow, this is an error condition return ATN_ERROR; } cmd.str[i++] = c; } } // Now ATN has just been released, do bus turnaround if(!turnAround()) return ATN_ERROR; // We have recieved a CMD and we should talk now: ret = ATN_CMD_TALK; } else { // Either the message is not for us or insignificant, like unlisten. delayMicroseconds(TIMING_ATN_DELAY); writeDATA(false); writeCLOCK(false); // { // char buffer[20]; // sprintf(buffer, "NOTUS: %u", c); // Log(Information, FAC_IEC, buffer); // } // Wait for ATN to release and quit while(not readATN()); //Log(Information, FAC_IEC, "ATNREL"); } } else { // No ATN, release lines writeDATA(false); writeCLOCK(false); } // some delay is required before more ATN business delayMicroseconds(TIMING_ATN_DELAY); cmd.strlen = i; return ret; } // checkATN
void main(void) { init(); STOP(); lcd_set_cursor(0x00); lcd_write_string("(-,-) - -- --- -"); //x/y of robot, explore/return, zone of victim/got victim, walls, way went lcd_set_cursor(0x40); lcd_write_string("- - - (3,1) GREG"); //orientation, cliff detected, v.wall detected, x/y of final destination char victimIndicator = 0; while(!home) { if(start.pressed && ready == FALSE) { findWalls(); if(leftWall && rightWall && frontWall) //if facing east turnAround(); //turn to face west else if (rightWall && frontWall) //if facing north turnLeft90(); //turn to face west else if(leftWall && frontWall) //if facing south turnRight90(); //turn to face west ready = TRUE; //commence exploring the map lcd_set_cursor(0x06); lcd_write_data('E'); //Explore mode play_iCreate_song(1); } //EEPROM Serial Transfer if(eepromSerial.pressed && ready == FALSE) { eepromSerial.pressed = FALSE; lcd_set_cursor(0x00); lcd_write_string("EEPROM Serial "); lcd_set_cursor(0x40); lcd_write_string("Please Wait... "); writeEEPROMTestData(); EEPROMToSerial(); lcd_set_cursor(0x40); lcd_write_string("Complete "); } if(start.pressed) { ready = TRUE; checkForFinalDestination(); lookForVictim(); findWalls(); play_iCreate_song(5); if(leftWall) { rotateIR(24,CCW); leftAngleCorrect(); rotateIR(24,CW); } play_iCreate_song(5); if(frontWall) frontWallCorrect(); play_iCreate_song(5); switch(node) // Gives the Create specific movement instructions for certain squares to go shortest path home and collecting the victim { case 0: goToNextCell(); break; case 1: if (goingHome) { if (victimZone == 1) goRight(); else if (getOrientation() == EAST) goForward(); else if (getOrientation() == SOUTH) goRight(); else goToNextCell(); } else goToNextCell(); break; case 2: if (goingHome) { if (victimZone == 2) goForward(); else if (getOrientation() == SOUTH) goRight(); else if (getOrientation() == NORTH) goLeft(); else goToNextCell(); } else goToNextCell(); break; case 3: if (goingHome) { if (victimZone == 3) goRight(); else if (getOrientation() == EAST) goForward(); else if (getOrientation() == SOUTH) goLeft(); else goToNextCell(); } else goToNextCell(); break; case 4: if (getOrientation() == EAST) goRight(); else goToNextCell(); break; case 5: if (getOrientation() == NORTH) goRight(); else goToNextCell(); break; case 6: if (getOrientation() == WEST) { play_iCreate_song(6); goForward(); } else goToNextCell(); break; default: break; } play_iCreate_song(5); if(getSuccessfulDrive()) { //Send EEPROM data for current cell if(xVictim == xCoord && yVictim == yCoord) { victimIndicator = 1; } /*if(xVirtual == xCoord && yVirtual == yCoord) { switch(dVirtual) { case WEST: { updateMapData(1,0,0,0,victimIndicator,getOrientation()); break; } case SOUTH: { updateMapData(0,1,0,0,victimIndicator,getOrientation()); break; } case EAST: { updateMapData(0,0,1,0,victimIndicator,getOrientation()); break; } case NORTH: { updateMapData(0,0,0,1,victimIndicator,getOrientation()); break; } default: updateMapData(0,0,0,0,victimIndicator,getOrientation()); } }*/ updateMapData(0,0,0,0,victimIndicator,getOrientation()); victimIndicator = 0; updateLocation(); updateNode(); if(goingHome) checkIfHome(); } } } }