Dual VNH5019 motor driver troubles reading library interpretation

Thread Starter

espayros

Joined Aug 3, 2017
2
Hi to all

I have this powerful motor driver, which documentation is found here
https://github.com/pololu/dual-vnh5019-motor-shield
The thing is, I've been modifying a code that was made for adafruit motor driver V2, in order to use it on this shield.
https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/library-reference
another adafruit library reference https://learn.adafruit.com/afmotor-library-reference/af-dcmotor
I've accomplished make it working (drive two motors) but not in the way I want. The following lines are the ones I changed to do exactly the same.
The order is, original adafruit reading and a comment text with the current vnh5019 reading I put.

Code:
int direction1 = FORWARD;                         // int direction1 = 400
int direction2 = FORWARD;                         // int direction2 = 400
int prev_direction1 = RELEASE;                  // int prev_direction1 = 0
int prev_direction2 = RELEASE;                  // int prev_direction2 = 0
motor1->setSpeed(0);                                  // md.setM1Speed (0)          this line is fine for me
motor2->setSpeed(0);                                  // md.setM2Speed (0)          this line too
motor1->run(FORWARD);                            // md.setM1Speed (400)
motor1->run(RELEASE);                              // md.setM1Speed (0)
motor2->run(FORWARD);                            // md.setM2Speed (400)
motor2->run(RELEASE);                              // md.setM2Speed (0)
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
I think for RELEASE param I should put in there md.setSpeeds(0, 0) because in the second adafruit reference it says "is equivalent to setSpeed (0), but another problem appears: I can't put a library inside a value, for instance "int prev_direction1 = md.setM1Speed(0)". What should I put in that case? and what about the rest?
FORWARD, BACKWARD and motor1/2->run doesn't work that way, so I'm lost in that part. Please I need a proper change and I'm quite new in arduino coding.
By the way, here is the original source code https://github.com/sungjik/my_perso...arduino/motor_controller/motor_controller.ino
And in attachments the one I changed.
Thanks!
 

Attachments

Top