Jump to content

DCS-BIOS: Potentiometer stutter


Tekkx

Recommended Posts

After a long time I found some spare to continue the work on my cockpit parts. I'm still on the SAS-Panel.

 

Just as it looked like it should work, I encountered a new problem: TRIM-pot stutters!

It's a special pot with a detention at center position, it feels very well and it was not some cheap.

 

The matter is, it sends a continuous data stream to DCS, except on both end positions.

 

BTW: Thank you, Ian, for the latest version of dcs-library 0.2.6. Looks (out from my actual position) like any connection problems of the past will stay there: In the Past. Great work. Thank you.

 

Search and Read this forum regard stutter brought nothing useful out. So I sat down here and raped Ians library. Before I go to the testbed and brick my system I want to show my thoughts here to discuss them: (There is a close-to-100%-chance I haven't noticed some side effects)

 

Here's my version of Potentiometers.h

#ifndef __DCSBIOS_POTS_H
#define __DCSBIOS_POTS_H

#include "Arduino.h"
#include "PollingInput.h"

namespace DcsBios {

class Potentiometer : PollingInput {
	private:
		void pollInput() {
			unsigned int state = map(analogRead(pin_), 0, 1023, 0, 65535);
			// if (state != lastState_) { // original line
                               // replaced by following two lines
			int valueChange = abs(state - lastState_); // declares absolut change	
			if (valueChange > 500) { // sends message just if Pot has really changed its value (500 is just shot from the hip, maybe much less will do the job) 
				char buf[6];
				utoa(state, buf, 10);
				if (sendDcsBiosMessage(msg_, buf))
					lastState_ = state;
			}
		}
		char* msg_;
		char pin_;
		unsigned int lastState_;
	public:
		Potentiometer(char* msg, char pin) {
			msg_ = msg;
			pin_ = pin;
			pinMode(pin_, INPUT);
			lastState_ = map(analogRead(pin_), 0, 1023, 0, 65535);
		}
};

}

#endif

 

Feel free to bash or/and improve my thoughts.

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Link to comment
Share on other sites

You should update your version of the Arduino library. Starting with v0.2.10 (v0.2.11 is the current one), the Potentiometer class uses an EWMA filter and a threshold.

 

If the default values (which I determined experimentally with three random old pots from my junk bin) do not work well for you, you can use the PotentiometerEWMA class directly:

 

DcsBios::PotentiometerEWMA<pollInterval, hysteresis, ewma_divisor> instanceName("COMMAND", PIN_NUMBER);

 

The defaults for pollInterval, hysteresis and ewma_divisor are 5 (milliseconds), 128 and 5. These are the ones you get if you just use the plain Potentiometer class.

 

The pollInterval is the amount of milliseconds between polls.

 

Any changes that are less than the hysteresis value are not sent to the PC. This value should be a multiple of 64, because a 16-bit value is reported to DCS (and checked against the hysteresis value) but the ADC is only 10 bit (65536 / 1024 = 64). The default hysteresis value of 128 gives a final resolution of about 65536 / 128 = 512 steps, which should still be enough to control a dial with a 360 degree scale. For something simple like a volume knob, the hysteresis can be increased to 256 or 512 if necessary.

 

The ewma_divisor value determines the "dampening". Increasing this value will mitigate stutter but it will also increase the time the pot takes to respond.

 

PS: Sorry for the late answer, I have been busy applying for jobs.

Link to comment
Share on other sites

Ian;3215837']You should update your version of the Arduino library. Starting with v0.2.10 (v0.2.11 is the current one), the Potentiometer class uses an EWMA filter and a threshold.

 

...

 

PS: Sorry for the late answer, I have been busy applying for jobs.

 

Oh. Dammit. I took a closer look and found out, I installed v0.2.11 already, but I unzipped it not yet. So I found at my storage just this old directory. :music_whistling:

Ergo my laudatio is regarding 0.2.11 and dcs-bios-v0.5.5 :thumbup:

 

I will modify my code tomorrow. :)

 

And: You aren't late!

Good luck for your applications.

 

Edit: While I opened this thread and complained about jitter, the compiled and uploaded version on the used NANO has been at least six months old and still at v0.2.6. Updating with the latest library solved the problem well (even with plain Potentiometer class) :)

 

BTW this tells me, I (we) have to have a closer look to new updates. This should be standard procedure, as you (Ian) put a lot of work and knowledge in it. Shame on me!


Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Link to comment
Share on other sites

Now has risen the next problem (as usual): As my Pot has a detention at center (while the physical center isn't equal to the electrical center) I have to add some kind of Trim-(of the TRIM)-feature. If the TRIM pot (due to the retention point) isn't at precise center position, TAKEOFF TRIM doesn't work.

I think about to add a second pot as a trimmer to evoke a slight shifting of the electrical center to match the mechanical center.

I have no adequate hardware available, but a dry calculating experiment shows, a Threaded Potentiometer (Trimmer) with about (or some more) 2 MOhm (soldered parallel to all 3 pins of the 10k-Pot) should do the job.

 

Edit (few days later): A 2MOhm 10turn-Trim-Potentiometer has been delivered (to prevent mistakes I'll call it from now "Shift-Pot" or "Center-Shift-Pot").

 

I soldered it (quick and dirty) Pin-on-Pin on the YAW-TRIM Pot: As I supposed: I can shift the center of the YAW-TRIM as I want. The Range of the TRIM-Pot (0 to 65534) is the same as before.

 

The tuning procedure is as follows:

- Establish a working RS-485-System with running connect-serial-port.cmd-window (I use the ASK-variant, which is very reliable - Thank You, Ian). DCS is in PAUSE or even not started.

- Calculate the center of the pot (65534 / 2) (mental or use a pocket calculator) ;)

- Bring YAW_TRIM to the mechanical center

- Turn Center-Shift-Pot (while watching your command-window) until you reach the calculated value (or a value close to this).

That's it.

 

To move the center I have to do some (at least one or two) turns at the Shift-Pot. Very convinient and precise. No Breath Holding while shifting is needed. :)

Success!

 

Roll-Out-Version of this Light-Board will have this Shift-Pot on board as a standard feature and will be ready tuned.

 

Look at the pic: This is what I describe as "quick-n-dirty" :)

For a better view I unplugged the Backlight (3pin connector, labeled "PWM in", which comes from the Interface-Control-Board).

IMG_20170813_194949.thumb.jpg.fbbbed4655b9b683cbdbcc6a22103538.jpg


Edited by Tekkx

Manual for my version of RS485-Hardware, contact: tekkx@dresi.de

Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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