Entering an if(x > y) statement when x & y both equal 0

Your problems are simple programming errors, caused by not paying attention.

Does that mean you see the problem? Could you explain what you're seeing that I am clearly not?

I confirmed that the presence of the Serial.print() does in in fact change the value of extArm.
If I place another Serial.print() inside the if statement, extArm comes out as .000404.

  //Serial.println(extArm, 15);
  if(abs(extOrder) < abs(armExt)){
    Serial.println(extArm);
    extOrder = 0.0;
    shaftPos = 0.0;
    armExt = 0.0;
    M2Encoder.write(0);
  }

but having it in front of the if() statement, extArm reads truly 0

  Serial.println(extArm, 15);
  if(abs(extOrder) < abs(armExt)){
    //Serial.println(extArm, 15);
    extOrder = 0.0;
    shaftPos = 0.0;
    armExt = 0.0;
    M2Encoder.write(0);
  }

So the existence of the serial.print causes the value to change, why?
It's worth noting that if I remove the Serial.print() Inside the if statement as well as the one outside, this resolves the issue too. This further tells me the Serial.print() is somehow affecting the value of armExt

Are you referring to the fact that I never actually set the motor power to 0? This is deliberate (and my college professor insisted I do this) because the proportional control will cause the motor power order to go to 0 when it reaches its destination.

I don't know if the values are really changing but it's USUALLY A BAD IDEA to expect two different float values to be EXACTLY equal.

You might want to subtract and check for a difference, depending on how close they have to be.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.