M280 no 'get'?
-
Im using some servos in lieu of steppers and would like to get current position for calibration. Marlin has
M280 Px ; returns Sx value of Px
RRF 3.4.5 returns error without S parameter. When I look at the OM state.gpout it returns a dac value, I need the get digital value. How do I accomplish this?
Heres a vid of what I'm doing;
https://youtu.be/FzovkhonvkI -
-
@wayneosdias both RRF and Marlin support two ranges of S values. Low values are interpreted as angles, while high values are interpreted as pulse widths in microseconds. Which form do you want to convert the PWM to?
-
@dc42 My understanding and how Im attempting to use M280 as a servo controller is that S is a angle. In my case there are two issues.
1, Empirically, I found S is only valid 0-180 for M280. Thats fine but Im using 270 degree servos. Abstracting the 180 to 270 degree;
2, Im not that familiar with servos, but the ones Im using, DS3225, have a dead band of 1-10 cnts for certain ranges. Referring to the above img my start point is 135deg/90cnts, but in reality to get 135deg I need 97cnts on one servo and 100cnts on the other.During use of the machine each time a nozzle is changed the work offsets need to be recalibrated. In BtnCmd I created a Jog panel;
Since I cant seem to find a way to just call M280 Px to receive Sx and apply an offset I need to declare 2 addl globals to set the offset to my two other critical positions 90deg and 180 deg.if param.A=0 if global.Servo1Cnts>global.Servo1CntsCal set global.Servo1Offsets=global.Servo1Cnts-global.Servo1CntsCal set global.Servo1_180=global.Servo1_180+global.Servo1Offsets set global.Servo1_135=global.Servo1_135+global.Servo1Offsets set global.Servo1_90=global.Servo1_90+global.Servo1Offsets else ;global.Servo1Cnts<global.Servo1CntsCal set global.Servo1Offsets=global.Servo1CntsCal-global.Servo1Cnts set global.Servo1_180=global.Servo1_180-global.Servo1Offsets set global.Servo1_135=global.Servo1_135-global.Servo1Offsets set global.Servo1_90=global.Servo1_90-global.Servo1Offsets else if global.Servo2Cnts>global.Servo2CntsCal set global.Servo2Offsets=global.Servo2Cnts-global.Servo2CntsCal set global.Servo2_180=global.Servo2_180+global.Servo2Offsets set global.Servo2_135=global.Servo2_135+global.Servo2Offsets set global.Servo2_90=global.Servo2_90+global.Servo2Offsets else ;global.Servo2Cnts<global.Servo2CntsCal set global.Servo2Offsets =global.Servo2CntsCal-global.Servo2Cnts set global.Servo2_180=global.Servo2_180-global.Servo2Offsets set global.Servo2_135=global.Servo2_135-global.Servo2Offsets set global.Servo2_90=global.Servo2_90-global.Servo2Offsets
It all works, but seems clumsy. Researching M280, Marlin 'gets' S if the S parameter is not set. Does RRF have a simple way of getting current S?
-
@wayneosdias I suggest you retrieve the PWM from the object model and convert that to angle. The formula that RRF uses to convert angle to PWM is:
pulseWidth = ((angle/180) * (2400 - 544)) + 544
pwm = pulseWidth * 1e-6 * pwmFrequencywhere pwmFrequency is 50Hz unless you have changed it. It follows that:
pulseWidth = pwm * 1e6 / 50
angle = (pulseWidth - 544) * (180/(2400-544))So you can use something like this to retrieve the angle:
echo ((state.gpOut[0].pwm * 1000000/50)-544)*(180.0/(2400-544))
which works for me.
-
@dc42 Ah ok, Ill give that a try. Initailly when I looked at the OM state.gpout for feedback the resolution was too low, on the order of tens of mA.
You can see in the screen shots the state.gpout doesnt have the resolution. Despite the servo actually physically moving 20degrees the OM state.gpout is constant;
Is the OM just value just being rounded in the DWC browser formatting?
-
@wayneosdias the value returned in a request for part of the OM is rounded to 2 decimal places. However, if you use the value in a calculation, it is not rounded.
-
@dc42 Perfect, thank you
-
-
@wayneosdias also I've increased the PWM reporting to 3 decimal places in RRF 3.5beta2.
-
@dc42 Thanks again. I rolled back from 3.5 to 3.4.5 because of an issue with CNC mode within DWC; Jogging via DWC throws 'missing u parameter' error. Ill be happy to test 3.5 once that gets resolved