int main() // Main function { xbee = fdserial_open( 9, 8, 0, 9600 ); //Initialize communication char c; //Create char while ( 1 ) { c = fdserial_rxChar( xbee ); //get all values sent to the ActivityBot if ( c == 'f' ) //if the robot was told to go forward, go forward { drive_speed( 64, 64 ); } else if ( c == 'b' ) //if the robot was told to go backward, go backward { drive_speed( -64, -64 ); } else if ( c == 'l' ) //if the robot was told to go left, go left { drive_speed( 0, 64 ); } else if ( c == 'r' ) //if the robot was told to go right, go right { drive_speed( 64, 0 ); } else if ( c == 's' ) //if the robot is told to stop, stop { drive_speed( 0, 0 ); } } }
int main() // Main - execution begins! { xbee = fdserial_open(11, 10, 0, 9600); //dprint(xbee, "hello"); //dprint(xbee, "hello"); drive_speed(0,0); // Start servos/encoders cog drive_setRampStep(10); // Set ramping at 10 ticks/sec per 20 ms sirc_setTimeout(50); // Remote timeout = 50 ms //drive_feedback(0); dt = CLKFREQ/10; t = CNT; while(1) // Outer loop { int button = sirc_button(4); // check for remote key press // Motion responses - if key pressed, set wheel speeds if(button == 2) { if(!running) cogstart(&gofwd, NULL, fstack, sizeof fstack); } if(button == 8) { if(!running) cogstart(&gobkwd, NULL, bstack, sizeof bstack); } if(button == CH_UP)drive_rampStep(100, 100); // Left turn if(button == CH_DN)drive_rampStep(-100, -100); // Right turn if(button == VOL_DN)drive_rampStep(-100, 100); // Left turn if(button == VOL_UP)drive_rampStep(100, -100); // Right turn if(button == MUTE)drive_rampStep(0, 0); // Stop if(button == ENTER) { getTicks(); displayTicks(); } if(CNT - t > dt) { t+=dt; i++; getTicks(); if ( ticksLeftCalc != ticksLeftCalcOld || ticksRightCalc != ticksRightCalcOld || ticksLeft != ticksLeftOld || ticksRight != ticksRightOld ) { displayTicks(); } } } }
int main(){ //servo_angle(16,1800); //pause(500); print("This is Receiver!\n"); xbee = fdserial_open(9,8,0,9600); //access these port with the xbee while(1){ command = fdserial_rxChar(xbee); //recieve one bit of data from transmitter if(command == 0) { high(0); low(1); low(2); } else if(command == 1) { low(0); high(1); low(2); } else if(command == 2) { low(0); low(1); high(2); } else { low(0); low(1); low(2); } } }
void MessageStart() { lock = locknew(); lockclr(lock); simpleterm_close(); msg_serial = fdserial_open(31, 30, 0, 115200); cogstart(&HandleSerial, NULL, msg_stack, sizeof(msg_stack)); }
void cmd_init(int wifi_rx, int wifi_tx, int debug_rx, int debug_tx) { // Close default same-cog terminal simpleterm_close(); // Set to open collector instead of driven wifi = fdserial_open(wifi_rx, wifi_tx, 0b0100, 115200); // Generate a BREAK to enter CMD command mode pause(10); low(wifi_tx); pause(1); input(wifi_tx); pause(1); if (debug_tx != -1 && wifi_tx != debug_tx) debug = fdserial_open(debug_rx, debug_tx, 0, 115200); else debug = wifi; }
int main() { //simpleterm_close(); //close default terminal, I want to use those pins //if the default uart pins are not b nused, this isn't needed fdserial *d = fdserial_open(RX_PIN, TX_PIN,0, BAUD); while(1) { fdserial_txChar(d, fdserial_rxChar(d)); } }
void gps_run(void *par) { gps_byte_t tempBuff[16]; gps_byte_t ch; int idx; gps_ser = fdserial_open(_gps_rx_pin, _gps_tx_pin, 0, _gps_baud); for(;;) { if(gps_stopping) { fdserial_close(gps_ser); gps_stopping = 0; } ch = fdserial_rxChar(gps_ser); //search for the start of an NMEA sentence if(ch != '$') continue; //read in characters from the GPS idx = 0; do { ch = fdserial_rxChar(gps_ser); inBuff[idx++] = ch; }while(ch != 13); inBuff[idx] = 0; //null terminate //got the full sentence, do a little prep work to get ready for parsing. //modifies inBuff! PrepBuff(); if(strncmp(inBuff, "GPRMC", 5) == 0) ParseRMC(); if(strncmp(inBuff, "GPGGA", 5) == 0) ParseGGA(); } }
void pollPingSensors(void *par) { // The last IR sensor will be retagged with this position number, // in case there are more PINGs than IRs. const int lastIRposition = 7; propterm = fdserial_open(QUICKSTART_RX_PIN, QUICKSTART_TX_PIN, 0, 115200); //term = fdserial_open(31, 30, 0, 115200); // for Debugging // Initialize variables outside of loop // This may or may not improve performance. int ping = 0, ir = 0; char receivedChar; while(1) // Repeat indefinitely { /* We wait for input from the other side, Which lets us not activate the sensors if the other end is not working, and also lets the other end rate limit the input. */ receivedChar = fdserial_rxChar(propterm); //char receivedChar = 'i'; // for Debugging - Cause it to always run instead of waiting for a signal // Only send data when we get the expected "init" character, avoiding running on random garbage from an open connection if (receivedChar == 'i') { high(16); // LEDs for debugging isActive = 1; for(int i=0; i < NUMBER_OF_PING_SENSORS; i++ ) { ping = ping_cm(FIRST_PING_SENSOR_PIN + i); dprint(propterm, "p,%d,%d.", i, ping); receivedChar = fdserial_rxChar(propterm); // Should get a character after each output for rate limiting //dprint(term, "p,%d,%d\n", i, ping); // For Debugging if(i < NUMBER_OF_IR_SENSORS) { // If there is also an IR sensor at this number check it too ir = mcp3208_IR_cm(i); dprint(propterm, "i,%d,%d.", i, ir); receivedChar = fdserial_rxChar(propterm); // Should get a character after each output for rate limiting } } //dprint(term, "\n"); // For Debugging - add a line break here and pull the above two } low(16); // LEDs for debugging } /* TODO: Be sure to test that the data coming in is REAL TIME! */ }
void main() { badge_setup(); simpleterm_close(); ir_start(); ee_wipe(); // Connection to host routine (FORCE CONNECTION TO HOST) port = fdserial_open(31, 30, 0, 115200); char_size(SMALL); cursor(2, 4); display("Connecting..."); while(1) { dprint(port, "Propeller\n"); pause(1000); // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout if (fdserial_rxCount(port) == 0) { continue; } else if (fdserial_rxCount(port) < 5) { fdserial_rxFlush(port); continue; } else dscan(port, "%s", handshake); // Attempt handshake and listen to response if (strcmp(handshake, "H0st") == 0) { break; } } clear(); while(1) { rgb(L, OFF); rgb(R, OFF); char_size(BIG); cursor(0, 0); display("HOTSPOT!"); char_size(SMALL); cursor(4, 5); display("Start an"); cursor(1, 6); display("interaction to"); cursor(0, 7); display("upload your data"); memset(&their, 0, sizeof(info)); int t = CNT; int dt = CLKFREQ * 2; if (check_inbox() == 1) { clear(); message_get(&their); ir_send(&my); char_size(SMALL); cursor(2, 2); display("Receiving..."); while(1) { if (CNT - t > dt) { clear(); char_size(SMALL); cursor(5, 2); display("ERROR!"); cursor(0, 5); display("Please try again"); dprint(port, "txBegin\n"); dprint(port, "Timeout\n"); ee_wipe(); clear_inbox(); pause(2000); clear(); break; } if (check_inbox() == 1) { t = CNT; message_get(&their); if(!strcmp(their.name, "txDone")) { char_size(SMALL); cursor(0, 5); display("Upload complete"); dprint(port, "txBegin\n"); ee_uploadContacts(port); ee_wipe(); clear_inbox(); pause(1000); clear(); break; } ee_save(&their); dprint(port, "Name: %s\n", their.name); dprint(port, "Email: %s\n", their.email); } } } } }
int main(void) { //drive_pins(12, 13); sirc_setTimeout(60); simpleterm_close(); pause(100); term = fdserial_open(31, 30, 0, 115200); pause(100); drive_open(); while(1) { dprint(term, "%c", CLS); button = sirc_button(10); if(button == PWR) { set_mode(); } switch(mode) { case 0: switch(button) { case CH_UP: //drive_speed(100, 100); drive_speed(smul, smul); break; case CH_DN: //drive_speed(-100, -100); drive_speed(-smul, -smul); break; case VOL_DN: //drive_speed(-100, 100); drive_speed(-smul, smul); break; case VOL_UP: //drive_speed(100, -100); drive_speed(smul, -smul); break; default: //drive_speed(0, 0); drive_speed(0, 0); break; } break; case 1: for(int i = 0; i < 4; i++) { dist[i] = ping_cm(14+i); //dprint(term, "%d=%03d\n", i, dist[i]); pause(10); } speedL = 0; speedR = 0; if(dist[BACK] < 30) { speedL += 100; speedR += 100; } if(dist[FRONT] < 30) { speedL -= 100; speedR -= 100; } if(dist[LEFT] < 30) { if(speedL == 0) speedL -= 100; else if(speedL < 0) //speedR += 200; speedR += 50; else if(speedL > 0) //speedR -= 200; speedR -= 50; } if(dist[RIGHT] < 30) { if(speedR == 0) speedR -= 100; else if(speedR < 0) //speedL += 200; speedL += 50; else if(speedR > 0) //speedL -= 200; speedL -= 50; } drive_speed(speedL, speedR); pause(100); break; case 2: smul = 50; mode = 0; break; case 3: smul = 100; mode = 0; break; /* case 4: val = get_val(); dprint(term, "val = %d\n", val); pause(3000); break; */ } } }
int main() { //access the simpleIDE terminal simpleterm_close(); //set full-duplex serialization for the terminal term = fdserial_open(31, 30, 0, 9600); char c; //servo_angle(16, gripDegree); //Orient gripper to half open on start //pause(3000); while (1) { c = fdserial_rxChar(term); //Get the character entered from the terminal if (c != -1) { //Use the below to see if any key input is being read by the terminal // dprint(term, "You typed: %c\n", c); //Link key presses to directional commands, and print the command to strings if (c == 'f') //press "f" fof forward { Drive(ticks, ticks, maxSpeed); dprint(term, "ok\n"); } else if (c == 'b') //press "b" for backward { Drive(-ticks, -ticks, maxSpeed); dprint(term, "ok\n"); } else if (c == 'r') //press "r" for right turn { Drive(turnTick, -turnTick, maxTurnSpeed); dprint(term, "ok\n"); } else if (c == 'l') //press "l" for left turn { Drive(-turnTick, turnTick, maxTurnSpeed); dprint(term, "ok\n"); } //Increasing and Decreasing Drive Speed else if (c == 'u') { ticks = ticks + 2; if (ticks > maxSpeed) //clamp speed so it can't go over the maximum speed { ticks = maxSpeed; } dprint(term, "move_speed %d\n", ticks); } else if (c == 'd') { ticks = ticks - 2; if (ticks < minSpeed) //clamp speed so it can't go negative or 0 { ticks = minSpeed; } dprint(term, "move_speed %d\n", ticks); } //Increase Turn Speed; else if (c == 't') { turnTick = turnTick + 1; if (turnTick > maxTurnSpeed) { turnTick = maxTurnSpeed; } dprint(term, "turn_speed %d\n", turnTick); } //decrease turn speed else if (c == 'n') { turnTick = turnTick - 1; if (turnTick < minTurnSpeed) { turnTick = minTurnSpeed; } dprint(term, "turn_speed %d\n", turnTick); } else if (c == 'p') //ping distance { pingDistance = ping(8); dprint(term, "echo %d\n", pingDistance); dprint(term, "ok\n"); } else if (c == 'k') // poke { } else if (c == 'o') //open gripper { gripState = 0; gripDegree = -1800; } else if (c == 'g') //close gripper { gripState = 1; gripDegree = 1800; } } // End of Read Character Function if (gripState != -1) { Grip(gripDegree, 2000); } } // End of While Loop } //End of Main Loop
void main() { badge_setup(); simpleterm_close(); contacts_clearAll(); preserve_header(); CLKLIMIT = CLKFREQ * 2; // Connection to host routine (FORCE CONNECTION TO HOST) port = fdserial_open(31, 30, 0, 115200); text_size(SMALL); cursor(2, 4); oledprint("Connecting..."); spkr = talk_run(9, 10); // Start talk process while(1) { dprint(port, "Propeller\n"); pause(1000); // We need this pause, since the host needs time to respond. 5 x 1 second = 10 second timeout if (fdserial_rxCount(port) == 0) { continue; } else if (fdserial_rxCount(port) < 5) { fdserial_rxFlush(port); continue; } else dscan(port, "%s", handshake); // Attempt handshake and listen to response if (strcmp(handshake, "H0st") == 0) { break; } } clear(); talk_say(spkr, "heloa"); while(1) { rgb(L, OFF); rgb(R, OFF); text_size(LARGE); cursor(0, 0); oledprint("HOTSPOT!"); text_size(SMALL); cursor(4, 5); oledprint("Start an"); cursor(1, 6); oledprint("interaction to"); cursor(0, 7); oledprint("upload your data"); char their_id[7]; memset(&their_id, 0, 7); int t = CNT; char i_type[5]; irscan("%s%s", their_id, i_type); if (strlen(their_id) > 0) { clear(); eeprint("%s,%u,%s\n", their_id, 0, "INFO"); irprint("%s\n%s\n", "htspt1", "DUMP"); text_size(SMALL); cursor(2, 2); oledprint("Receiving..."); while(1) { char b[128]; memset(&b, 0, 128); irscan("%s", b); if (CNT - t > CLKLIMIT) { clear(); text_size(LARGE); cursor(0, 0); oledprint(" ERROR"); text_size(SMALL); cursor(0, 6); oledprint("Please try again"); dprint(port, "txBegin\n"); dprint(port, "Timeout\n"); contacts_clearAll(); preserve_header(); talk_say(spkr, "oops;/trae,-ugen"); pause(2000); clear(); break; } if (strlen(b) > 0) { t = CNT; if(!strcmp(b, "irDone")) { clear(); text_size(LARGE); cursor(0, 0); oledprint("SUCCESS"); text_size(SMALL); cursor(0, 6); oledprint("Upload complete"); talk_say(spkr, "oakay;</aem,dun"); dprint(port, "txBegin\n"); upload_contacts(port); contacts_clearAll(); preserve_header(); pause(1000); clear(); break; } save_contact(b); } } } } }