#include <FeedbackSensor.h>
Public Member Functions | |
void | disableSensor () |
void | enableSensor () |
FeedbackSensor () | |
int | getFeedback () |
Private Attributes | |
bool | feedback_inv1 |
bool | feedback_inv2 |
Definition at line 13 of file FeedbackSensor.h.
FeedbackSensor::FeedbackSensor | ( | ) |
initialized the external interrupt
Definition at line 13 of file FeedbackSensor.c.
References disableSensor(), feedback_inv1, feedback_inv2, wheel1, and wheel2.
00013 { 00014 00015 00016 // set data direction to input 00017 DDRD &= ~((1<<PD2) | (1<<PD6)); // for second sensor | | (1<<PD3) | (1<<PD7)); 00018 00019 // enable pullups 00020 PORTD |= (1<<PD2) | (1<<PD6); // for second sensor | (1<<PD3) | (1<<PD7); 00021 00022 // consider falling and rising edges 00023 MCUCR |= (1<<ISC10) | (1<<ISC00); 00024 00025 // consider only falling edges 00026 //MCUCR |= (1<<ISC01) | (1<<ISC11);// | (1<<ISC01) | (1<<ISC11); 00027 00028 // disable sensor 00029 this->disableSensor(); 00030 00031 // initialize feedback values 00032 feedback_inv1 = feedback_inv2 = false; 00033 wheel1 = wheel2 = 0; 00034 }
void FeedbackSensor::disableSensor | ( | ) |
disable serial interrupt
Definition at line 49 of file FeedbackSensor.c.
Referenced by Environment::doAction(), and FeedbackSensor().
00049 { 00050 00051 00052 cli(); 00053 00054 // set interrupt register flags 00055 GICR &= ~((1<<INT0)); // for second sensor | (1<<INT1)); 00056 GIFR &= ~((1<<INTF0)); // for second sensor | (1<<INTF1)); 00057 00058 }
void FeedbackSensor::enableSensor | ( | ) |
active external incremental encoder (external interrupt)
Definition at line 37 of file FeedbackSensor.c.
References wheel1, and wheel2.
Referenced by Environment::doAction().
00037 { 00038 00039 // reset counters 00040 wheel1 = wheel2 = 0; 00041 00042 // set interrupt register flags 00043 GICR |= (1<<INT0); // for second sensor | (1<<INT1); 00044 GIFR |= (1<<INTF0); // for second sensor | (1<<INTF1); 00045 sei(); 00046 }
int FeedbackSensor::getFeedback | ( | ) |
returns the collected reward from both sensors
Definition at line 61 of file FeedbackSensor.c.
References feedback_inv1, feedback_inv2, FEEDBACK_THRESHOLD, BoardController::getSwitchState(), SWITCH_INV_FB_0, wheel1, and wheel2.
Referenced by Environment::doAction().
00061 { 00062 00063 int _fb = 0; 00064 00065 00066 // add sensor0 value 00067 if (!feedback_inv1) { 00068 _fb += wheel1; 00069 } else { 00070 _fb -= wheel1; 00071 } 00072 00073 // add sensor1 value 00074 if (!feedback_inv2) { 00075 00076 if (((int)_fb + (int)wheel2) <= 127) { 00077 _fb += wheel2; 00078 } else { 00079 _fb = 127; 00080 } 00081 00082 } else { 00083 if (((int)_fb + (int)wheel2) > -127) { 00084 _fb -= wheel2; 00085 } else { 00086 _fb = -127; 00087 } 00088 } 00089 00090 // reset counters 00091 wheel1 = wheel2 = 0; 00092 00093 00094 // check for reward-signal invertion 00095 if (BoardController::getSwitchState(SWITCH_INV_FB_0)==0) { 00096 _fb *= -1; 00097 } 00098 00099 // suppress noise 00100 if (abs(_fb) >= FEEDBACK_THRESHOLD) return _fb; 00101 else return(0); 00102 }
bool FeedbackSensor::feedback_inv1 [private] |
bool FeedbackSensor::feedback_inv2 [private] |