I read your first post again, and I think I understand what it is you are trying to do. Can you tell me what your modified code is actually doing and what you expect it to do?
I looked at the code and comments in your first post and noticed that you are replacing
void run(uint8_t) from the Adafruit_MotorShield library with
void setM1Speed(int speed) from the DualVNH5019MotorShield library. According to the library reference section for the Adafruit Motor Shield V2,
run just controls the motors’ direction and state. However,
setSpeeds sets both the direction and speed of a motor channel in the DualVNH5019MotorShield library. The motor direction is determined by the sign of the speed number, which is what the conditional IF/ELSE IF statements are doing in your code.
You can condense this part of your code:
if(PWM_val1 > 0) direction1 = FORWARD; // if(PWM_val1 > 0) direction1 = 400
else if(PWM_val1 < 0) direction1 = BACKWARD; // else if(PWM_val1 < 0) direction1 = -400
if (rpm_req1 == 0) direction1 = RELEASE; // if (rpm_req1 == 0) direction1 = 0
if(PWM_val2 > 0) direction2 = FORWARD; // if(PWM_val2 > 0) direction2 = 400
else if(PWM_val2 < 0) direction2 = BACKWARD; // else if(PWM_val2 < 0) direction2 = -400
if (rpm_req2 == 0) direction2 = RELEASE; // if (rpm_req2 == 0) direction2 = 0
motor1->run(direction1); // md.setM1Speed(direction1)
motor2->run(direction2); // md.setM2Speed(direction2)
motor1->setSpeed(abs(PWM_val1)); // md.setM1Speed(abs(PWM_val1)) this line is fine for me
motor2->setSpeed(abs(PWM_val2)); // md.setM2Speed(abs(PWM_val2)) this line too
if (rpm_req1 == 0)
if (rpm_req2 == 0)
I did not look at the rest of your Arduino sketch, since it is quite long. If you are still having trouble converting your code, please simplify your code as much as possible to where it should work, but does not, then post it here.