Another Nasal issue

Everything in connection with developing aircraft for FlightGear
User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 3:53 am

I have an old Luftwaffe floatplane that uses YAsim that I patched together a simple little nasal that simulates the idle shut-off of a diesel engine by pulling the throttle to the bottom stop cutting the fuel off. I would like some help making a 'reset' for this function that turns it off completely whenever the floats are without weight or compression.

the code I have so far is this..

newdiesel-idle.nas

Code: Select all

#### Set Diesel idle level/cutoff with throttle position and mixture with altitude.

var pos_throttle   = props.globals.getNode("/controls/engines/engine[0]/throttle");
var pos_mixture   = props.globals.getNode("/controls/engines/engine[0]/mixture");


 setlistener("/controls/engines/engine[0]/throttle", func {
   var throttle = pos_throttle.getValue();
   if (throttle >= 0.05)   { pos_mixture.setValue(1.0); return 0; }
   if (throttle > 0)   { pos_mixture.setValue(0.068); return 0; }
   pos_mixture.setValue(0);
 });

#### Set mixture to alt level
  setlistener("instrumentation/altimeter/pressure-alt-ft", func {
   var alt = "instrumentation/altimeter/pressure-alt-ft";
   var mixture = "controls/engines/engine[0]/mixture";
   if (getprop(alt) > 15000) {
      setprop (mixture, 0.69);
      }
      if (getprop(alt) < 15000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) > 10000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) < 10000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) > 5000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) < 5000) {
      setprop (mixture, 0.94);
      }
      if (getprop(alt) > 3000) {
      setprop (mixture, 0.94);
      }

var MixtureInit = func {

  settimer(env_effects, 2);
  settimer(mixture_loop, 3);            # Delay startup a bit to allow things to initialize


It's triggering a console complaint since I rewrote it. I'm wanting to initialize a stop to the first function and toggle on the second mixture change with altitude when the weight on the main float gear [1] is released when it's airborne. I don't know the syntax to write in to change which function changes the mixture's state.

Could someone help please?

123apple
Posts: 81
Joined: Fri Jul 15, 2016 1:17 pm

Re: Another Nasal issue

Postby 123apple » Thu Oct 05, 2017 9:59 am

Could you please post the exact error message? Thanks.

You *may* want to use
if () {
} else {

instead of a lot of

if () {
}

statements.

User avatar
IAHM-COL
Posts: 5609
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: Another Nasal issue

Postby IAHM-COL » Thu Oct 05, 2017 11:29 am

123apple wrote:Could you please post the exact error message? Thanks.

You *may* want to use
if () {
} else {

instead of a lot of

if () {
}

statements.



Code: Select all

if () {
}


this is usually a better coding syntax, somewhere else. I dont know if it applies to nasal, but I'd speculate even in nasal this is preferable over nested ifs with else
R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it? Probably not, because if they don’t recognise their freedoms, they’ll let their freedoms fall

User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Re: Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 2:33 pm

The error is "nasal parse error in C:/../../../../Nasal/newdiesel-idle.nas line 44" there's another console complaint below it that I don't think is related

Hmmm I think I need to describe better what I want to achieve with this Nasal?

Maybe a function flow chart? :?:

I will try the else statements, but, a lot of this function is riding on the Weight on Wheels property acting as a toggle between the two mixture control states. Unfortunately I'm not clear at all on how to write the syntax for the WOW state change. The Diesel idle nasal is working great. But I would want the idle function to work as well on a higher altitude lake.
Last edited by LesterBoffo on Thu Oct 05, 2017 2:40 pm, edited 1 time in total.

User avatar
IAHM-COL
Posts: 5609
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: Another Nasal issue

Postby IAHM-COL » Thu Oct 05, 2017 2:39 pm

it would be helpful to see the error log. it may give us hints
R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it? Probably not, because if they don’t recognise their freedoms, they’ll let their freedoms fall

User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Re: Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 2:46 pm

yeah I just edited the message above to include the console warning.

To add the WOW state change, would I have to declare the new state function like the var-throttle or mixture, sorta like

Code: Select all

var pos_gear   = props.globals.getNode("/gear/gear[1]extend");


:?:

User avatar
IAHM-COL
Posts: 5609
Joined: Sat Sep 12, 2015 3:43 pm
Location: Homey, NV (KXTA) - U.S.A
Contact:

Re: Another Nasal issue

Postby IAHM-COL » Thu Oct 05, 2017 3:41 pm

from your error saying the problem is parsing at line 44 I pressume the only problem you have is missing a proper closure for function MixtureInit

In other words, line 44 should be "}"
like in

Code: Select all

#lines 40 to 44 shown below
var MixtureInit = func {

  settimer(env_effects, 2);
  settimer(mixture_loop, 3); # Delay startup a bit to allow things to initialize
}


Last line in above code seems missing in yours
R.M.S.
If we gave everybody in the World free software today, but we failed to teach them about the four freedoms, five years from now, would they still have it? Probably not, because if they don’t recognise their freedoms, they’ll let their freedoms fall

User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Re: Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 4:25 pm

OK, actually the "}" is present at line 44, I apparently didn't include it in the code cut and paste. :oops:

Code: Select all

#### Set Diesel idle level/cutoff with throttle position and mixture with altitude.

var pos_throttle   = props.globals.getNode("/controls/engines/engine[0]/throttle");
var pos_mixture   = props.globals.getNode("/controls/engines/engine[0]/mixture");
var pos_gear   = props.globals.getNode("/gears/gears[1]/wow");


 setlistener("/controls/engines/engine[0]/throttle", func {
   var throttle = pos_throttle.getValue();
   if (throttle >= 0.05)   { pos_mixture.setValue(1.0); return 0; }
   if (throttle > 0)   { pos_mixture.setValue(0.068); return 0; }
   pos_mixture.setValue(0);
 });

#### Set mixture to alt level
  setlistener("/gears/gears[1]/wow", func {
   var alt = "instrumentation/altimeter/pressure-alt-ft";
   var mixture = "controls/engines/engine[0]/mixture";
   if (getprop(alt) > 15000) {
      setprop (mixture, 0.69);
      }
      if (getprop(alt) < 15000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) > 10000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) < 10000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) > 5000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) < 5000) {
      setprop (mixture, 0.94);
      }
      if (getprop(alt) > 3000) {
      setprop (mixture, 0.94);
      }

var MixtureInit = func {

  settimer(env_effects, 2);
  settimer(mixture_loop, 3);            # Delay startup a bit to allow things to initialize
}


Any thoughts on the state change for toggling the variable controlling the mixture?

P.S. also noticed that because the state change of the gear[1] wow is binary, it's context is as a true-false 'boolean'. How does one code this change in a nasal variable?

User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Re: Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 5:13 pm

I have to admit I'm completely lost here as a non programmer,

the work function flow would be thusly..

If gear[1] weight (wow) is true, the mixture idle nasal is toggled on.

If the gear weight (wow) is false, the mixture idle nasal is toggled off, and the new mixture function with altitude controlling it is toggled on..

Is this making sense to anyone?

Here's what I've made so far, I don't know how to make an 'and' function statement so that with the gear weight being false the mixture being reinitialized under a new gear control. I could use some guidance here.

Code: Select all

#### Set Diesel idle level/cutoff with throttle position and mixture with altitude.

var pos_throttle   = props.globals.getNode("/controls/engines/engine[0]/throttle");
var pos_mixture   = props.globals.getNode("/controls/engines/engine[0]/mixture");
var pos_gear   = props.globals.getNode("/gears/gears[1]/wow");


 setlistener("/controls/engines/engine[0]/throttle", func {
   var throttle = pos_throttle.getValue();
   if (throttle >= 0.05)   { pos_mixture.setValue(1.0); return 0; }
   if (throttle > 0)   { pos_mixture.setValue(0.068); return 0; }
   pos_mixture.setValue(0);
 });

#### Set mixture to alt level
  setlistener("/gears/gears[1]/wow", func {
    var gear = pos_gear.getValue();
     if (gear = false)  { pos_gear.setValue(1.0); return 0;
      if (gear = true)  { pos_mixture.setValue(1.0); return 0;
   var alt = "instrumentation/altimeter/pressure-alt-ft"; }
   var mixture = "controls/engines/engine[0]/mixture"; }
   if (getprop(alt) > 15000) {
      setprop (mixture, 0.69);
      }
      if (getprop(alt) < 15000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) > 10000) {
      setprop (mixture, 0.78);
      }
   if (getprop(alt) < 10000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) > 5000) {
      setprop (mixture, 0.85);
      }
   if (getprop(alt) < 5000) {
      setprop (mixture, 0.94);
      }
      if (getprop(alt) > 3000) {
      setprop (mixture, 0.94);
      }

var MixtureInit = func {

  settimer(env_effects, 2);
  settimer(mixture_loop, 3);            # Delay startup a bit to allow things to initialize
}

User avatar
LesterBoffo
Posts: 747
Joined: Tue Sep 15, 2015 3:58 am
Location: Beautiful sunny, KOTH

Re: Another Nasal issue

Postby LesterBoffo » Thu Oct 05, 2017 6:23 pm

OK, the last coding change was a step in the right direction, I now have the mixture set back to default control, once the gear wow is set to false, and I can control it again with the 'm' and 'shift+m' keys, now to get the altitude to preset the mixture..


Return to “Aircraft Development”

Who is online

Users browsing this forum: No registered users and 1 guest