SHWotever / SimHub

Multi sim dashboard, bass shaker driver, ....
http://www.simhubdash.com/
808 stars 98 forks source link

RC Servo/ESC Output #1619

Open jager07 opened 6 months ago

jager07 commented 6 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when I use an Electronic Speed Controller to control brushless fans and have to edit the SHFansPWM to support a Servo output using timer2 to avoid conflicts… have it working but any new compilation with additional features requires my edits.

Describe the solution you'd like Allowing ServoPWM outputs, being able to support say a min, max output, driving a traditional RC PPM Servo signal.

Describe alternatives you've considered I mention above I’ve edited the SHFansPWM to output a servo PPM instead of PWM, using servotimer2.

Additional context Useful for output say servo position based on speed or connecting to a ESC for brushless fan control, I use these to drive powerful ducted fans to provide a lot of airflow!

SHWotever commented 6 months ago

I'm sorry I've never tested such setup can you link some wiring and products link to get an overview of such setup and evaluate how relevant they are (price/feature) ?

jager07 commented 6 months ago

Hi,RC servo control via Arduino is just using a servo library, can then control an electronic speed controller as well.I can send the changes I made in the SHFanPWM module that replaces the PEM output with the servo pulse position pulses, it works great to control an brushless high sped fan.Cheers Jason  https://youtu.be/qOzE5F5vFGs?si=YZpluBPTd--NQTxVOn 20 May 2024, at 7:31 PM, Wotever @.***> wrote: I'm sorry I've never tested such setup can you link some wiring and products link to get an overview of such setup and evaluate how relevant they are (price/feature) ?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

SHWotever commented 6 months ago

Would you have some links to actual hardware ? I've only found small ones (65mm) when I looked, which are probably extremely noisy. I really need to evaluate the factual interest of it ;)(price/features/advantages/downsides)

jager07 commented 6 months ago

Hi,Sorry for the delay, check out this flight sim gauge using servos, you could use same for simhub for temp, fuel etc… also the other application is controlling electronic speed controllers for brushless motors, I use two ducted fans for my wind which blows about 10x more than a normal fan…Dual 2" gauge for Flight Simulator by alvaroaleathingiverse.comServos are available form reliable manufacturers like Savox and Spectrum, Hitect, all are various sizes, low cost and quite.Most flight sim software like Simhub allows for servo connection/support for gauges.Really depends on the sim racing community to support it, in flight sim many do because gauges are so integral to the sim.Cheers JasonOn 20 May 2024, at 8:41 PM, Wotever @.***> wrote: Would you have some links to actual hardware ? I've only found small ones (65mm) when I looked, which are probably extremely noisy. I really need to evaluate the factual interest of it ;)(price/features/advantages/downsides)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

VHF-ACADDICT commented 2 months ago

Hi, i’m also searching how to use an esc/brushless/propeller (i have plenty to test…) for my windsim, is it possible to share your modified SHFansPWM here please ? Thx !

jager07 commented 2 months ago

See attached, I use this file to replace the original, this replaces the PWM with a Servo compatible output. The only issue was you have to use TimerOne to ensure no conflict with timers (from memory I think this was correct…)

Anyway, it worked for Servo control and ESC control and I use it for my ducted fan wind simulator that pushes an extreme amount of air and sounds like jet when driving,..

I hope you make sense of what i have added. You’ll need the libraries;

include

include

Cheers, Jason ##############

ifndef __SHSHAKEITPWMFANS_H__

define __SHSHAKEITPWMFANS_H__

include

include "SHShakeitBase.h"

include

include

ServoTimer2 Duct_Fan[4];

class SHShakeitPWMFans : public SHShakeitBase { private:

byte pins[4]; byte mins[4]; byte maxs[4]; int relays[4]; unsigned long offSince[4]; unsigned long offDelay[4] = { 2000,2000,2000,2000 }; byte reverseRelayLogic[4] = { 0,0,0,0 }; byte enabledOutputs; public: uint8_t motorCount() { return enabledOutputs; }

String providerName() { return "PWMFan"; }

void safetyStop() override { SHShakeitBase::safetyStop();

for (int i = 0; i < enabledOutputs; i++) {
  if (relays[i] > 0) {
    SetRelayState(i, false);
  }
}

}

void begin(byte pEnabledOutputs, byte pPin01, byte pPin02, byte pPin03, byte pPin04) { Timer1.initialize(40);

pins[0] = pPin01;
pins[1] = pPin02;
pins[2] = pPin03;
pins[3] = pPin04;
enabledOutputs = pEnabledOutputs;
for (int i = 0; i < pEnabledOutputs; i++) {
  Duct_Fan[i].attach(pins[i]);
  Duct_Fan[i].write(750);
}

}

void setMin(byte pMin01, byte pMin02, byte pMin03, byte pMin04) { mins[0] = pMin01; mins[1] = pMin02; mins[2] = pMin03; mins[3] = pMin04; }

void setMax(byte pMax01, byte pMax02, byte pMax03, byte pMax04) { maxs[0] = pMax01; maxs[1] = pMax02; maxs[2] = pMax03; maxs[3] = pMax04; }

void setRelays( int r01, int r02, int r03, int r04, int d01, int d02, int d03, int d04, bool l01, bool l02, bool l03, bool l04) { relays[0] = r01; relays[1] = r02; relays[2] = r03; relays[3] = r04;

offDelay[0] = d01;
offDelay[1] = d02;
offDelay[2] = d03;
offDelay[3] = d04;

reverseRelayLogic[0] = l01;
reverseRelayLogic[1] = l02;
reverseRelayLogic[2] = l03;
reverseRelayLogic[3] = l04;

for (int i = 0; i < enabledOutputs; i++) {
  if (relays[i] > 0) {
    pinMode(relays[i], OUTPUT);
    SetRelayState(i, false);
  }
  offSince[i] = 0;
}

}

protected:

void SetRelayState(int relayIdx, bool state) { int relayPin = relays[relayIdx]; if (relayPin > 0) {

  if (!state) {
    digitalWrite(relayPin, reverseRelayLogic[relayIdx] ? HIGH : LOW);
  }
  else {
    digitalWrite(relayPin, reverseRelayLogic[relayIdx] ? LOW : HIGH);
  }
}

}

void setMotorOutput(uint8_t motorIdx, uint8_t value) { double value2 = value; if (value2 < mins[motorIdx]) { value2 = 0; } else { value2 = (value2) / 255.0 * (double)maxs[motorIdx]; }

int esc = map(int(value2),0,255,750,2250); // 750 2250

Duct_Fan[motorIdx].write(esc);

if (relays[motorIdx] > 0) {
  if (value2 > 0) {
    SetRelayState(motorIdx, true);
    offSince[motorIdx] = 0;
  }
  else {
    if (offSince[motorIdx] == 0) {
      offSince[motorIdx] = millis();
    }

    if ((millis() - offSince[motorIdx]) > offDelay[motorIdx]) {
      SetRelayState(motorIdx, false);
      offSince[motorIdx] = 0;
    }
  }
}

} };

endif

On 10 Sep 2024, at 8:09 pm, VHF-ACADDICT @.***> wrote:

Hi, i’m also searching how to use an esc/brushless/propeller (i have plenty to test…) for my windsim, is it possible to share your modified SHFansPWM here please ? Thx !

— Reply to this email directly, view it on GitHub https://github.com/SHWotever/SimHub/issues/1619#issuecomment-2340301425, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJE4IW2XCESEZ463F4UWBNLZV3D5BAVCNFSM6AAAAABH7HBJ3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBQGMYDCNBSGU. You are receiving this because you authored the thread.

VHF-ACADDICT commented 2 months ago

Thank you, I’ll try later one more time without making a new folder for this, because I’ve experienced some issues while compiling the sketch, mainly about servotimer, at the last attempt the error was a « character that is missing somewhere.