Exemple #1
0
/*********************************************************************
  
  Main Program Loop

**********************************************************************/
int main()
{

  /* Initializations */
  debug_init();     /* This should be first. */
  timer_init();

  /* This should be before any GPIO activities. */
  uint32 ret_val = bcm2835_init(); 
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_init() failed.");
  }

  pwm_init();
  pump_init();
  therm_init();
  pid_init();

  pump_start();

  /* Take temperature as input from console. */
  float setpoint;
  printf("Set your desired temperature: ");
  scanf("%f", &setpoint);
  pid_update_temp_setpoint(setpoint);

  pid_gain_params pid_gain;
  pid_gain.k_p = 1;
  pid_gain.k_d = 1;
  pid_gain.k_i = 1;
  pid_gain.k_windup = 1;
  pid_set_gain(&pid_gain);

  /* Main Program Loop */
  while (1)
  {
    pwm_run();
    therm_capture();
    pid_loop();
  }

  pump_stop();

  /* De-initializations */
  pump_deinit();
  pid_deinit();
  pwm_deinit();

  /* This should be after all GPIO activities. */
  ret_val = bcm2835_close();
  if ( ret_val == 0 )
  {
    DEBUG_MSG_ERROR("bcm2835_close() failed.");
  }
  timer_deinit();
  debug_deinit();   /* This should be last. */

  return 0;
}
Exemple #2
0
int start_servo()
{
    int i;
    for(i=0;i<sizeof(servo_pin)/sizeof(servo_pin[0]);i++)
    {
        pwm_run(servo_pin[i][0], servo_pin[i][1]);
    }
    return 0;
}