Lua script for custom mixer is not working

Hi,
I am new to lua scripting and using pixhawk 6x and trying to write a custom mixer. I am using an example script. I have put example lua script inside an update function. But it is not running, and I get pre-arm failure “PreArm: Motors: Check frame class and type”. The script is as follows:

function update()
    MotorsMatrix:add_motor_raw(0, -1, 0, 1, 2)
    MotorsMatrix:add_motor_raw(1, 1, 0, 1, 4)
    MotorsMatrix:add_motor_raw(2, 0, 1, -1, 1)
    MotorsMatrix:add_motor_raw(3, 0, -1, -1, 3)

    assert(MotorsMatrix:init(4), "Failed to init MotorsMatrix")

    motors:set_frame_string("scripting plus example")
end

return update, 1000

I have enabled the SCR_ENABLE parameter and have set the FRAME_CLASS to Scripting matrix. But I am not getting any pwm data out from the servo pins. If I use Quad FRAME_CLASS I am getting the pwm pulses in dso. Is there a way to check if script is loaded and running?

Can anyone please help me with this?

Thanks,
Sayan

Just to add one more thind that I have turned off BRD_SAFETY checks for getting the pwm in pins.

I would try not calling add_motor_raw multiple times.

Thanks for the reply, Lupus! But I took this example script from ardupilot examples located under AP_Scripting library. Please let me know if you have any better solution for this.

Please post a log file. With LOG_DISARMED set to 1

Thanks, I could make it run by removing the fast task in copter for custom controller. I do not know why it is not running with the custom controller code. Do you know any reasons for this? Is the controller code taking much more time and memory that scripts are not running?

It is working in SITL with the custom controller.

Please post a log file.

Got it working for now. I was creating another thread with higher priority that the lua script priority which was preventing it from running.