Discussion - Motor Guide (Making a Mobile Robot Pt 7)

Thank you for your answer. I solved the problem. At first I let the blue and black cable (positive and negative switching control) empty. Now I put 5 volts to the one and ground the other one. Now it works fine.

@JoshNewans I’m trying to rewrite your ros Arduino bridge into a complete Raspberry Pi Pico/ Micro-ROS library. I’m setting up a MotorData ROS2 service, with the intent of sending position and velocity data from the Pico, to an RPI.

I am not running your library on my motors, so my mental model comes from reading code only.

In the diff_drive_arduino library, when the HW interface calls the comms_.read_encoder_values(wheel_l_.enc, wheel_r_.enc) method, what is actually returned? Is it all encoder counts since the Arduino got powered up, or is it the number of counts since the last call?

The reason I’m asking is that with my current (pun) cheap DC motor Hall effect encoders, all I can do is increment a count variable whenever there is an interrupt on the correct GPIO pin. I have no problems computing the current angular velocity from the counts and delta_time, but the position term really puzzles me.

EDIT: I just watched the video where you write the HW interface from start. I was not ready for that video until now. Now I understand position is the total angular displacement since startup. Thank you so much for the effort you lay down :slight_smile:

@JoshNewans hello i have a question, can the arduino program on your repo need improve if i use differen motor driver shield like pololu VNH5019 or IBT-2 (BTS7960)? because i need more power for the motor

good day @joshnewans I have some doubts about closed-loop control, I am using Waveshare DCGM-3865-12V-240RPM Motor (https://www.waveshare.com/wiki/DCGM-3865-12V-EN-240RPM) when I using open loop control to control motor speed using pulse with modulation it works fine. while going to closed loop system I can’t understand why you giving 1.5 for rev/sec (So your motor rpm is 90) or if any other thing is there, by changing the slider can we able to control the rpm of the motor? but in my case speed is not changing my motor rpm is 240/60=4 if I change the slider I can’t see any variation in the speed of the motor shaft but direction control works fine

Hey @JoshNewans , instead of the arduino and L298N, coul’d we have use a DC HAT? like Adafruit DC & Stepper Motor HAT for Raspberry Pi

I am Having the same issue and have also connected all the wires ,please help i am getting the e values as 0 0 ans using arduino mega with the same pins layout

Hi @Tony_Stark, I am having the same problem. You need to change the values of the pins in encoder_driver.h arduino code. The PORTD and PORTC pins are different for arduino mega.

/*

  • Visual representation of the ports and respective
  • pins for the Arduino Mega
    */
    //-------------------------------------------------------
    // LSB P0 P1 P2 P3 P4 P5, P6, P7 MSB
    //-------------------------------------------------------
    // PORTA = {22, 23, 24, 25, 26, 27, 28, 29};
    // PORTF = {A0, A1, A2, A3, A4, A5, A6, A7};
    // PORTK = {A8, A9, A10, A11, A12, A13, A14, A15};
    // PORTC = {37, 36, 35, 34, 33, 32, 31, 30};
    // PORTL = {49, 48, 47, 46, 45, 44, 43, 42};
    // PORTB = {53, 52, 51, 50, 10, 11, 12, 13};
    // PORTG = {41, 40, 39, xx, xx, 4, xx, xx};
    // PORTD = {21, 20, 19, 18, xx, xx, xx, 38};
    // PORTE = {0, 1, xx, 5, 2, 3, xx, xx};
    // PORTH = {17, 16, xx, 6, 7, 8, 9, xx};
    // PORTJ = {15, 14, xx, xx, xx, xx, xx, xx};
    //-------------------------------------------------------

But even after updating the values, it does not seem to work

I just solved the problem. I will share the link to the repository in a couple of days