void main() { systemInit(); //Among other things, allocates byte arrays for sending commands. dynamixel_init(); // Oooh. what's this? setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); //usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); // Initial setting of serial mode updateSerialMode(); // Set up P1_5 to be the radio's TX debug signal. // P1DIR |= (1<<5); // IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) // P1DIR |= 0x20; //Enable pin P1_5 while(1) { uint32 ms; uint16 now; uint16 speed; updateSerialMode(); boardService(); updateLeds(); errorService(); // Code for oscillating a servo back and forth ms = getMs(); // Get current time in ms now = ms % (uint32)10000; // 10 sec for a full swing if(now >= (uint16)5000){ // Goes from 0ms...5000ms now = (uint16)10000 - now; // then 5000ms...0ms } speed = interpolate(now, 0, 5000, 100, 900); // speed is really the position. ax12SetGOAL_POSITION(32, speed); delayMs(30); } }
void main() { systemInit(); setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComRxEnforceOrdering = 1; radioComInit(); } // Set up P1_5 to be the radio's TX debug signal. P1DIR |= (1<<5); IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) while(1) { updateSerialMode(); boardService(); updateLeds(); errorService(); /* toggle_led();*/ if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComTxService(); } usbComService(); switch(currentSerialMode) { case SERIAL_MODE_USB_RADIO: usbToRadioService(); break; case SERIAL_MODE_UART_RADIO: uartToRadioService(); break; case SERIAL_MODE_USB_UART: usbToUartService(); break; } } }
void main() { // uint32 ms; // uint32 now; // uint8 cmdrAlive = 0; // Here we define what pins we will be using for PWM. // uint8 CODE pwmPins[] = {ptrGunMotor->pwmpin}; uint8 CODE pwmPins[] = {11}; MOTOR gunMotor = MAKE_MOTOR_3_PIN(pwmPins[0], 12, 13); //(PWM, B, A) MOTOR *ptrGunMotor = &gunMotor; // setDigitalOutput(param_arduino_DTR_pin, LOW); // ioTxSignals(0); // Initialize UARTs uart0Init(); uart0SetBaudRate(param_baud_rate_UART); uart1Init(); uart1SetBaudRate(param_baud_rate_XBEE); pwmStart((uint8 XDATA *)pwmPins, sizeof(pwmPins), 10000); guns_firing_duration = 125; // time in ms gunbutton = zFALSE; solenoid_on_duration = 80; // time in ms solenoidbutton = zFALSE; laserbutton = zFALSE; systemInit(); // Initialize other stuff index_cmdr = -1; /// MAIN LOOP /// while(1) { // updateSerialMode(); boardService(); updateLeds(); errorService(); // cmdr counts down from CMDR_ALIVE_CNT by -1 whenever no packets are received? cmdrAlive = (uint8) CLAMP(cmdrAlive + CmdrReadMsgs(), 0, CMDR_ALIVE_CNT); // ms = getMs(); // Get current time in ms // now = getMs(); // now = ms % (uint32)10000; // 10 sec for a full swing // if(now >= (uint16)5000){ // Goes from 0ms...5000ms // now = (uint16)10000 - now; // then 5000ms...0ms // } // speed = interpolate(now, 0, 5000, 100, 900); if (laserbutton == zTRUE && cmdrAlive > 0){ // uart0TxSendByte('L'); setDigitalOutput(param_laser_pin, HIGH); } else {setDigitalOutput(param_laser_pin, LOW);} //FIRE THE GUNS!!!!! //Resets timer while gunbutton is held down. if (gunbutton == zTRUE){ // uart0TxSendByte('Z'); guns_firing = zTRUE; setMotorSpeed(ptrGunMotor, -60); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Check whether to stop firing guns if (guns_firing && clockHasElapsed(guns_firing_start_time, guns_firing_duration)){ // uart0TxSendByte('X'); guns_firing = zFALSE; setMotorSpeed(ptrGunMotor, 0); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Activate solenoid for hopup feed unjammer if (solenoidbutton == zTRUE){ // uart0TxSendByte('Z'); solenoid_on = zTRUE; setDigitalOutput(10, HIGH); solenoid_on_start_time = getMs(); } //Check whether to disable solenoid if (solenoid_on && clockHasElapsed(solenoid_on_start_time, solenoid_on_duration)){ // uart0TxSendByte('X'); solenoid_on = zFALSE; setDigitalOutput(10, LOW); solenoid_on_start_time = getMs(); } delayMs(5); } }