ROS driver for Zumo32u4

I modified HomeBrew Robotic’s ros_arduino_bridge to support the zumo 32u4 robot. Pretty simple mods. It works, however the reset encoder count does not reset to 0. Not sure why. Drive works fine though.

Download from https://github.com/pryan1068/ros_arduino_bridge

Hello.

From a cursory glance at its GitHub, it seems that ros_arduino_bridge has a resetEncoder function; are you saying that the ros_arduino_bridge function does not seem to work for you or is one of the functions in our Zumo library not functioning as intended?

-Tony

I implemented the resetEncoder function, but during testing it did not keep the 0 value. Both the Zumo lib and my resetEncoder code are pretty simple; I suspect it’s on the ROS side. Of note, readEncoder() works fine.

Here’s the relevant Arduino code from https://github.com/pryan1068/ros_arduino_bridge/blob/zumo32u4-support/ros_arduino_firmware/src/libraries/ROSArduinoBridge/encoder_driver.ino:

#elif defined(ZUMO32U4)
#include <Zumo32U4Encoders.h>

  /* Create the encoders object */
  Zumo32U4Encoders encoders;

  /* Wrap the encoder reading function */
  long readEncoder(int i) {
    if (i == LEFT)
      return encoders.getCountsLeft();
    else
      return encoders.getCountsRight();
  }

  /* Wrap the encoder reset function */
  void resetEncoder(int i) {
    if (i == LEFT)
      return encoders.getCountsAndResetLeft();
    else
      return encoders.getCountsAndResetRight();
  }
#else
  #error A encoder driver must be selected!
#endif

Hello.

I noticed you have return statements in resetEncoder even though it has a void return type, which causes the expression after the “return” keyword to not be evaluated. If you don’t care about the counts before the reset, you should remove the “return” keyword. If you do want to get that value, you should change the return type of resetEncoder to int.

-Tony

You are the man. That fix worked. I simply removed the return keyword. Good eye.

With that, we now have a working ROS driver for Zumo32u4.

Thanks Tony!!!

1 Like