예제 #1
0
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 uartToRadioService()
{
    // Data
    while(!spi0MasterBusy() && radioComTxAvailable())
    {
        radioComTxSendByte(spi0MasterReceiveByte());
    }

    while(radioComRxAvailable() && !spi0MasterBusy())
    {
        spi0MasterSendByte(radioComRxReceiveByte());
    }

    // Control Signals.
    ioTxSignals(radioComRxControlSignals());
    radioComTxControlSignals(ioRxSignals());
}
예제 #3
0
void uartToRadioService()
{
    // Data
    while(uart1RxAvailable() && radioComTxAvailable())
    {
        radioComTxSendByte(uart1RxReceiveByte());
    }

    while(radioComRxAvailable() && uart1TxAvailable())
    {
        uart1TxSendByte(radioComRxReceiveByte());
    }

    // Control Signals.
    ioTxSignals(radioComRxControlSignals());
    radioComTxControlSignals(ioRxSignals());
}
예제 #4
0
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 usbToUartService()
{
    uint8 signals;

    // Data
    while(usbComRxAvailable() && !spi0MasterBusy())
    {
        spi0MasterSendByte(usbComRxReceiveByte());
    }

    while(!spi0MasterBusy() && usbComTxAvailable())
    {
        usbComTxSendByte(spi0MasterReceiveByte());
    }

    ioTxSignals(usbComRxControlSignals());

    // Need to switch bits 0 and 1 so that DTR pairs up with DSR.
    signals = ioRxSignals();
    usbComTxControlSignals( ((signals & 1) ? 2 : 0) | ((signals & 2) ? 1 : 0));

    // TODO: report framing, parity, and overrun errors to the USB host here
}
void main()
{
	int8 SPI_SEND = 0;
	int8 prev_send = 0;
    systemInit();

    setDigitalOutput(param_arduino_DTR_pin, LOW);
    ioTxSignals(0);

    usbInit();

    spi0MasterInit();
    spi0MasterSetFrequency(38400);
//    uart1Init();
//    uart1SetBaudRate(param_baud_rate);

    if (param_serial_mode != SERIAL_MODE_USB_SPI)
    {
        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();

        if(!spi0MasterBusy() && SPI_SEND != prev_send){
        	spi0MasterSendByte(SPI_SEND);
        	prev_send = SPI_SEND;
        }

        if (param_serial_mode != SERIAL_MODE_USB_SPI)
        {
            radioComTxService();
        }

        usbComService();

//        switch(currentSerialMode)
//        {
//        case SERIAL_MODE_USB_RADIO:  usbToRadioService();  break;
//        case SERIAL_MODE_SPI_RADIO: uartToRadioService(); break;
//        case SERIAL_MODE_USB_SPI:   usbToUartService();   break;
//        }


		switch(usbComRxReceiveByte()){

		case 0:		// STOP
			SPI_SEND += 15;
			SPI_SEND = (SPI_SEND%255);
			break;
		case 1:		// Initialize
			SPI_SEND -= 15;
			SPI_SEND = (SPI_SEND%255);
			break;
		}
    }
}