I want to make _pwm a rostopic


I am a student studying ros using rosbot 2.0.

I want to make _pwm rostopic to check the control input of the motor.

Looking at the firmware code, I checked that the function getDutyCycle in the motor driver (DRV8848.h and DRV8848.cpp) can read the PWM as _pwm.read().

Should I add getDutyCycle to main.cpp in firmware?

Or should I write the code by adding a new node to the rosbot_ekf package?

I would really appreciate it if you could give me a starting point and some details.

Thanks for reading.

Hi Chokings,
You can use the RosbotDrive::getSpeed function that is defined in the RosbotDrive.cpp file. It is based on getDutyCycle() function.

I have prepared for you an outline of the solution that is in my fork (link to commit). When you subscribe /pwm topic, message data (Float32) tells you the ratio of low state time to cycle period.

I hope this solution suits you.

Best regards,

Thank you for answer.

A problem occurs when downloading and building the firmware code. I wrote a question about it. How can I solve this?

Thank you again.

Hi Chokings,
You can find an answer there that will help you solve the problem with building PIO project.
Please, let me know if it helped you.

Best regards,