void init_car(){ init_motor(); init_motor_CWCCW(); init_encoder(); init_External_Interrupt(); init_linear_actuator(); init_Neural(&n_r, 0.01, 0.01, 0); init_Neural(&n_l, 0.01, 0.01, 0); init_Neural(&n_r_back, 0.01, 0.01, 0); init_Neural(&n_l_back, 0.01, 0.01, 0); array_1d_Init_2(RECORD_SIZE, 0, path_record_r_p); array_1d_Init_2(RECORD_SIZE, 0, path_record_l_p); array_1d_Init_2(RECORD_SIZE, 0, path_record_r_n); array_1d_Init_2(RECORD_SIZE, 0, path_record_l_n); array_1d_Init_2(RECORD_SIZE, 0, kp_record_l); array_1d_Init_2(RECORD_SIZE, 0, kp_record_r); array_1d_Init_2(RECORD_SIZE, 0, ki_record_l); array_1d_Init_2(RECORD_SIZE, 0, ki_record_r); array_1d_Init_2(RECORD_SIZE, 0, kd_record_l); array_1d_Init_2(RECORD_SIZE, 0, kd_record_r); array_1d_Init_2(RECORD_SIZE, 0, desire_record); array_1d_Init_2(RECORD_SIZE, 0, c_out_r); array_1d_Init_2(RECORD_SIZE, 0, c_out_l); path_counter = 0; carTimers = xTimerCreate("Car_State_Polling", ( CAR_POLLING_PERIOD), pdTRUE, ( void * ) 1, Car_State_Polling ); xTimerStart( carTimers, 0 ); }
int main( int argc, char** argv ) { char c; init_motor(frameSize.width,frameSize.height); init_fish(); //printf("hacked frames %d w %d h %d\n",frames,tmpw,tmph); begin = clock(); #if 1 while(1) { get_fish_pos(); cvShowImage( "set_HSV", gr_frame ); fish_motor(fishPos); c = (char)cvWaitKey(50); if( c == 27 ) break; if( c == 'c'){ while(1){ c = getchar(); if(ctlMotor(c)<0) break; } } } #endif end = clock(); time_spent = (double)(end - begin)/CLOCKS_PER_SEC; time_spent += 1; printf("time of prog %f, numframe %d,numframe for sec %d\n", time_spent,mod,mod/(int)time_spent); exit_fish(); exit_motors(); return(0); }
void init() { ResetReason = MCUSR; cli(); WDT_off(); // Turn off until initialization is done and we can pet the dog. init_leds (); init_buttons(); init_limit_switches(); init_motor(); float mBaseFrequencyHerz = 500.0; // 4khz pwm_init( mBaseFrequencyHerz, TRUE ); init_serial(); init_configuration(); // read_configuration_and_set(); // init_adc(); // start_sampling(); encoder_init(); // pot_init (); WDT_Prescaler_Change(); //delay(100000); // ~ 2 sec //read_cal(); // Read everything including motor stops. sei(); //OS_InitTask(); }
motor::motor(void) : DefaultGUIModel("motor with Custom GUI", ::vars, ::num_vars) { setWhatsThis("<p><b>motor:</b><br>QWhatsThis description.</p>"); DefaultGUIModel::createGUI(vars, num_vars); // this is required to create the GUI customizeGUI(); init_motor(); update( INIT ); // this is optional, you may place initialization code directly into the constructor refresh(); // this is required to update the GUI with parameter and state values }
void init(void){ init_pin(); init_clock(); init_uart(); init_ui(); init_timer(); init_oc(); init_motor(); InitUSB(); // initialize the USB registers and serial interface engine init_interrupts(); }
int main(void) { /* hardware initialisation: */ init_motor(); init_buzzr(); init_leds(); init_switch(); uint8_t mode = 0; for(;;) /* ever */ { //do something switch(mode){ case 1: mode_blinktest(); break; case 2: mode_motortest(); break; case 3: mode_beeptest(); break; default: //mode=0; blinkrattlebeep(); } //check switches and change mode switch( PIND & 0b00000011){ case 0b00000010: //left switch pressed mode--; if (mode > 3) mode =3; flashleds(LED_L); break; case 0b00000001: //right switch pressed mode++; if (mode > 3) mode = 0; flashleds(LED_R); break; case 0b00000000: //both switches pressed flashleds(LED_R|LED_L); break; } } /* never return 0; */ return 0; }
int main() { // capture any reset reason G_reset_source = MCUSR; // clear the status register by writing ones // (odd, I know, but that is how it is done) MCUSR = 0x1F; // Display on the LCD that serial connection is needed print("Waiting for"); lcd_goto_xy(0, 1); print(" serial conn..."); // This init will block if no serial connection present // so user sees message on LCD to make a connection init_interface(); // Display the user interface over the serial usb // connection serial_check(); print_reset_reason(); print_usb("Welcome to lab 3!\r\n", 19); print_usage(); print_prompt(); // clear "Waiting for connection" message from the LCD clear(); // turn on interrupts sei(); init_motor(); init_encoder(); // set controller for 1000 Hz init_controller_w_rate(50); while (1) { serial_check(); check_for_new_bytes_received(); } return 0; }
void init_board() { uint8_t i; d7segment_init(); init_ir(); init_motor(); uart_init(); adc_init(1); // AVCC as reference g_cmd_decode = 0; g_motor= 0; for ( i = 0 ; i< MOTOR_MAX ;i++) { g_speed[i] = 1; g_angle[i] = 1; } sei(); }
int main(void) { init_menu(); clear(); init_motor(); init_timers(); encoders_init(IO_D2, IO_D3, IO_C4, IO_C5); sei(); while (1) { if(g_pd_release) { pd_task(); g_pd_release = 0; } if(g_velocity_release) { velocity_task(); g_velocity_release = 0; } if(g_encoder_release) { encoder_task(); g_encoder_release = 0; } if(g_log_release) { log_task(); g_log_release = 0; } if(g_interpolate_release) { interoplate_task(); g_interpolate_release = 0; } serial_check(); check_for_new_bytes_received(); } }
int16_t main(void) { init_clock(); init_ui(); init_pin(); init_timer(); init_oc(); init_spi(); init_enc(); init_md(); init_motor(); // (&motor1)->vel_set = 360.0; InitUSB(); while (USB_USWSTAT!=CONFIG_STATE) { ServiceUSB(); } while (1) { ServiceUSB(); } }
int main (void) { //Initialize UART with 8-bit character sizes,no parity,1 stop bit uart_init(); sei(); init_motor(); //This should be called first before using any motor command macro init_sensor(); TCNT0 = 0x63; // for speed control TCCR0 = 0x05; X=1; Y=1; curHead = East; while(1) { trans('1'); _delay_ms(1); trans('2'); _delay_ms(1); trans('3'); _delay_ms(1); fwd(); //move(0x22); //moveStraight(); //turnRight(); //stop(); //while(1); //moveStraight(); // Now ISR will initiate the actions } }
void main() { unsigned short val = 0; unsigned int show_data = 0; //unsigned short last_data = 0; uart2_init(); init_led(); init_motor(); init_steering(); init_speed(); show_byte(0); //led_vcc_on(); while(1) { // show_byte(0x12,1); if((uart_data >= '0') && (uart_data <= 'z')) { //last_data = val; val = uart_data; } //show_data = (cmd_func << 8) | (val & 0xff); show_data = ((left_dis << 8)&0xff00) | (right_dis & 0xff); //show_data = (left_diff << 8) | (right_diff & 0xff); show_byte(show_data); if(sg_flag == 1) { sg_flag = 0; delay1ms_show(1000 * 3,show_data); if(sg_flag == 0) { //maybe call up() twice in 3s stop_sg(); } } //uart2_send('a'); //uart2_send('b'); //uart2_send('c'); } }
void init_board() { uint8_t i; d7segment_init(); init_ir(); init_motor(); uart_init(); adc_init(3); // 2.56 BG as reference g_cmd_decode = 0; g_motor= 0; g_program_index =0; g_ircode =0; for ( i = 0 ; i< MOTOR_MAX ;i++) { g_speed[i] = 1; g_angle[i] = 1; } sei(); }
void initialize() { /* ---------communication-------- */ init_USART3(9600); USART_puts(USART3,"initial...\n\r"); USART_puts(USART3,"USART is ready\n\r"); /* ------------motors------------ */ init_motor(); init_linear_actuator(); USART_puts(USART3,"motor is ready \n\r"); /* ------------sensor------------ */ init_encoder(); init_CurTransducer(); init_Indicator(); /* -----------SD(data)----------- */ USART_puts(USART3,"test sdio/fat \n\r"); start_record(); USART_puts(USART3,"test end \n\r"); }
void init() { prc2 = 1; /*PACRの書込み許可*/ pacr = 3; /*80ピンに設定*/ /*クロック設定*/ prc0=1; cm21=0; cm06=0; prc0=0; /* I/Oポート設定 */ pd1 = 0x0f; /* P10 to P13 output */ pd3 = 0xf0; /* P34 to P37 output */ /* 入力ピンをプルアップ */ pu05 = 1; /* P24 to P27 pull-up */ pu06 = 1; /* P30 to P33 pull-up */ pu14 = 1; /* P60 to P63 pull-up */ init_motor(); }
//Initialize and enables all the peripherals void init_peripherals(void) { //Motor control variables & peripherals: init_motor(); //Init Control: init_ctrl_data_structure(); //Timebases: init_tb_timers(); //UART 2 - RS-485 init_rs485(); //Analog, expansion port: init_analog(); //Clutch: init_clutch(); //Enable Global Interrupts CyGlobalIntEnable; //I2C1 (internal, potentiometers, Safety-CoP & IMU) init_i2c1(); //Peripherals that depend on I2C: #ifdef USE_I2C_INT //MPU-6500 IMU: #ifdef USE_IMU init_imu(); CyDelay(25); init_imu(); CyDelay(25); init_imu(); CyDelay(25); #endif //USE_IMU //Strain amplifier: #ifdef USE_STRAIN init_strain(); #endif //USE_STRAIN #endif //USE_I2C_INT //I2C2 (external) #ifdef USE_I2C_EXT //Enable pull-ups: I2C_OPT_PU_Write(1); //I2C2 peripheral: init_i2c2(); //Set RGB LED - Starts Green i2c_write_minm_rgb(SET_RGB, 0, 255, 0); #endif //USE_I2C_EXT //Magnetic encoder: init_as5047(); // First DieTemp reading is always inaccurate -- throw out the first one #ifdef USE_DIETEMP DieTemp_1_GetTemp(&temp); #endif //USB CDC #ifdef USE_USB init_usb(); #endif //USE_USB }
int main(void) { int8_t byte_str[4]; // Wird benutzt um hier ein Byte als String abzulegen // LCD Display intialisieren lcd_init(); // Startmeldung ausgeben show_start_message(); // Stepper Initialisieren init_stepper(); // Motor Initialisieren init_motor(); // Steursignale BYTE_READY, SYNC und SOE Initialisieren init_controll_signals(); // Schreibschutz setzen clear_wps(); // Timer0 --> GCR senden init_timer0(); // Tasten Initialisieren init_keys(); // Timer2 --> wird alle 1ms aufgerufen // z.B. zu Tasten entprellen init_timer2(); // Meldung ausgeben, das auf SD Karte gewartet wird lcd_setcursor(0,2); lcd_string("Wait for SD-Karte..."); // SD Karte initialisieren // Partition und Filesystem öffnen // Warten bis alles O.K. ist while(init_sd_card()){} lcd_clear(); view_dir_entry(0,&file_entry); #ifdef DEBUG_MODE lcd_setcursor(0,4); lcd_string("T:"); lcd_setcursor(5,4); lcd_string("M:"); lcd_setcursor(9,4); lcd_string("K:"); lcd_setcursor(2,4); sprintf(byte_str,"%d",akt_half_track >> 1); lcd_string(byte_str); #endif // Interrupts erlauben sei(); while(1) { // Auf Steppermotor aktivität prüfen // und auswerten if(stepper_signal_r_pos != stepper_signal_w_pos) { uint8_t stepper = stepper_signal_puffer[stepper_signal_r_pos++]>>2 | stepper_signal_puffer[stepper_signal_r_pos-1]; switch(stepper) { case 0x30: case 0x40: case 0x90: case 0xE0: // DEC stepper_dec(); stepper_signal_time = 0; stepper_signal = 1; break; case 0x10: case 0x60: case 0xB0: case 0xC0: // INC stepper_inc(); stepper_signal_time = 0; stepper_signal = 1; break; } #ifdef DEBUG_MODE lcd_setcursor(2,4); lcd_string(" "); lcd_setcursor(2,4); sprintf(byte_str,"%d",akt_half_track >> 1); lcd_string(byte_str); #endif } else if(stepper_signal && (stepper_signal_time >= STEPPER_DELAY_TIME))
void taskBackground(void* pvParameter) { static unsigned int val1; static unsigned int val2; time_t time_sec; // vTaskSetApplicationTaskTag( NULL, ( void * ) 'b' ); alarm_st = 0; #ifndef SIM_DEBUG //sysinit wdi_ena = 0; Spi_init(); if(get_time_rtc(&rtc_time)== FALSE) { SetError(RTC_ERR, HARWARE_ALRM_SCR); reset_rtc(); while(clear_os_rtc() == FALSE); init_time_rtc(&rtc_time); // rtc_time.tm_sec = 0; // rtc_time.tm_min = 0; // rtc_time.tm_hour = 0; // rtc_time.tm_mday = 1; // rtc_time.tm_wday = 0; // rtc_time.tm_mon = 0; // rtc_time.tm_year = 100; // rtc_time.tm_yday = 0; // rtc_time.tm_isdst = 0; set_time_rtc(&rtc_time)/*set_date()*/; } else if(mktime(&rtc_time)==-1) { SetError(RTC_ERR, HARWARE_ALRM_SCR); // reset_rtc(); init_time_rtc(&rtc_time); set_time_rtc(&rtc_time)/*set_date()*/; } time_sec = mktime(&rtc_time); set_clock(time_sec); // if(get_days(&calib_date) > 365) // if(time_sec - calib_time >= 31536000L /*365*24*60*60*/) // { // Beep(800); // lcd_clear(); // beep(800,4); // RTclock.timer = 2000; //10sec timeout // draw_text( 15, LCD_TXTLINE1, (uchar*)"SEND THE PUMP", LCD_PIXEL_ON,0); // draw_text( 54, LCD_TXTLINE2, (uchar*)"TO", LCD_PIXEL_ON,0); // draw_text( 29, LCD_TXTLINE3, (uchar*)"CALIBRATE", LCD_PIXEL_ON,0); // while(RTclock.timer > 0); // } SST25ProtDisable(); SST25ReadArray(PARAM_E2PIMG_BASE, &E2pImage, sizeof(E2pImage_t)); if(crc16((unsigned char*)&E2pImage, sizeof(E2pImage_t)) != 0) { SetError(EEPROM_ERR, HARWARE_ALRM_SCR); set_defaults(); } SST25ReadArray(CLBR_E2PIMG_BASE, &Clbr_E2pImage, sizeof(Clbr_E2pImage_t)); if(crc16((unsigned char*)&Clbr_E2pImage, sizeof(Clbr_E2pImage_t)) != 0) { SetError(EEPROM_ERR, HARWARE_ALRM_SCR); set_fact_defaults(); } if(GetError() != 0) { err_code = GetError(); ClearError(); ((unsigned int*)&E2pImage)[sizeof(E2pImage_t)/2 - 1] = crc16(&E2pImage, sizeof(E2pImage_t) - 2); SST25SectorErase(PARAM_E2PIMG_BASE); if(!SST25WriteArray(PARAM_E2PIMG_BASE, &E2pImage, sizeof(E2pImage_t))) /*CriticalError("eeprom err")*/; } MCP23S08Init(); MCP4822Write(0, zero_press1 , 0); MCP4822Write(1, zero_press2 , 0); init_motor(); init_airdet(); #endif init_keypad(); init_clock(); CheckParams(); /* drop task priority */ vTaskPrioritySet( hBACKGRNDTask, tskIDLE_PRIORITY + 1 ); while (1) { vTaskDelay( 50 / portTICK_RATE_MS ); // Wait 50ms if(val1 > 0x0fff) val1 = 0; else val1++; if(val2 > 0x0fff) val1 = 0; else val2++; if(!wdi_ena) toggleExpGPO(WDI_EXTIOBIT); // ClrWdt(); // WD_PIN^= 1; /*toggle external watch dog */ } }