scheduler.c
Go to the documentation of this file.
00001 /***************************************************************************
00002 ***  Fraunhofer IPA 
00003 ***  Robotersysteme 
00004 ***  Projekt: 3D cartography demonstrator
00005 ****************************************************************************
00006 ****************************************************************************
00007 ***  Autor: Julio Sagardoy (goa-js)
00008 ***************************************************************************/
00009 
00017 
00018 #include <avr/io.h>
00019 #include <avr/interrupt.h>
00020 
00022 #include <publisher.h>
00023 #include <scheduler.h>
00024 #include <servo.h>
00025 #include <stepper.h>
00026 #include <utils.h>
00027 
00028 #define SCHED1 25       //(milliseconds)
00029 
00030 static char sl1_isEnabled;
00031 static uint8_t p_count;
00032 static uint8_t t_count;
00033 
00034 void scheduler_layer0()
00035 {       
00036         int16_t p_rem_steps;
00037         uint8_t t_rem_steps;
00038         uint8_t p_lat;
00039         uint8_t t_lat;
00040         
00041         p_rem_steps = stepper_get_rem_steps();  // Remaining steps of the stepper
00042         p_lat = stepper_get_latency();                  // Latency btw steps
00043         t_rem_steps = servo_get_rem_steps();    // Remaining steps of the servo
00044         t_lat = servo_get_latency();                    // Latency btw steps
00045         
00047         if (p_rem_steps > 0)
00048         {
00049                 if(p_count == p_lat )   // Yes, its time to move once
00050                 {
00051                         stepper_advance();
00052                         stepper_set_rem_steps(p_rem_steps - 1);
00053                         p_count = 0;
00054                 }
00055                 else
00056                         p_count++;      // Not yet but just keep waiting
00057         }
00058         
00060         if (t_rem_steps > 0)
00061         {
00062                 if(t_count == t_lat )   // Yes, its time to move once
00063                 {
00064                         servo_advance();
00065                         servo_set_rem_steps(t_rem_steps - 1);
00066                         t_count = 0;
00067                 }
00068                 else
00069                         t_count++;      // Not yet, but just keep waiting
00070         }
00071 }
00072 
00075 void scheduler_Set_sl1( int8_t stat ) {
00076         sl1_isEnabled = stat;
00077 }
00078 int8_t scheduler_Get_sl1( ) {
00079         return sl1_isEnabled;
00080 }
00081 
00084 void scheduler_layer1()
00085 {
00086         if( sl1_isEnabled )
00087         {
00088                 publishData();
00089         }
00090 }
00091 
00092 ISR(TIMER4_COMPA_vect)
00093 {
00095         cli();
00096         
00097         static uint8_t counter1;        
00098         
00099         scheduler_layer0();
00100         
00101         counter1++;
00102         if( counter1 == SCHED1 )
00103         {
00104                 scheduler_layer1();
00105                 counter1 = 0;
00106         }
00107         
00109         sei();
00110 }
00111 
00114 void scheduler_init( )
00115 {
00116         sl1_isEnabled = false;
00117         
00118         // Timer 4 is the scheduler itself
00119         TCCR4A = 0;             // 
00120         TCCR4B = 0x09;  // 0b00001001. CTC mode Prescaler 1
00121 
00122         OCR4A = 14746;  // CTC every 1ms
00123         
00124         TIMSK4 = 0x02;  // 0b00000010; Enable irq OCIE4A
00125 }


cob_3d_mapping_demonstrator
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:03:46