Roland schrieb:Wie hast du diese denn montiert? Hast du mal ein Bild? Rein interessehalber
ISR(PCINT2_vect){
#endif
unsigned long timeMicros = micros();
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryLeftState2 = digitalRead(pinOdometryLeft2);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryRightState2 = digitalRead(pinOdometryRight2);
boolean motorMowRpmState = digitalRead(pinMotorMowRpm);
robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);
robot.setMotorMowRPMState(motorMowRpmState);
}
void Robot::calcOdometry(){
double left_cm = ((double)ticksLeft) / ((double)odometryTicksPerCm);
double right_cm = ((double)ticksRight) / ((double)odometryTicksPerCm);
// Angepasst: Chris
#ifdef __AVR__
ISR(PCINT2_vect){
unsigned long timeMicros = micros();
boolean odometryLeftState = bitRead(PINK,4);
boolean odometryLeftState2 = bitRead(PINK,5);
boolean odometryRightState = bitRead(PINK,6);
boolean odometryRightState2 = bitRead(PINK,7);
boolean motorMowRpmState = bitRead(PINK,3);
robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);
robot.setMotorMowRPMState(motorMowRpmState);
#else
ISR(PCINT2_vect){
unsigned long timeMicros = micros();
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryLeftState2 = digitalRead(pinOdometryLeft2);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryRightState2 = digitalRead(pinOdometryRight2);
boolean motorMowRpmState = digitalRead(pinMotorMowRpm);
robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);
robot.setMotorMowRPMState(motorMowRpmState);
#endif
}
void Robot::setOdometryState(unsigned long timeMicros, boolean odometryLeftState, boolean odometryRightState, boolean odometryLeftState2, boolean odometryRightState2){
int leftStep = 1;
int rightStep = 1;
if (odometryLeftSwapDir) leftStep = -1;
if (odometryRightSwapDir) rightStep = -1;
if (odometryLeftState != odometryLeftLastState){
if (odometryLeftState){ // pin1 makes LOW->HIGH transition
if (twoWayOdometrySensorUse) {
// pin2 = HIGH? => forward
if (odometryLeftState2) odometryLeft += leftStep; else odometryLeft -= leftStep;
}
else {
if (motorLeftPWMCurr >=0) odometryLeft ++; else odometryLeft --;
}
}
odometryLeftLastState = odometryLeftState;
}
if (odometryRightState != odometryRightLastState){
if (odometryRightState){ // pin1 makes LOW->HIGH transition
if (twoWayOdometrySensorUse) {
// pin2 = HIGH? => forward
if (odometryRightState2) odometryRight += rightStep; else odometryRight -= rightStep;
}
else {
if (motorRightPWMCurr >=0) odometryRight ++; else odometryRight --;
}
}
odometryRightLastState = odometryRightState;
}
if (twoWayOdometrySensorUse) {
if (odometryRightState2 != odometryRightLastState2){
odometryRightLastState2 = odometryRightState2;
}
if (odometryLeftState2 != odometryLeftLastState2){
odometryLeftLastState2 = odometryLeftState2;
}
}
}
#ifdef __AVR__
ISR(PCINT2_vect, ISR_NOBLOCK){
#else
ISR(PCINT2_vect){
#endif
unsigned long timeMicros = micros();
#ifdef twoWayOdometrySensorUse
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryLeftState2 = digitalRead(pinOdometryLeft2);
boolean odometryRightState2 = digitalRead(pinOdometryRight2);
#else
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryLeftState2 = 0;
boolean odometryRightState2 = 0;
#endif
boolean motorMowRpmState = digitalRead(pinMotorMowRpm);
robot.setOdometryState(timeMicros, odometryLeftState, odometryRightState, odometryLeftState2, odometryRightState2);
robot.setMotorMowRPMState(motorMowRpmState);
}
#if defined(twoWayOdometrySensorUse) && twoWayOdometrySensorUse == 1
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryLeftState2 = digitalRead(pinOdometryLeft2);
boolean odometryRightState2 = digitalRead(pinOdometryRight2);
#else
boolean odometryLeftState = digitalRead(pinOdometryLeft);
boolean odometryRightState = digitalRead(pinOdometryRight);
boolean odometryLeftState2 = 0;
boolean odometryRightState2 = 0;
#endif