/********************************************************** * Function: controller *********************************************************/ void *controller(void *arg) { char request[10]; char answer[10]; MIXER_STATE = 0; TIME_LAST_CHANGE_MIXER = time(NULL); // Endless loop memset(request,'\0',10); memset(answer,'\0',10); struct timespec timeInit, timeEnd, timeDiff, timePeriod; timePeriod.tv_sec = (time_t) TIME_SEC_CYCLE_SECONDS; timePeriod.tv_nsec = (long) TIME_SEC_CYCLE_NANOSECONDS; while(1) { // - Lectura de la pendiente actual if(read_slope(request, answer) == 2) { printf("Error in read slope"); } // - Lectura de la velocidad actual if(read_speed(request, answer) == -1.0) { //Error printf("Error in read speed"); } // - Activar el acelerador if(gas_turn(request, answer) != 0 ) { //Error printf("Error in break. Current value = "); } // - Activar el freno if(break_turn(request, answer) != 0 ) { //Error printf("Error in break. Current value = "); } // - Activar el Mezclador if(mixer_turn(request, answer) != 0 ) { //Error printf("Error in break. Current value = "); } sec_cycle = (sec_cycle + 1) % TOTAL_SEC_CYCLES; clock_gettime(CLOCK_REALTIME, &timeEnd); diffTime(timeEnd, timeInit, &timeDiff); diffTime(timePeriod, timeDiff, &timeDiff); nanosleep(&timeDiff, NULL); addTime(timeInit, timePeriod, &timeInit); } //return (0); }
/* * List Speed of CD-ROM drive. */ static void list_speeds(const char *name, int fd) { #ifdef CDROM_SELECT_SPEED int max_speed, curr_speed = 0, prev_speed; select_speed(fd, 0); max_speed = read_speed(name); while (curr_speed < max_speed) { prev_speed = curr_speed; select_speed(fd, prev_speed + 1); curr_speed = read_speed(name); if (curr_speed > prev_speed) printf("%d ", curr_speed); else curr_speed = prev_speed + 1; } printf("\n"); #else warnx(_("CD-ROM select speed command not supported by this kernel")); #endif }
/* * List Speed of CD-ROM drive. */ static void list_speeds(struct eject_control *ctl) { #ifdef CDROM_SELECT_SPEED int max_speed, curr_speed = 0; select_speed(ctl); max_speed = read_speed(ctl->device); while (curr_speed < max_speed) { ctl->x_arg = curr_speed + 1; select_speed(ctl); curr_speed = read_speed(ctl->device); if (ctl->x_arg < curr_speed) printf("%d ", curr_speed); else curr_speed = ctl->x_arg + 1; } printf("\n"); #else warnx(_("CD-ROM select speed command not supported by this kernel")); #endif }
void easy_uart :: print_settings(void) { bool ret = false; std::cout << "UART settings:\n"; ret = read_speed(speed); if (ret) std::cout << "Speed: " << speed << std::endl; ret = ! ioctl(fd, GET_UART_SETUP, &LCR); if (ret) { std::cout << "len_word: " << LCR.bit.len_word + 5 << std::endl; std::cout << "num_stop_bit: " << LCR.bit.num_stop_bit + 1 << std::endl; std::cout << "parity: "; if (LCR.bit.parity == 1) std::cout << "YES\n"; else std::cout << "NO\n"; std::cout << "evenparity: "; if (LCR.bit.evenpar == 1) std::cout << "PARITY\n"; else std::cout << "NO PARITY\n"; std::cout << "sticpar: "; if (LCR.bit.sticpar == 1) std::cout << "CONST PARITY\n"; else std::cout << "GENERATION\n"; std::cout << "break Control: "; if (LCR.bit.brcon == 1) std::cout << "YES_BREAK\n"; else std::cout << "NO_BREAK\n"; } ret = !ioctl(fd, GET_UART_MODE, &mode_fifo); if (ret) { std::cout << "mode: "; switch(mode_fifo) { case 0 : std::cout << "NORM\n"; break; case 64 : std::cout << "UART 16550\n"; break; case 192 : std::cout << "UART 16550А\n"; break; default : std::cout << "unknow\n"; } } return; }
void SPEED(Machine & machine){ machine.stack.push(read_speed()); }
// Main function void main(void) { reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin(); initGPIO(); initADC(); initConsole(); int i = 0; //init_password(); send_data(); initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data); int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0; int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0; float distance = 0; bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time; int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0; IntMasterEnable(); while(1){ //reading data read_data = split_data(UART_char_data_old, read_data); // decode data speed = read_speed(); //read data into variables adc = run_adc()/7; //calculations aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed); if (speed_set_data.enable == 1){ step_motor_control(encoder_1/40, aim_pos); } //sending fake data fake_speed = (int)adc;//= random_at_most(100/1.852); send_info(fake_speed);//knots //storing data store_speed(speed); buffed_speed = analysis_speed(); acc = read_acceleration(buffed_speed); max_acc = max_acc_func(acc, max_acc); time = read_time(); satillite = read_satillite(); fix = read_fix(); quality = read_quality(); debounce_button(); // debounce buttons screen = read_button_screen(screen, fix); distance = read_distance(); select_read(); //need a mosfet for turning power off // select adds a an on and off switch yo if (screen == 1){ if(screen_prev != 1 && screen == 1){ speed_set_data.speed = buffed_speed; } speed_set_data.speed = set_speed(speed_set_data.speed); // set the speed to cruise at } if (screen == 2){ //0 to 100 acceleration_test(speed); } // refresh chainging if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){ UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0); refresh_rate += 1; } if (i >= 50){ display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite, encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times); i = 0; } screen_prev = screen; i++; } }
int main(void) { int cnt; setup_ports(); read_config(); setup_timer(); setup_control(); PORTC = DISABLED; setup_uart(9600UL); flags = eeread(FLAGS_START); ph_u = 0; ph_v = 24; ph_w = 12; pwm_u = 0; pwm_v = 0; pwm_w = 0; sei(); cnt = 0; while (1) { register byte i; if ((flags & FLAG_POT) && cnt == 0) read_speed(); cnt++; cnt &= 0x3F; if (flags & FLAG_GO) { int8_t cnt_u, cnt_v, cnt_w; int u_u, u_v, u_w; /* Disable all phases */ PORTC &= ~((1 << EU) | (1 << EV) | (1 << EW)); /* Wait to turn mosfets off */ _delay_loop_2(delay_num * delay_step); /* Switch all bridges to HIGH */ PORTC |= ((1<<UU) | (1<<UV) | (1<<UW)); /* Enable all phases */ PORTC |= ((1<<EU) | (1<<EV) | (1<<EW)); //_delay_loop_2(50); cnt_u = cnt_v = cnt_w = -1; u_u = u_v = u_w = 1; for (i = 0; i < MAX_PWM; i++) { if (i == pwm_u || (i > pwm_u && u_u)) { CLRBIT(PORTC, EU); // DISABLE U u_u = 0; cnt_u = delay_num; } if (i == pwm_v || (i > pwm_v && u_v)) { CLRBIT(PORTC, EV); // DISABLE V u_v = 0; cnt_v = delay_num; } if (i == pwm_w || (i > pwm_w && u_w)) { CLRBIT(PORTC, EW); // DISABLE W u_w = 0; cnt_w = delay_num; } _delay_loop_2(delay_step); if (cnt_u == 0) { CLRBIT(PORTC, UU); // Set U to LOW PORTC |= (1<<EU); cnt_u = -1; } if (cnt_v == 0) { CLRBIT(PORTC, UV); // Set V to LOW PORTC |= (1<<EV); cnt_v = -1; } if (cnt_w == 0) { CLRBIT(PORTC, UW); // Set W to LOW PORTC |= (1<<EW); cnt_w = -1; } if (cnt_u > 0) cnt_u--; if (cnt_v > 0) cnt_v--; if (cnt_w > 0) cnt_w--; } } else { PORTC = DISABLED; _delay_loop_1(250); } } return 0; }