Stepper motor with more revolution for altimeter.
Stepper motor with more revolution for altimeter.
Hi everyone.
This is my first topic
I almost have done my first Cessna 172 cockpit just before I noticed quite a big problem.
I have a single stepper motor powered altimeter and to work properly it has to move around with the 100ft needle, so e.q. to achieve 10'000ft stepper has to execute 10 full rotations.
The problem is that AM allows to move from 0.0 to 1.0, so only 360°.
I read something about message port but I don't know If I fully understand the topic.
Maybe with message port I can use another arduino board to run just stepper motors (I need also 2 of them to run heading indicator and autopilot hdg bug) and code them with arduino ino, but I have no idea how it should look like :/
I also tried to make it with "if, elseif" to specify every 1000ft but only first 1000ft (360°) worked and then stepper died.
Any advice will be nice If You open in full window mode, altimeter is in the top (without stepper) and at the left-bottom site are located 2 steppers for heading indicator. Photo from front.
This is my first topic
I almost have done my first Cessna 172 cockpit just before I noticed quite a big problem.
I have a single stepper motor powered altimeter and to work properly it has to move around with the 100ft needle, so e.q. to achieve 10'000ft stepper has to execute 10 full rotations.
The problem is that AM allows to move from 0.0 to 1.0, so only 360°.
I read something about message port but I don't know If I fully understand the topic.
Maybe with message port I can use another arduino board to run just stepper motors (I need also 2 of them to run heading indicator and autopilot hdg bug) and code them with arduino ino, but I have no idea how it should look like :/
I also tried to make it with "if, elseif" to specify every 1000ft but only first 1000ft (360°) worked and then stepper died.
Any advice will be nice If You open in full window mode, altimeter is in the top (without stepper) and at the left-bottom site are located 2 steppers for heading indicator. Photo from front.
Re: Stepper motor with more revolution for altimeter.
You can go from 0.99 for example to 0, without going back. You'll just have to some smart scripting with fastest and slowest, and probably using % so you always stay at 1 and below.
Re: Stepper motor with more revolution for altimeter.
Perhaps if you posted your existing code we could take a look.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Stepper motor with more revolution for altimeter.
This how my code looks like for now. It has to has more "elseif" for each 1000ft, but as I mentioned before, for now only first 1000ft works and then stepper die...
I'm also worry about that if simulator starts at e.g. 3400ft, my stepper would run only 400ft forward because of my non smart code.
I'm also worry about that if simulator starts at e.g. 3400ft, my stepper would run only 400ft forward because of my non smart code.
Code: Select all
--Made by Wendy, FlightSimparts.eu
--use as you like
local CollectData = false
function input_change(state)
if state == false then
hw_stepper_motor_calibrate(id, 0.0)
hw_stepper_motor_position(id, 0.0)
CollectData = true
end
print("state = " .. tostring(state))
end
-- Initialization starting, rotate clockwise for 3 seconds
id = hw_stepper_motor_add("Altimeter", "4WIRE_4STEP", 2048, 60)
-- Initialization starting, rotate clockwise for 3 seconds
hw_stepper_motor_position(id, nil, "ENDLESS_COUNTERCLOCKWISE")
input = hw_input_add("ZeroStop", input_change)
local function new_altitude(altitude)
altimeter_altitude = var_cap(altitude, 0, 40000)
if CollectData == true then
hw_stepper_motor_position(id, 1/1000 * altitude) -- , "FASTEST")
elseif (CollectData == true and altitude >= 1000) then
hw_stepper_motor_position(id, 1/1000 * (altitude - 1000))
else
end
end
xpl_dataref_subscribe("sim/cockpit2/gauges/indicators/altitude_ft_pilot", "FLOAT", new_altitude)
Re: Stepper motor with more revolution for altimeter.
Your code will always do the first if because that condition is always met after calibration. But rather than fix that, It just seems excessive to use all those if..else. Why not just something like this. You will need to handle the minus altitudes slightly differently but i'll let you do that.
Code: Select all
if CollectData == true then
hw_stepper_motor_position(id, altitude % 1000)
end
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Stepper motor with more revolution for altimeter.
Yeah!Sling wrote: ↑Sat Sep 25, 2021 1:41 pm Your code will always do the first if because that condition is always met after calibration. But rather than fix that, It just seems excessive to use all those if..else. Why not just something like this. You will need to handle the minus altitudes slightly differently but i'll let you do that.
Code: Select all
if CollectData == true then hw_stepper_motor_position(id, altitude % 1000) end
If I could I would buy u a beer
Now my code looks like that and works just fine! I even deleted the "var_cap" values and works both positive and negative altitudes.
Thanks a lot
Code: Select all
if CollectData == true then
hw_stepper_motor_position(id, ((altitude % 1000) / 1000), "FASTEST")
end
Re: Stepper motor with more revolution for altimeter.
Happy to assist. Glad you got it working.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Stepper motor with more revolution for altimeter.
The only problem I can think of is that if you reset your flight, it can get out of sync. So it might be smart to set the position/altitude through a timer.
I think that there are a few Cessna 172 instruments that use this for the animation. You could use this as an example.
I think that there are a few Cessna 172 instruments that use this for the animation. You could use this as an example.
Re: Stepper motor with more revolution for altimeter.
You might be right, I have to look for it, thanks.Ralph wrote: ↑Sun Sep 26, 2021 9:36 am The only problem I can think of is that if you reset your flight, it can get out of sync. So it might be smart to set the position/altitude through a timer.
I think that there are a few Cessna 172 instruments that use this for the animation. You could use this as an example.
Re: Stepper motor with more revolution for altimeter.
Let us know if you need help with that part.