Stepper Calibration

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
JanisZvirgzdins
Posts: 21
Joined: Fri Feb 25, 2022 12:34 pm

Stepper Calibration

#1 Post by JanisZvirgzdins »

Hello!

I have created a code for Boeing chronometer that runs with stepper motor and hall sensor for calibration. Everything works kinda ok, except that everytime the needle passes the sensor, it tries to calibrate again. Is there a way to include in code that it calibrates only once? And then ignores the Hall sensor after calibration is done. Thanks!

Here is the code:

Code: Select all

NEEDLE = hw_stepper_motor_add("CHRONO", "4WIRE_4STEP", 2048, 30)

hw_stepper_motor_position(NEEDLE, nil, "ENDLESS_CLOCKWISE")

 function hall_sensor(position)
          
    if position == 0 then
    hw_stepper_motor_calibrate(NEEDLE, 0.52)
    hw_stepper_motor_position(NEEDLE, 0.0)
    end             
end


timer_start(10000, function ()
function chronometer(data)
hw_stepper_motor_position(NEEDLE, 1/60 * data)
end
xpl_dataref_subscribe("laminar/B738/clock/captain/chrono_seconds_needle", "FLOAT", chronometer)
end)

hw_switch_add("SENSOR ", 1, hall_sensor)

User avatar
Ralph
Posts: 7917
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Stepper Calibration

#2 Post by Ralph »

Make a global variable called calibrated for example. Then set it to true when the calibration is done and only do your calibration if it is false. So...

Code: Select all

if not calibrated then
  your calibration stuff...
end

JanisZvirgzdins
Posts: 21
Joined: Fri Feb 25, 2022 12:34 pm

Re: Stepper Calibration

#3 Post by JanisZvirgzdins »

Thanks, Ralph, it sounds logic. But I'm not sure, I even know where to start... :D:D

User avatar
Ralph
Posts: 7917
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Stepper Calibration

#4 Post by Ralph »

You'll get something like this:

Code: Select all

local calibrated = false
NEEDLE = hw_stepper_motor_add("CHRONO", "4WIRE_4STEP", 2048, 30)

hw_stepper_motor_position(NEEDLE, nil, "ENDLESS_CLOCKWISE")

function hall_sensor(position)
  if position == 0 and not calibrated then
    hw_stepper_motor_calibrate(NEEDLE, 0.52)
    hw_stepper_motor_position(NEEDLE, 0.0)
    calibrated = true
  end             
end


timer_start(10000, function ()
  function chronometer(data)
    if calibrated then -- Optional extra check, you can leave this one out if 10 seconds is always enough
      hw_stepper_motor_position(NEEDLE, 1/60 * data)
    end
  end
  xpl_dataref_subscribe("laminar/B738/clock/captain/chrono_seconds_needle", "FLOAT", chronometer)
end)

hw_switch_add("SENSOR ", 1, hall_sensor)

JanisZvirgzdins
Posts: 21
Joined: Fri Feb 25, 2022 12:34 pm

Re: Stepper Calibration

#5 Post by JanisZvirgzdins »

Thank you so much, I could never figure it out by myself! Now everythig is OK! Thank you!!!

Post Reply