This topic has 3 replies, 3 voices, and was last updated 2 years, 3 months ago by aayushkm52.

  • Author
    Posts
  • #8018
     Che Martin
    Participant

    Good Morning All,

    I have the Omni-wheel Vector robot and I am working on making it autonomous. I used the wheel speed in m/s to get a PID output. My question is how do I convert the PID output to a PWM for my Analogwrite command? My PWM range is -225, 255.

    Regards,
    Che

    #8019
     SuperDroid
    Keymaster

    The analogWrite() command takes values from 0 to 255. You need to take the absolute value (or magnitude) of your pid output, scale it to 0-255, and set the direction pin output for that motor high or low depending on the sign.

    #8115
     Che Martin
    Participant

    Good Morning,

    Thank you for your reply. I have been trying to do the scaling but the issue is that that PWM to Speed is not a fully linear relationship. For instance a PWM of 60, 80, 100, produces a wheel speed of .08, .12 and .16 m/s respectively but as I go higher example a PWM of 120,140 and 160, the respective speeds in m/s is .18, .19, 20. My calculation for the wheel speed from encoder ticks is ((current encoder reading – last encoder reading)/1990{ticks per rotation})* 2pi(wheel radius). Any idea on how to get map wheel speed to PWM given that its non-linear?

    Regards,
    Che

    #9519
     aayushkm52
    Participant

    If your wheels have encoders, the usual approach is to use a PID loop to drive the wheels at the specific speed you want, rather than PWMing the motors. That way the PID will make the wheels turn at that speed on different surfaces and angles, and overcome the inertia when it is stopped. It’s smoother and more precise. The cmd_vel message says “I want this many m/s linear and this many rad/sec rotation” and the control node driving your motor converts those to wheel speeds and sends the desired wheel speeds as targets to the PID loop.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Login Register

©2024 SDRobots.com | All rights reserved.

Log in with your credentials

or    

Forgot your details?

Create Account