Stepper motor Fs2020

Support for Arduino in combination with Air Manager and Air Player

Moderators: Ralph, russ

Post Reply
Posts: 2
Joined: Sat Apr 10, 2021 5:48 pm

Stepper motor Fs2020

#1 Post by BlackHook » Sun Apr 11, 2021 8:38 am

I started in programming, I did some switch and now I try to operate a stepper motor to engine RPM but I have some worries code for FS2020

message error :
ERROR - error in dataref callback: logic.lua:11: attempt to index a number value (local 'rpm')

Can you help me?

Code: Select all

stepper_rpm = hw_stepper_motor_add("Engine RPM", "4WIRE_4STEP", 945, 30)

-- Initialization starting, rotate clockwise for 3 seconds
hw_stepper_motor_position(stepper_rpm, nil, "ENDLESS_CLOCKWISE")

timer_start(3000, function(count)
    hw_stepper_motor_calibrate(stepper_rpm, 0.0)
    hw_stepper_motor_position(stepper_rpm, 0.0)

    local function PT_rpm_FSX(rpm)
      engine_rpm = var_cap(rpm[1], 0, 3500)
      -- The stepper motor position is set as a value from 0 to 1, so we have to convert the RPM to a position.
      -- Therefore we divide 1 by 3500, this is then multiplied with the current RPM.
      hw_stepper_motor_position(stepper_rpm, 1 / 3500 * engine_rpm)

    fs2020_variable_subscribe("PROP RPM:1", "RPM", PT_rpm_FSX)

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

Re: Stepper motor Fs2020

#2 Post by Ralph » Sun Apr 11, 2021 9:16 am

The RPM from FS2020 isn't an array, so you have to remove the [1]

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests