Rotorcraft Corner

You can talk about anything flight (simulation) related here

Moderators: russ, Ralph

Message
Author
User avatar
Sling
Posts: 5239
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Rotorcraft Corner

#21 Post by Sling »

Ralph wrote: Wed Apr 10, 2019 5:15 pm Depends on what you're aiming for. If you want to make the autopilot system yourself, then you're up for a challenge :) I still want to try something with a PID system in Lua, but it is very complex I'm afraid.

If you just want to control the buttons that are already in the flight model, then it's quite easy.
I can agree with that having played with PID in the past. The tuning is the bit I found tricky. How much of each element to get the desired result.

Hopefully the Heli already has the system modelled and will be a simple instrument for the pilot interaction only.

Tony

SimPassion
Posts: 5339
Joined: Thu Jul 27, 2017 12:22 am

Re: Rotorcraft Corner

#22 Post by SimPassion »

What's a nice detailed and interesting paper on K-MAX concept and solution choices :

https://www.heli-archive.ch/en/helicopt ... 1200-k-max


Image


Image

User avatar
jph
Posts: 2856
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Rotorcraft Corner

#23 Post by jph »

I have never had any issue in Arduino IDE with PID control. I see no reason why LUA can be more of an issue - yes, the tuning is often time consuming but not too bad if you understand what is happening,

From our friendly CGPT -
Here's a simple example of a PID (Proportional-Integral-Derivative) controller implemented in Lua. Please note that Lua doesn't have built-in support for PID controllers, so you'll need to implement the control logic yourself. This example assumes that you have access to functions for reading the current state and applying a control output. In this case, I've used readSensor() to get the current state and applyOutput(output) to apply the control output.

Code: Select all

-- PID Controller Parameters
local kp = 0.5  -- Proportional gain
local ki = 0.1  -- Integral gain
local kd = 0.2  -- Derivative gain

-- PID Controller Variables
local setpoint = 100  -- Desired setpoint
local integral = 0
local lastError = 0

-- Sample time (adjust as needed)
local dt = 0.1

-- Main control loop
function pidControl()
    -- Read current state
    local current = readSensor()

    -- Calculate error
    local error = setpoint - current

    -- Calculate integral and derivative terms
    integral = integral + error * dt
    local derivative = (error - lastError) / dt

    -- Calculate control output
    local output = kp * error + ki * integral + kd * derivative

    -- Apply control output
    applyOutput(output)

    -- Update last error for the next iteration
    lastError = error
end

-- Example functions for simulation purposes
function readSensor()
    -- Simulated sensor reading (replace with actual sensor reading)
    return math.random(80, 120)
end

function applyOutput(output)
    -- Simulated actuator output (replace with actual actuator control)
    print("Applying output:", output)
end

-- Main loop (replace with your actual control loop)
for i = 1, 10 do
    pidControl()
    os.execute("sleep " .. dt)  -- Simulate a time delay (remove in actual implementation)
end
This example is a basic template, and you may need to adjust the parameters (kp, ki, kd) and other aspects of the code based on your specific system and requirements. Additionally, replace the readSensor() and applyOutput(output) functions with the actual functions to read sensor data and apply control output in your system.
Joe. CISSP, MSc.

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

Re: Rotorcraft Corner

#24 Post by Ralph »

A while ago I tried to come up with a script, with the help of Google Bard, to make a helicopter stay at the same altitude.
But it is a spiders web you get tangled in :) There are so many factors to take into account. Engine RPM, rotor RPM, torque, temperatures, slowly increasing vertical speed and not too much vertical speed, etc...

Post Reply