Exemplo n.º 1
0
int main(void)
{
  main_init();

#if LIMIT_EVENT_POLLING
  /* Limit main loop frequency to 1kHz.
   * This is a kludge until we can better leverage threads and have real events.
   * Without this limit the event flags will constantly polled as fast as possible,
   * resulting on 100% cpu load on boards with an (RT)OS.
   * On bare metal boards this is not an issue, as you have nothing else running anyway.
   */
  uint32_t t_begin = 0;
  uint32_t t_diff = 0;
  while (1) {
    t_begin = get_sys_time_usec();

    handle_periodic_tasks();
    main_event();

    /* sleep remaining time to limit to 1kHz */
    t_diff = get_sys_time_usec() - t_begin;
    if (t_diff < 1000) {
      sys_time_usleep(1000 - t_diff);
    }
  }
#else
  while (1) {
    handle_periodic_tasks();
    main_event();
  }
#endif

  return 0;
}
Exemplo n.º 2
0
int main(void)
{

  mcu_init();
  sys_time_register_timer((1. / PERIODIC_FREQUENCY), NULL);

  /* Init GPIO for rx pins */
  gpio_setup_input_pullup(A_RX_PORT, A_RX_PIN);
  gpio_setup_input_pullup(B_RX_PORT, B_RX_PIN);

  /* Init GPIO for tx pins */
  gpio_setup_output(A_TX_PORT, A_TX_PIN);
  gpio_setup_output(B_TX_PORT, B_TX_PIN);

  gpio_clear(A_TX_PORT, A_TX_PIN);

  /* */
  while (1) {
    if (sys_time_check_and_ack_timer(0)) {
      main_periodic();
    }
    main_event();
  }

  return 0;
}
Exemplo n.º 3
0
int main(void) {

  mcu_init();
  sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);

  /* init RCC */
  rcc_peripheral_enable_clock(&RCC_APB2ENR, A_PERIPH);
  // rccp_perihperal_enable_clock(&RCC_APB2ENR, B_PERIPH);

  /* Init GPIO for rx pins */
  gpio_set(A_RX_PORT, A_RX_PIN);
  gpio_set_mode(A_RX_PORT, GPIO_MODE_INPUT,
          GPIO_CNF_INPUT_PULL_UPDOWN, A_RX_PIN);
  gpio_set(B_RX_PORT, B_RX_PIN);
  gpio_set_mode(B_RX_PORT, GPIO_MODE_INPUT,
          GPIO_CNF_INPUT_PULL_UPDOWN, B_RX_PIN);

  /* Init GPIO for tx pins */
  gpio_set_mode(A_RX_PORT, GPIO_MODE_OUTPUT_50_MHZ,
          GPIO_CNF_OUTPUT_PUSHPULL, A_TX_PIN);
  gpio_set_mode(B_RX_PORT, GPIO_MODE_OUTPUT_50_MHZ,
          GPIO_CNF_OUTPUT_PUSHPULL, B_TX_PIN);

  gpio_clear(A_TX_PORT, A_TX_PIN);

  /* */
  while (1) {
    if (sys_time_check_and_ack_timer(0))
      main_periodic();
    main_event();
  }

  return 0;
}
Exemplo n.º 4
0
void nps_autopilot_run_step(double time __attribute__ ((unused))) {

  if (nps_radio_control_available(time)) {
    radio_control_feed();
    main_event();
  }

  if (nps_sensors_gyro_available()) {
    imu_feed_gyro_accel();
    main_event();
  }

  if (nps_sensors_mag_available()) {
    imu_feed_mag();
    main_event();
 }

  if (nps_sensors_baro_available()) {
    baro_feed_value(sensors.baro.value);
    main_event();
  }

  if (nps_sensors_gps_available()) {
    booz_gps_feed_value();
    main_event();
  }

  if (nps_bypass_ahrs) {
    sim_overwrite_ahrs();
  }

  main_periodic();

  if (time < 8) { /* start with a little bit of hovering */
    int32_t init_cmd[4];
    init_cmd[COMMAND_THRUST] = 0.253*SUPERVISION_MAX_MOTOR;
    init_cmd[COMMAND_ROLL]   = 0;
    init_cmd[COMMAND_PITCH]  = 0;
    init_cmd[COMMAND_YAW]    = 0;
    supervision_run(TRUE, FALSE, init_cmd);
  }
  for (uint8_t i=0; i<ACTUATORS_MKK_NB; i++)
    autopilot.commands[i] = (double)supervision.commands[i] / SUPERVISION_MAX_MOTOR;

}
Exemplo n.º 5
0
int main( void ) {
  main_init();

  while(1) {
    handle_periodic_tasks();
    main_event();
  }
  return 0;
}
Exemplo n.º 6
0
int main( void ) {
  main_init();
  while(1) {
    if (sys_time_check_and_ack_timer(0))
      main_periodic();
    main_event();
  }
  return 0;
}
Exemplo n.º 7
0
int main( void ) {
  main_init();
  while(1) {
    if (sys_time_periodic())
      main_periodic();
    main_event();
  }
  return 0;
}
void nps_autopilot_run_step(double time)
{

  nps_electrical_run_step(time);

#if RADIO_CONTROL && !RADIO_CONTROL_TYPE_DATALINK
  if (nps_radio_control_available(time)) {
    radio_control_feed();
    main_event();
  }
#endif

  if (nps_sensors_gyro_available()) {
    imu_feed_gyro_accel();
    main_event();
  }

  if (nps_sensors_mag_available()) {
    imu_feed_mag();
    main_event();
  }

  if (nps_sensors_baro_available()) {
    float pressure = (float) sensors.baro.value;
    AbiSendMsgBARO_ABS(BARO_SIM_SENDER_ID, pressure);
    main_event();
  }

#if USE_SONAR
  if (nps_sensors_sonar_available()) {
    float dist = (float) sensors.sonar.value;
    AbiSendMsgAGL(AGL_SONAR_NPS_ID, dist);

    uint16_t foo = 0;
    DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &foo, &dist);

    main_event();
  }
#endif

  if (nps_sensors_gps_available()) {
    gps_feed_value();
    main_event();
  }

  if (nps_bypass_ahrs) {
    sim_overwrite_ahrs();
  }

  if (nps_bypass_ins) {
    sim_overwrite_ins();
  }

  handle_periodic_tasks();

  /* scale final motor commands to 0-1 for feeding the fdm */
  for (uint8_t i = 0; i < NPS_COMMANDS_NB; i++) {
    autopilot.commands[i] = (double)motor_mixing.commands[i] / MAX_PPRZ;
  }
}
Exemplo n.º 9
0
void nps_autopilot_run_step(double time __attribute__ ((unused))) {

  if (nps_radio_control_available(time)) {
    radio_control_feed();
    main_event();
  }

  if (nps_sensors_gyro_available()) {
    imu_feed_gyro_accel();
    main_event();
  }

  if (nps_sensors_mag_available()) {
    imu_feed_mag();
    main_event();
 }

  if (nps_sensors_baro_available()) {
    baro_feed_value(sensors.baro.value);
    main_event();
  }

  if (nps_sensors_gps_available()) {
    gps_feed_value();
    main_event();
  }

  if (nps_bypass_ahrs) {
    sim_overwrite_ahrs();
  }

  handle_periodic_tasks();

  /* scale final motor commands to 0-1 for feeding the fdm */
  /* FIXME: autopilot.commands is of length NB_COMMANDS instead of number of motors */
  for (uint8_t i=0; i<SUPERVISION_NB_MOTOR; i++)
    autopilot.commands[i] = (double)(supervision.commands[i] - SUPERVISION_MIN_MOTOR) / SUPERVISION_MAX_MOTOR;

}
Exemplo n.º 10
0
int main(void) {

  hw_init();
  sys_time_init();
  overo_link_init();
  DEBUG_SERVO1_INIT();

  while (1) {
    if (sys_time_periodic())
      main_periodic();
    main_event();
  }

  return 0;
}
Exemplo n.º 11
0
int main(void) {
  main_init();

  servos[0] = 1;
  servos[1] = 2;
  servos[2] = 3;
  servos[3] = 4;

  while (1) {
    if (sys_time_periodic())
      main_periodic();
    main_event();
  }
  return 0;
}
Exemplo n.º 12
0
int main(void)
{

  main_init();
  while (1) {
    if (sys_time_check_and_ack_timer(main_periodic_tid)) {
      main_periodic();
    }
    if (sys_time_check_and_ack_timer(radio_control_tid)) {
      radio_control_periodic_task();
    }
    main_event();
  };
  return 0;
}
Exemplo n.º 13
0
int main(void) {

  mcu_init();
  unsigned int tmr_02 = sys_time_register_timer(0.2, NULL);
  unsigned int tmr_03 = sys_time_register_timer(0.3, NULL);
  sys_time_register_timer(0.5, main_periodic_05);

  while(1) {
    if (sys_time_check_and_ack_timer(tmr_02))
      main_periodic_02();
    if (sys_time_check_and_ack_timer(tmr_03))
      main_periodic_03();
    main_event();
  }

  return 0;
}
Exemplo n.º 14
0
int main(void) {

  mcu_init();
  sys_time_register_timer((1./PERIODIC_FREQUENCY), NULL);

  /* init RCC */
  RCC_APB2PeriphClockCmd(A_PERIPH , ENABLE);
  //  RCC_APB2PeriphClockCmd(B_PERIPH , ENABLE);
  //  GPIO_DeInit(A_RX_PORT);
  /* Init GPIO for rx pins */
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  //  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = A_RX_PIN;
  GPIO_Init(A_RX_PORT, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = B_RX_PIN;
  GPIO_Init(B_RX_PORT, &GPIO_InitStructure);
  /* Init GPIO for tx pins */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = A_TX_PIN;
  GPIO_Init(A_TX_PORT, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = B_TX_PIN;
  GPIO_Init(B_TX_PORT, &GPIO_InitStructure);

  A_TX_PORT->BRR  = A_TX_PIN;

  /* */
  while (1) {
    if (sys_time_check_and_ack_timer(0))
      main_periodic();
    main_event();
  }

  return 0;
}
Exemplo n.º 15
0
int main(void) {

  hw_init();
  sys_time_init();


  /* init RCC */
  RCC_APB2PeriphClockCmd(A_PERIPH , ENABLE);
  //  RCC_APB2PeriphClockCmd(B_PERIPH , ENABLE);
  //  GPIO_DeInit(A_RX_PORT);
  /* Init GPIO for rx pins */
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  //  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = A_RX_PIN;
  GPIO_Init(A_RX_PORT, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = B_RX_PIN;
  GPIO_Init(B_RX_PORT, &GPIO_InitStructure);
  /* Init GPIO for tx pins */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Pin = A_TX_PIN;
  GPIO_Init(A_TX_PORT, &GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = B_TX_PIN;
  GPIO_Init(B_TX_PORT, &GPIO_InitStructure);

  A_TX_PORT->BRR  = A_TX_PIN;

  /* */
  while (1) {
    if (sys_time_periodic())
      main_periodic();
    main_event();
 };
  return 0;
}