Example #1
0
void run_chordtest(int argc, char **argv)
{
  node *n = node_start(LOG_ERROR,0);
  if (NULL == n)
    exit(1);

  if (0 == argc) {
    /* Standalone mode; run the test locally */
    endpointid managerid;
    managerid.ip = n->listenip;
    managerid.port = n->listenport;
    managerid.localid = MANAGER_ID;
    start_manager(n);
    testchord(n,&managerid,1);
  }
  else {
    /* Client mode; run the chord test on a set of remote nodes specified in the file */
    endpointid *managerids;
    int nmanagers;
    if (0 != read_managers(n,argv[0],&managerids,&nmanagers))
      exit(1);
    testchord(n,managerids,nmanagers);
    free(managerids);
  }

  node_run(n);
}
u32 nodewrap_run(union trapped_args *args, void *pr_ctxt)
{
    u32 ret;
    struct node_res_object *node_res;

    find_node_handle(&node_res, pr_ctxt, args->args_node_run.node);

    if (!node_res)
        return -EFAULT;

    ret = node_run(node_res->node);

    return ret;
}
Example #3
0
int main(void) {
    struct control_params_t control_params;
    struct motor_params_t motor_params;
    float temp;
    uint8_t node_id;

    hal_reset();
    hal_set_low_frequency_callback(systick_cb);

    /* Read parameters from flash */
    Configuration configuration;
    configuration.read_motor_params(motor_params);
    configuration.read_control_params(control_params);

    /* Set phase reverse if required */
    if (configuration.get_param_value_by_index(PARAM_CONTROL_DIRECTION) == 1.0f) {
        hal_set_pwm_reverse(true);
    }

    /* Estimate motor parameters */
    hal_set_pwm_state(HAL_PWM_STATE_RUNNING);

    g_controller_state.mode = CONTROLLER_IDENTIFYING;
    g_parameter_estimator.start_estimation(hal_control_t_s);

    hal_set_high_frequency_callback(identification_cb);
    while (g_controller_state.mode == CONTROLLER_IDENTIFYING);
    hal_set_high_frequency_callback(NULL);

    /* Copy measured Rs and Ls */
    if (!g_controller_state.fault) {
        motor_params.rs_r = g_measured_rs_r;
        motor_params.ls_h = g_measured_ls_h;

        /*
        This is not strictly necessary as the values are never written to
        flash, but it does enable the measurements to be read via the
        parameter interfaces.
        */
        configuration.set_param_value_by_index(PARAM_MOTOR_RS,
                                               motor_params.rs_r);
        configuration.set_param_value_by_index(PARAM_MOTOR_LS,
                                               motor_params.ls_h);

        /* R/L * t must be < 1.0; R must be < 1.0 */
        if (motor_params.rs_r / motor_params.ls_h * hal_control_t_s >= 1.0f ||
                motor_params.rs_r > 1.0f) {
            g_controller_state.fault = true;
        }
    }

    /* Initialize the system with the motor parameters */
    ((volatile StateEstimator*)&g_estimator)->set_control_params(
        control_params.bandwidth_hz, hal_control_t_s);
    ((volatile StateEstimator*)&g_estimator)->set_motor_params(
        motor_params.rs_r, motor_params.ls_h, motor_params.phi_v_s_per_rad,
        hal_control_t_s);
    ((volatile StateEstimator*)&g_estimator)->reset_state();

    ((volatile DQCurrentController*)&g_current_controller)->set_params(
        motor_params, control_params, hal_control_t_s);

    /* Set up the control parameters */
    *((volatile float*)&g_controller_constants.idle_speed_rad_per_s) =
        motor_params.idle_speed_rad_per_s;
    *((volatile float*)&g_controller_constants.spinup_rate_rad_per_s2) =
        motor_params.spinup_rate_rad_per_s2;
    *((volatile float*)&g_controller_constants.accel_current_a) =
        motor_params.accel_voltage_v / motor_params.rs_r;
    *((volatile float*)&g_controller_constants.max_current_a) =
        motor_params.max_current_a;
    *((volatile float*)&g_controller_constants.braking_current_a) =
        motor_params.max_current_a * control_params.braking_frac;
    *((volatile float*)&g_controller_constants.effective_inv_r) =
        control_params.gain / motor_params.rs_r;

    temp = 1.0f / (float(2.0 * M_PI) * control_params.bandwidth_hz);
    *((volatile float*)&g_controller_constants.control_lpf_coeff) =
        hal_control_t_s / (hal_control_t_s + temp);

    /* Clear audio state */
    g_audio_state.off_time = 0;
    g_audio_state.phase_rad = 0.0f;
    g_audio_state.angular_velocity_rad_per_u = 0.0f;
    g_audio_state.volume_v = 0.0f;

    /*
    After starting the ISR tasks we are no longer able to access g_estimator,
    g_current_controller and g_speed_controller, since they're updated from
    the ISRs and not declared volatile.
    */
    hal_set_high_frequency_callback(control_cb);

    node_id = hal_get_can_node_id();
    node_init(node_id, configuration);
    node_run(node_id, configuration, motor_params, control_params);
}