int main () { char uartReceiverBuffer[RECEIVER_SIZE]; Servo_Init(10000); Servo_Callib(); UART_InitWithInt(9600); while(1) { if(eReciever_GetStatus()==READY) { Reciever_GetStringCopy(uartReceiverBuffer); if (eCompareString("callib", uartReceiverBuffer)==EQUAL) { Servo_Callib(); } else if (eCompareString("left", uartReceiverBuffer)==EQUAL) { Servo_GoTo(50); } else if (eCompareString("right", uartReceiverBuffer)==EQUAL) { Servo_GoTo(150); } } } }
/* ------------------------------------------------------------------------- * 函数名称: * 函数功能: * 输入形参: * 返回值: --------------------------------------------------------------------------- */ void Board_Init(void) { u8 i; //系统时钟配置 SystemInit(); //延时函数初始化 delay_init(72); //定时器1初始化 TIM1_config(); //舵机初始化 Motor_Init(); Servo_Init(); //串口配置 USART_Config(); //串口中断配置 NVIC_Config(); //LED初始化 LED_Init(); //按键初始化 KEY_Init(); //等待电调中间值确定 for(i=0;i<3;i++) { delay_ms(1000); } }
int main () { char uartReceiverBuffer[RECEIVER_SIZE]; Servo_Init(10000); Servo_Callib(); UART_InitWithInt(9600); while(1) { if(eReciever_GetStatus()==READY) { Reciever_GetStringCopy(uartReceiverBuffer); DecodeMsg(uartReceiverBuffer); if(ucTokenNr!=0&&asToken[0].eType==KEYWORD) // pacze czy slowo klucz { switch(asToken[0].uValue.eKeyword) { case CALLIB: Servo_Callib(); break; case GOTO: if(asToken[1].eType==NUMBER&&asToken[1].uValue.uiNumber<200)Servo_GoTo(asToken[1].uValue.uiNumber); // tu czy po goto byla liczba oraz czy wartosc mniejsza od 200 break; default: break; } } } } }
/** Lock or unlock the I/O lines used by the servos. Sets whether the specified Servo I/O is active. @param index An integer specifying which servo (0 - 3). @param state An integer specifying the active state - 1 (active) or 0 (inactive). @return Zero on success. \b Example \code // enable servo 2 Servo_SetActive(2, 1); \endcode */ int Servo_SetActive( int index, int state ) { if ( index < 0 || index >= SERVO_COUNT ) return CONTROLLER_ERROR_ILLEGAL_INDEX; if ( state ) { if( Servo == NULL ) { int retVal = Servo_Init( ); if( retVal != CONTROLLER_OK ) return retVal; } return Servo_Start( index ); } else { if( Servo == NULL ) return -1; int retVal = Servo_Stop( index ); if( retVal != CONTROLLER_OK ) return retVal; if( --Servo->users <= 0 ) retVal = Servo_Deinit( ); return retVal; } }
void Init() { ReadConfigFromEEPROM(); //LEDs DDRC |= (1<<PC3); //Red LED DDRB |= (1<<PB5); //Green LED //check for service mode CheckServiceMode(); #ifndef NO_BINDING Bind_RX_Init(); #endif Red_LED_ON; Timer0_Init(); USART_Init(); RF22B_Init(); Servo_Init(); to_rx_mode(); sei(); }
void Init() { ReadConfigFromEEPROM(); //LEDs DDRC |= (1<<PC3); //Red LED DDRB |= (1<<PB5); //Green LED //check for service mode CheckServiceMode(); #ifndef NO_BINDING //check BIND button state DDRD &= ~(1<<PD3); PORTD |= (1<<PD3); _delay_ms(1); if (bit_is_clear(PIND,PD3)) { _delay_ms(1000); if (bit_is_clear(PIND,PD3)) bind = 1; } else bind = 0; if (bind) { RF_Header[0] = 'B'; RF_Header[1] = 'I'; RF_Header[2] = 'N'; RF_Header[3] = 'D'; } else { RF_Header[0] = SETTINGS.RF_HEADER[0]; RF_Header[1] = SETTINGS.RF_HEADER[1]; RF_Header[2] = SETTINGS.RF_HEADER[2]; RF_Header[3] = SETTINGS.RF_HEADER[3]; } #endif Red_LED_ON; Timer0_Init(); USART_Init(); RF22B_Init(); Servo_Init(); to_rx_mode(); sei(); }
/* ------------------------------------------------------------------------- * 函数名称:void Board_Init(void) * 函数功能:调用底层硬件初始化函数,供main()函数调用 * 输入形参:无 * 返回值:无 --------------------------------------------------------------------------- */ void Board_Init(void) { u8 i; SystemInit(); //系统时钟配置 delay_init(72); //延时函数初始化 TIM1_config(); TIM4_Mode_Config(); Motor_Init(); //舵机初始化 Servo_Init(); USART_Config(); //串口配置 LED_Init(); //按键初始化 KEY_Init(); for(i=0;i<3;i++) //等待电调中间值确定 { delay_ms(1000); } OV7670_Init(); //最后进行摄像头初始化 }
/* ------------------------------------------------------------------------- * 函数名称: * 函数功能: * 输入形参: * 返回值: --------------------------------------------------------------------------- */ void Board_Init(void) { //系统时钟配置 SystemInit(); //延时函数初始化 delay_init(72); //定时器1初始化 TIM1_config(); //舵机初始化 Servo_Init(); //串口配置 USART_Config(); //串口中断配置 NVIC_Config(); //LED初始化 LED_Init(); //按键初始化 KEY_Init(); }
boolean Plugin_027(byte function, struct NodoEventStruct *event, char *string) { boolean success=false; #ifdef PLUGIN_027_CORE switch(function) { case PLUGIN_COMMAND: { if (!Servo_attached(event->Par1-1)) { Servo_Init(event->Par1-1); Servo_attach(event->Par1-1,PIN_WIRED_OUT_1 + event->Par1-1); } Servo_write(event->Par1-1,event->Par2); success=true; break; } #endif // CORE #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI! case PLUGIN_MMI_IN: { char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE); if(GetArgv(string,TempStr,1)) { if(strcasecmp(TempStr,PLUGIN_NAME_027)==0) { if(GetArgv(string,TempStr,2)) { if(GetArgv(string,TempStr,3)) { if(event->Par1>0 && event->Par1<5 && event->Par2>=0 && event->Par2<=180) { event->Type = NODO_TYPE_PLUGIN_COMMAND; event->Command = 27; // Plugin nummer success=true; } } } } } free(TempStr); break; } case PLUGIN_MMI_OUT: { strcpy(string,PLUGIN_NAME_027); strcat(string," "); strcat(string,int2str(event->Par1)); strcat(string,","); strcat(string,int2str(event->Par2)); break; } #endif //MMI } return success; }
/****************************************************************************** * * Test program * *****************************************************************************/ int main(void) { int ret; int servo; // lame TI compiler cant handle loop var declaration FPUStackingDisable(); /* Initialize the clock to run at 40 MHz */ SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); gSysClock = SysCtlClockGet(); /* Initialize the UART. */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); #ifdef STELLARISWARE UARTStdioInit(0); #else UARTStdioConfig(0, 115200, gSysClock); #endif UARTprintf("\n\nServoBoard-Test\n---------------\n"); /* Initialize the GPIO port for the RGB LED */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, RGB_PINS); GPIOPinWrite(GPIO_PORTF_BASE, RGB_PINS, 0); /* Initialize the battery monitor * Use zeroes for parameter so default calibration will be used */ Servo_BatteryInit(0, 0); /* Initialize servos for 20 msec */ ret = Servo_Init(gSysClock, 20000); if(ret) { UARTprintf("error calling ServoInit\n"); return 0; } /* Enter loop to initialize all the servos in the system */ for(servo = 0; servo < NUM_SERVOS; servo++) { /* Associate each servo ID with a hardware timer (and A or B half) */ hServo[servo] = Servo_Config(servoInfo[servo].timer, servoInfo[servo].half); if(hServo[servo] == 0) { UARTprintf("error config servo %d\n", servo); return 0; } /* Delay a bit before initting the next servo. This is done to * spread out the servo pulses so they do not all happen at the * same time and load down the power supply. * The delay value was determined experimentally. If the * system clock frequency is changed then the delay value needs to * be changed */ SysCtlDelay(22000); } /* Set each servo position to 0 to start, with 100 ms delay */ for(servo = 0; servo < NUM_SERVOS; servo++) { /* Set the servo motion rate */ Servo_SetMotionParameters(hServo[servo], 200); Servo_SetPosition(hServo[servo], 0); SysCtlDelay((gSysClock / 10) / 3); } // MoveAll(0xFFF, 0); /* In this loop we just move all the servos between +45 and * -45 deg (uncalibrated). There is a 100 ms delay between each * servo, so that if observed with a scope each servo does not have * the exact same timing. */ while(1) { /* Move all servos to -45 deg, with 100 ms between each servo */ for(servo = 0; servo < NUM_SERVOS; servo++) { UpdateRGB(); MoveOne(servo, -450); DelayMs(100); } /* Now move all servos to +45 deg, with 100 ms delay */ for(servo = 0; servo < NUM_SERVOS; servo++) { UpdateRGB(); MoveOne(servo, 450); DelayMs(100); } /* Read the battery voltage and print to the terminal */ uint32_t bat = Servo_ReadBatteryMv(); UARTprintf("%u.%02u V\n", bat / 1000, (bat % 1000) / 10); } #ifndef ccs // prevent warning from TI ccs compiler return(0); #endif }