int main(void)
{
    DDRC |= 1<<LED2;
    DDRC |= 1<<LED3;
    init_TWI();
    motor_init();
    sei();
    while(1)
    {
        if(new_cmd_flag){
            process_cmd(cmd_buf);
        }
    }
}
Пример #2
0
int main(void)
{
  DDRC = 0xff;
  PORTC = 0x80;
  uint8_t i;
  char buf[10];
  
  init_TWI();
  
  while(1)
  {
    _delay_ms(1000);
    get_HM_data();
    if(hm.LoadStatus == 0xc8)
      PORTC &= ~(0x80);
  }
  return 0;
}
Пример #3
0
int main(void){
  //while(1);
  wdt_disable();
  
  ///Configure the Torquer
  configure_torquer();
  char buf[100];
  uint16_t v;
    
  int ao;
  for(ao=0;ao<1;ao++) 
  _delay_ms(1000);  
    
  /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus
  init_UART_MM();
  init_UART_GPS();
  init_SPI();
  init_TWI();
  
  send_preflight("Master\r", 7);
  
  ///Set Preflight pin as input
  cbi(DDR_PF, PIN_PF);
  
  ///* Switch on Global interrupts
  sei();
  
  ///Check if Preflight Pin is high
  while(1){
    
    ///* * Reset timer for 2 seconds
    timer_reset_two_sec();
    //get_HM_data();
    //send_preflight("Power\r", 6);
    
    
    ///* Preflight Checks
    if(0){
      ///* * Set the mode as preflight
      Mode = PREFLIGHT;
      /*slave_send(HM_DATA, "Hello", 5);
      _delay_ms(10);
      
      slave_send (BEGIN_TX_GS, NULL, 0);
      
      //power_up_peripheral(PCC);
      _delay_ms(10);
      
      ao = init_CC1020();
      
      if(ao) 
        send_preflight("CC Init\r", 8);
      else
        send_preflight("No Init\r", 8);
      while(1);*/
      /*power_up_peripheral(PGPS);
      while(1) {
        read_GPS();
      while(UCSR0B & _BV(RXCIE0));
      copy_gps_reading();
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.x/1000, Current_state.gps.y/1000, Current_state.gps.z/1000);
      
      send_preflight(buf, strlen(buf));
      sprintf(buf,"%ld %ld %ld\r", Current_state.gps.v_x/1000, Current_state.gps.v_y/1000, Current_state.gps.v_z/1000);
      
      send_preflight(buf, strlen(buf));
      _delay_ms(1000);
      }*/
      ///* * Magnetometer and Torquer test

	  ///* * Reading with one torquer on at once
      /*Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 10000;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 30000;
      Current_state.pwm.z_dir = 1;
      Current_state.pwm.z = 20000;
      send_preflight("Read\r", 5);
      set_PWM();*/
      while(1) {
        read_SS();
        //send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));
        for(v = 0; v < 6; v++)
        {
          sprintf(buf,"%u\r", (uint16_t)(((float)Current_state.ss.reading[v])*1.6*100/4096));
          send_preflight(buf, strlen(buf));
          sprintf(buf,"%x\r", Current_state.ss.reading[v]);
          send_preflight(buf, strlen(buf));
          
      }
      _delay_ms(1000);
    }
	  ///* * Set Torquer values to zero
      reset_PWM();
      while(1)
        read_MM();

      read_GPS();
      send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));
      
      ///* * Sunsensor test
      read_SS();
      send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));

      ///* Health Montoring
      get_HM_data();
      send_preflight((char *)&Current_state.hm, sizeof(struct HM_data));
	  
      ///Communication Task
      comm();
	  
	  ///* * Wait for 2 seconds to get over
      timer_wait_reset();
    }

  ///Normal Mode
  
    else{
    
      ///* Set default mode of Satellite
      Mode = DETUMBLING;
      
      ///* initialise Timer
      Time = 0;
      
      ///Loop begins
      while(1){
        //Fuses Pain, Nominal Mode checking
        send_preflight("Loop\r", 5);
        control();
        send_preflight("Control\r", 8);
        //power();
        comm();
        send_preflight("Comm\r", 5);
        v = StackCount();
        sprintf(buf, "Stack = %d\r", v);
        send_preflight(buf, strlen(buf));
        v = get_free_memory();
        sprintf(buf, "Stack(Method 2) = %d\r", v);
        send_preflight(buf, strlen(buf));
        Time += FRAME_TIME;
        timer_wait_reset();
      }
    }
  }
  return 0;
}
Пример #4
0
int main(void){
  
  ///Configure the Torquer
  configure_torquer();
    
  _delay_ms(1000);  
  
  /// Initialise Interfaces - UART of Magnetometer and GPS and the SPI bus
  init_UART_MM();
  init_UART_GPS();
  init_SPI();
  init_TWI();
  
  ///Set Preflight pin as input
  cbi(DDR_PF, PIN_PF);
  
  ///* Switch on Global interrupts
  sei();
  
  ///Check if Preflight Pin is high
  while(1){
    
    ///* * Reset timer for 2 seconds
    timer_reset_two_sec();
    
    ///* Get Health Monitoring data
    get_HM_data();
    
    ///* Preflight Checks
    if(PORT_PF & _BV(PIN_PF)){
      ///* * Set the mode as preflight
      Mode = PREFLIGHT;
      
      
      send_preflight("Master\r", 7);
      
      ///* * GPS test
      read_GPS();
      while(UCSR0B & _BV(RXCIE0));
      send_preflight((char *)&Current_state.gps, sizeof(struct GPS_reading));

      ///* * Magnetometer and Torquer test

      ///* * Reading with no torquers on
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
	  ///* * Reading with one torquer on at once
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 32768;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
  
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 32768;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 32768;  
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));

	  ///* * Reading with one torquer on at once, in other direction
      Current_state.pwm.x_dir = 1;
      Current_state.pwm.x = 32768;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
  
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 1;
      Current_state.pwm.y = 32768;
      Current_state.pwm.z_dir = 0;
      Current_state.pwm.z = 0;
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
      
      Current_state.pwm.x_dir = 0;
      Current_state.pwm.x = 0;
      Current_state.pwm.y_dir = 0;
      Current_state.pwm.y = 0;
      Current_state.pwm.z_dir = 1;
      Current_state.pwm.z = 32768;  
      set_PWM ();
      read_MM ();
      send_preflight((char *)&Current_state.mm, sizeof(struct MM_reading));
	  
	  ///* * Set Torquer values to zero
      reset_PWM();


      ///* * Sunsensor test
      read_SS();
      send_preflight((char *)&Current_state.ss, sizeof(struct SS_reading));

      ///* Health Montoring
      get_HM_data();
      send_preflight((char *)&Current_state.hm, sizeof(struct HM_data));
	  
      ///Communication Task
      comm();
	  
	  ///* * Wait for 2 seconds to get over
      timer_wait_reset();
    }

  ///Normal Mode
  
  else{
    
    ///* Set default mode of Satellite
    Mode = DETUMBLING;
    
    ///* initialise Timer
    Time = 0;
	 
    ///Loop begins
    while(!(PORT_PF & _BV(PIN_PF))){
      
      
  
      /**
      * * * * Task 2: Control codes
       * @ref control
       */
    
      
      control();
      
      /**
      * * * * Task 1: Communication with power uC through I2C. @ref power
      */
      power();

      

      /**
      * * * * Task 3: Communication check routine;
      * @ref comm
      */
      comm();
      
      wdt_disable();
      
      ///* * Increment the Timer
      Time += FRAME_TIME;
      
      ///* * Wait for 2 seconds to get over
      timer_wait_reset();
      
      }
    }
  }
  return 0;
}