1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Question preset load and gain for belt tension ?

Discussion in 'Electronic and hardware generally' started by harrie, Mar 19, 2024.

  1. harrie

    harrie Member

    Joined:
    Oct 1, 2022
    Messages:
    48
    Location:
    coevorden
    Balance:
    221Coins
    Ratings:
    +20 / 0 / -0
    My Motion Simulator:
    Arduino, 4DOF
    i did make lebois seat belt tensior with the 24 volt dc motor . i got 2 arduinos driving for now 5 motors . seat belt is onto arduino nr 2 axis 2b with a potmeter 10 k . working nice but would like to ad the function for preload and gain settings ore a switch for of/on . i got a arduino sketch but it is for servo motors .
    what i wanting to do
    1 . preload setting to adjust the start position of the tension with a potmeter
    2 . gain setting to adjust when playing . the force that is pulled with a potmeter adjustable when playing in game
    3 . switch to turn of/on the complete tension motion .
    4. how to set this up? adding a nr3 arduino card ? with a skech onto it only for belt tension ? is it possible in simtools to setup a motion gain with a potmeter/ remote keyboard keys ? . turnig in game playing a potmeter/keyboardkey so all axis motion gain are getting more ore less ?

    i got lebois arduino seatbelt tension skech but it is for servo motors ? flypt setup ? could this make working for simtools setup ? lebois smartbox for belt

    // Licence CC BY NC SA
    // www.lebois-racing.fr/en
    // Use native USB

    //#define EcoMode //The servo driver will be turned down when their is no torque to apply.

    #define NATIVEUSBPORT //it's not reliable when using the programming port

    int TorqueTarget = 0;
    int gain = 4095;
    int preload = 1;

    int EnablePin = A0;

    void setup() {
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);
    enableServo();
    delay(3000); //safetys delay to flash the board

    #ifdef NATIVEUSBPORT
    SerialUSB.begin(115200); //To communicate with FlyPT. In FlyPT, put that number in "Serial speed".
    #else
    Serial.begin(115200);
    #endif

    analogWriteResolution(12); //if you have an error here, it's because you didn't select the right Arduino
    analogReadResolution(12);
    pinMode(DAC0, OUTPUT); //to avoid wiring problems, both pins are used
    pinMode(DAC1, OUTPUT);
    analogWrite(DAC0, 0);
    analogWrite(DAC1, 0);
    digitalWrite(12, HIGH);
    digitalWrite(13, HIGH);
    }


    void loop() {
    SerialReaderB();

    int target = min(preload + TorqueTarget * gain / 4095, 4095);

    #ifdef EcoMode
    if (TorqueTarget == 0 && gain == 0) {
    disableServo();
    } else {
    enableServo();
    #ifdef PotentiometerMode
    analogWrite(DAC0, target);
    analogWrite(DAC1, target);
    #else
    analogWrite(DAC0, target);
    analogWrite(DAC1, target);
    #endif
    }
    #else
    analogWrite(DAC0, target);
    analogWrite(DAC1, target);
    #endif
    }

    void SerialReaderB() {
    int rawValue = 0;
    while (SerialUSB.available()) { //To communicate with FlyPT. In FlyPT, put that number in "Serial speed".
    char incomingChar = SerialUSB.read();

    if (incomingChar == 'A') {
    enableServo();
    } else if (incomingChar == 'B') {
    if (SerialUSB.available() >= 2) {
    uint8_t valueMSB = SerialUSB.read();
    uint8_t valueLSB = SerialUSB.read();
    TorqueTarget = (uint16_t)valueMSB << 8 | (uint16_t)valueLSB;
    }
    } else if (incomingChar == 'C') {
    disableServo();
    }
    }
    }

    void enableServo() {
    digitalWrite(EnablePin, LOW);
    }
    void disableServo() {
    digitalWrite(EnablePin, HIGH);
    analogWrite(DAC0, 0);
    analogWrite(DAC1, 0);
    }