ev3dev / ev3dev-lang-python

Pure python bindings for ev3dev
MIT License
422 stars 146 forks source link

Motor Ramping Assistance #787

Open TheDoctor2017 opened 1 year ago

TheDoctor2017 commented 1 year ago
ev3dev version: 4.14.117-ev3dev-2.3.5-ev3
ev3dev-lang-python version:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
ii micropython-ev3dev2 2.1.0 all Python language bindings for ev3dev for MicroPython
ii python3-ev3dev 1.2.0 all Python language bindings for ev3dev
ii python3-ev3dev2 2.1.0 all Python language bindings for ev3dev

I am trying to add ramping to my builds. I know it is supported by the Lego software, but I want Python practice so I am using ev3dev. I can't find anything in the basic motor commands. I did find this: https://ev3dev-lang.readthedocs.io/projects/python-ev3dev/en/stable/motors.html But it appears to require a custom class, which is beyond my programming knowledge. Is there anyone out there in ev3dev land that understands how this works that could give me a code example or any other method to support ramping on the motors to avoid the sharp jerk at initial start? Thanks in advance!

dlech commented 1 year ago

Did you try setting ramp_up_sp and ramp_down_sp?

TheDoctor2017 commented 1 year ago

Did you try setting ramp_up_sp and ramp_down_sp?

That's the problem, I don't know how. What is the full syntax of the command?

TheDoctor2017 commented 1 year ago

I figured it out. If anyone else runs across this, here is sample code:

lm = LargeMotor(OUTPUT_B) lm.ramp_up_sp = 2000

Now every time the motor is started it will ramp.

Important! The ramp_up_sp command must come AFTER any tank pairing assignments. For example, this works:

lm = LargeMotor(OUTPUT_A) rm = LargeMotor(OUTPUT_D) tank_pair = MoveTank(OUTPUT_A, OUTPUT_D) lm.ramp_up_sp = 1000 rm.ramp_up_sp = 1000

But this does not:

lm = LargeMotor(OUTPUT_A) rm = LargeMotor(OUTPUT_D) lm.ramp_up_sp = 1000 rm.ramp_up_sp = 1000 tank_pair = MoveTank(OUTPUT_A, OUTPUT_D)

The second code will not generate any errors, but there will be no ramping.