FeedbackSensor Class Reference

#include <FeedbackSensor.h>


Public Member Functions

void disableSensor ()
void enableSensor ()
char getFeedback ()
void init ()
void invertSensor (unsigned char _sensorId, bool _state)

Private Attributes

bool feedback_inv0
bool feedback_inv1


Detailed Description

Definition at line 12 of file FeedbackSensor.h.


Member Function Documentation

void FeedbackSensor::disableSensor (  ) 

disable serial interrupt

Definition at line 48 of file FeedbackSensor.c.

Referenced by init(), and ValueIteration::moveAndSaveFeedback().

00048                                    {
00049 
00050 
00051      cli();
00052 
00053      // set interrupt register flags
00054      GICR  &= ~((1<<INT0)); // for second sensor | (1<<INT1));
00055      GIFR  &= ~((1<<INTF0)); // for second sensor | (1<<INTF1));
00056 
00057 }

void FeedbackSensor::enableSensor (  ) 

active external incremental encoder (external interrupt)

Definition at line 35 of file FeedbackSensor.c.

References feedback_value0, and feedback_value1.

Referenced by ValueIteration::moveAndSaveFeedback().

00035                                   {
00036 
00037      // reset counters
00038      feedback_value0 = feedback_value1 = 0;
00039 
00040      // set interrupt register flags
00041      GICR |= (1<<INT0); // for second sensor |  (1<<INT1);
00042      GIFR |= (1<<INTF0); // for second sensor | (1<<INTF1);
00043      sei();
00044      
00045 }

char FeedbackSensor::getFeedback (  ) 

returns the collected reward from both sensors

Definition at line 60 of file FeedbackSensor.c.

References feedback_inv0, feedback_inv1, FEEDBACK_THRESHOLD, feedback_value0, and feedback_value1.

Referenced by ValueIteration::moveAndSaveFeedback().

00060                                   {
00061 
00062      int _fb = 0;
00063      
00064      
00065      // add sensor0 value
00066      if (!feedback_inv0) {
00067           _fb += feedback_value0;
00068      } else {
00069           _fb -= feedback_value0;
00070      }
00071 
00072      // add sensor1 value
00073      if (!feedback_inv1) {
00074 
00075           if (((int)_fb + (int)feedback_value1) <= 127) {
00076                _fb += feedback_value1;
00077           } else {
00078                _fb = 127;
00079           }
00080 
00081      } else {
00082           if (((int)_fb + (int)feedback_value1) > -127) {
00083                _fb -= feedback_value1;
00084           } else {
00085                _fb = -127;
00086           }
00087      }
00088 
00089      // reset counters
00090      feedback_value0 = feedback_value1 = 0;
00091 
00092      // suppress noise
00093      if (abs(_fb) >= FEEDBACK_THRESHOLD) return _fb;
00094      else return(0);
00095 }

void FeedbackSensor::init (  ) 

initialized the external interrupt

Definition at line 11 of file FeedbackSensor.c.

References disableSensor(), feedback_inv0, feedback_inv1, feedback_value0, and feedback_value1.

Referenced by ValueIteration::init().

00011                           {
00012 
00013 
00014      // set data direction to input
00015      DDRD &= ~((1<<PD2) | (1<<PD6)); // for second sensor | | (1<<PD3) | (1<<PD7));
00016 
00017      // enable pullups
00018      PORTD |= (1<<PD2) | (1<<PD6); // for second sensor | (1<<PD3) | (1<<PD7);
00019 
00020      // consider falling and rising edges 
00021      MCUCR  |= (1<<ISC10) | (1<<ISC00);
00022      
00023      // consider only falling edges
00024      //MCUCR  |= (1<<ISC01) | (1<<ISC11);// | (1<<ISC01) | (1<<ISC11);
00025 
00026      // disable sensor
00027      this->disableSensor();
00028 
00029      // initialize feedback values
00030      feedback_inv0 = feedback_inv1 = false;
00031      feedback_value0 = feedback_value1 = 0;
00032 }

Here is the call graph for this function:

void FeedbackSensor::invertSensor ( unsigned char  _sensorId,
bool  _state 
)

invert a feedback sensor

Definition at line 98 of file FeedbackSensor.c.

References feedback_inv0, feedback_inv1, FEEDBACK_SENSOR_0, and FEEDBACK_SENSOR_1.

Referenced by ValueIteration::moveAndSaveFeedback().

00098                                                                       {
00099 
00100      if (_sensorId == FEEDBACK_SENSOR_0) {
00101           feedback_inv0 = _state;
00102      } else if (_sensorId == FEEDBACK_SENSOR_1) {
00103           feedback_inv1 = _state;
00104      } 
00105 }


Field Documentation

Definition at line 22 of file FeedbackSensor.h.

Referenced by getFeedback(), init(), and invertSensor().

Definition at line 22 of file FeedbackSensor.h.

Referenced by getFeedback(), init(), and invertSensor().


The documentation for this class was generated from the following files:

Generated on Wed Mar 25 12:58:42 2009 for Crawling Robot Microcontroller Software by  doxygen 1.5.5