Jump to content

Using IntegerBuffer values in the loop() function


shreddersa

Recommended Posts

The DCS-BIOS documentation says the following about IntegerBuffer:

 

"Sometimes it is more convenient to get rid of the callback function and check the current value yourself from code in the loop() function."

 

This is the code snippet given which provides guidance on the callback:

void onAltMslFtChange(unsigned int newValue) {
   /* your code here */
}
DcsBios::IntegerBuffer altMslFtBuffer(0x0408, 0xffff, 0, onAltMslFtChange);

 

So in this case the callback "onAltMslFtChange" is given and provided a function.

 

How would I call the altMslFtBuffer value in the loop function?

 

As background I would like to run my code in the loop function as I require to use the timer function millis() in the loop to ensure that my force feedback actuator can run a while before re-assessing where it is. (I use the airspeed gauge value for that)

 

Any help appreciated!

Link to comment
Share on other sites

As I recall, "newValue" is set by the call function.

So in the case you mention, "newValue" in the function would be set to the "altMslFtBuffer" number IN the called function.

I also think that you don't need to deal with it in the loop, as it gets called automatically when the value changes.


Edited by No1sonuk
Link to comment
Share on other sites

Try this:

 

Put this in the define part at the start of your code:

unsigned int altMslFtnewValue;

This defines " altMslFtnewValue " as a global variable

 

then this:

void onAltMslFtChange(unsigned int newValue) {
  altMslFtnewValue = newValue;
}
DcsBios::IntegerBuffer altMslFtBuffer(0x0408, 0xffff, 0, onAltMslFtChange);

 

Then use " altMslFtnewValue " in your loop code.

 

Not sure if this would work, but it's what I'd try first.

Link to comment
Share on other sites

Try this:

 

Put this in the define part at the start of your code:

unsigned int altMslFtnewValue;

This defines " altMslFtnewValue " as a global variable

 

then this:

void onAltMslFtChange(unsigned int newValue) {
  altMslFtnewValue = newValue;
}
DcsBios::IntegerBuffer altMslFtBuffer(0x0408, 0xffff, 0, onAltMslFtChange);

 

Then use " altMslFtnewValue " in your loop code.

 

Not sure if this would work, but it's what I'd try first.

 

Thank you! Will give it a try and provide feedback on the result :)

Link to comment
Share on other sites

Solution!

 

No1sonuk and Longuich, (also Ian in a different post, see link below)

Many thanks for pointing me in the right direction. I have used advice from both of you and after much experimentation, headscratching, research and long hours finally came up with the right combination of elements in the code. The actuator now works beautifully, pulling the bungee cords tight to tension the action of the controls. It uses the airspeed reading to move the full range. This is the code snippet employed: (I have posted the full sketch in this post: https://forums.eagle.ru/showthread.php?p=4322727#post4322727

 

// constants won't change:
const long interval = 100;           // interval at which to move the actuator (milliseconds)

void setup() {
 DcsBios::setup();
 pinMode(inApin, OUTPUT);
 pinMode(inBpin, OUTPUT);
 pinMode(pwmpin, OUTPUT);
 pinMode(cspin, INPUT);
 pinMode(actuatorPin, INPUT);
}

void onAirspeedgaugeChange(unsigned int newValue) {
  AirSpeedConvert = newValue; //Read the airspeed value
}

void AirspeedChange() {
    
  int actuatorPosNow = analogRead(actuatorPin);// read the Actuator potentiometer (this will be a value between 132 and 1020 see above) 
  int AIRSPEED = static_cast<int>((AirSpeedConvert/46.17)+132); //see explanation for this factor above, will change for different actuators
   
   if (AIRSPEED > actuatorPosNow+10){   //if AIRSPEED is higher, start forward motion
     digitalWrite(inApin, HIGH); //Direction Forward
     analogWrite(pwmpin, 255); //set PWM speed to max.
     delay(200);
     motorOff();
      }
     
   else if (AIRSPEED < actuatorPosNow-10) { //if AIRSPEED is lower, start Reverse motion
     digitalWrite(inBpin, HIGH); //Direction Reverse
     analogWrite(pwmpin, 255); //set PWM speed to max.
     delay(200);
     motorOff();
     }
     
    else {  //if AIRSPEED is same as actuator position, switch motor off
      motorOff();
     }
     
     if((analogRead(cspin)>CS_THRESHOLD));
     {
       motorOff();
     }     
     
}
DcsBios::IntegerBuffer airspeedgaugeBuffer(0x5436, 0xffff, 0, onAirspeedgaugeChange);

void motorOff()
{
   digitalWrite(inApin, LOW);
   digitalWrite(inBpin, LOW);
   analogWrite(pwmpin, 0);
}

void loop() {
 DcsBios::loop();
 // we will check the satus of airspeed every second
 unsigned long currentMillis = millis();
   if (currentMillis - previousMillis >= interval) { //check if more than 1/10th second has passed
     previousMillis = currentMillis; // if yes, save the last time you moved the actuator
     AirspeedChange(); // and run the Airspeedchange function
   } // else nothing, just carry on..
}

Link to comment
Share on other sites

Any chance you could post pics? I'm quite curious...

 

The design has since been simplified somewhat but this will give you an overview.

https://heritageflightsim.com/2018/10/25/aileron-force-feedback-design/

 

https://heritageflightsim.com/2018/09/27/rudders-a-new-take-on-force-feedback/

 

 

I will also post a video on my channel showing the detail and operation in due course.

https://www.youtube.com/channel/UCpcPJ5Gpc4vvbUc53l-X9Kg

Link to comment
Share on other sites

Nice work.

 

Though I can't understand why you'd build a full cockpit, then go VR where you can't see it properly. :huh:

 

Aha! Great question and I am glad you asked :thumbup:

 

I suspect that part of the reason you asked is that you have not flown DCS World in VR yet? I may be wrong but if you have this should be easier to appreciate.

 

The technical explanation: We are using Augmented Virtuality (AV) to merge the virtual world DCS Mk.IX Spitfire simulator with an accurate real world working cockpit. AV is a subcategory of mixed reality which refers to the merging of real world objects into virtual worlds. As an intermediate case in the virtuality continuum, it refers to predominantly virtual spaces, where physical elements, e.g. physical objects or people, are dynamically integrated into, and can interact with, the virtual world in real time. :smartass:

 

What I want is that you can enter an accurate replica of the Spitfire cockpit, look around you and and interact with the controls. Then when you don the VR headset, the scene washes over you, the cockpit you stepped in to is still there, you can reach out and touch everything you see but you are now in a very real 3D environment, throwing you into a different era or place. The feeling of immersion is incredible. You can look all around and behind you and see the world as if it's really there. Granted, the technology is still young and most (not all!) VR HMD's are still a little grainy, but this is only getting better with time.

 

What inspired me to tackle this project in the first place was the experience of first seeing the Spitfire in VR and the incredibly well made flight model and detail in DCS World. I flew it today for the first time with all the effects (force feedback and Buttkicker) operating (except for the G-seat which I am still developing). The quality of immersion was mind blowing! You are really there..

 

Of course you could easily go the route of a full dome, you would simply add working gauges which is not a huge additional task. In fact, this is what you will experience when you fly the Boultbee Spitfire Simulator (for mucho Sterling!). But this is all in 2 D and in pretty washed out intensity..and you cannot look behind you...where is the immersion in that?

 

Not to mention the cost of such a setup of course.

 

No, give me VR with a real world cockpit combination anyday!

:joystick:

Link to comment
Share on other sites

I guess it would make more sense if you could see your hands...

 

This too is possible. The technology just isn’t quite up to it yet. LeapMotion is actually a very nice reasonably priced solution but not supported by DCS World. I have the VR gloves by VRfree but they are buggy and unreliable in their tracking. My best hope is the work being done by Oculus using their existing built in cameras for hand tracking. Good progress being made there. So yes, that will be good and yes, it’s coming soon! :D

Link to comment
Share on other sites

  • 11 months later...
On 5/11/2020 at 7:54 AM, shreddersa said:

 

This too is possible. The technology just isn’t quite up to it yet. LeapMotion is actually a very nice reasonably priced solution but not supported by DCS World. I have the VR gloves by VRfree but they are buggy and unreliable in their tracking. My best hope is the work being done by Oculus using their existing built in cameras for hand tracking. Good progress being made there. So yes, that will be good and yes, it’s coming soon! 😄

 

We'll be opening a VRfree Topic in this forum to discuss all things related VRfree and DCS. If you have issues with the gloves please get in touch with us. Here is a new video on the new functionality. We think it's never been this good and ED is working on more native support: 

 

 

Link to comment
Share on other sites

AR/XR tech is anticipated to grow in the coming years. HMDs are already available on the professional market, mature consumer units fit for flightsim with a real cockpit is for sure available within 3 years. There arent any technical barriers as the simplest options with a greenscreen backdrop is more or less a solved issue and virtual space partition is making great strides, its all a matter of price and maturity at this point.

 

Especially the option of using a greenscreen backdrop can be expected to come very fast as soon as VR headsets incorporate high quality stereoscopic cameras. Making your cockpit with this in mind is not a bad choice


Edited by Myrsnipe
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...