void spawner_new_c::setup_stream_(const options_class::redirect redirect, std_stream_type source_type, runner* this_runner) { auto source_pipe = this_runner->get_pipe(source_type); if (redirect.type == options_class::std) { if (source_type == std_stream_input) { get_std(std_stream_input, redirect.flags)->connect(source_pipe); } else { source_pipe->connect(get_std(source_type, redirect.flags)); } return; } PANIC_IF(redirect.type != options_class::pipe); auto index = redirect.pipe_index; auto stream = redirect.name; PANIC_IF(index < 0 || index >= runners.size()); auto target_runner = runners[index]; multipipe_ptr target_pipe; if (stream == "stdin") { PANIC_IF(source_type == std_stream_input); target_pipe = target_runner->get_pipe(std_stream_input, redirect.flags); source_pipe->connect(target_pipe); } else if (stream == "stdout") { PANIC_IF(source_type != std_stream_input); target_pipe = target_runner->get_pipe(std_stream_output, redirect.flags); target_pipe->connect(source_pipe); } else if (stream == "stderr") { PANIC_IF(source_type != std_stream_input); target_pipe = target_runner->get_pipe(std_stream_error, redirect.flags); target_pipe->connect(source_pipe); } else { PANIC("invalid stream name"); } if (control_mode_enabled) { if (source_type == std_stream_output) { setup_stream_in_control_mode_(this_runner, source_pipe); } else if (stream == "stdout") { setup_stream_in_control_mode_(target_runner, target_pipe); } } }
void EyeRover::calibrate(){ std::cout << "Starting calibration procedure, EyeRover must be static" << endl; std::cout << "Procedure should take about a second" << endl; m_calibrated = false; std::vector<std::vector<float> > _gyros_vals(NUMBER_OF_STEPS_FOR_CALIBRATION); std::vector<std::vector<float> > _accs_vals(NUMBER_OF_STEPS_FOR_CALIBRATION); read_gyroscope(); read_accelerometer(); read_magnetometer(); usleep(500000); //Sleep for half a second for (int i=0; i<NUMBER_OF_STEPS_FOR_CALIBRATION; ++i){ _gyros_vals[i] = read_gyroscope(); _accs_vals[i] = read_accelerometer(); } m_gyro_avg = get_mean(_gyros_vals); m_accelerometer_avg = get_mean(_accs_vals); if (get_std(_gyros_vals, 0, m_gyro_avg[0])> 0.01){ m_calibrated = false; std::cout << "Calibration failed." << endl; } else{ m_calibrated = true; std::cout << "Calibration succeeded." << endl; } }