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 Simtools does not send a new signal after 1 minute of operation.

Discussion in 'SimTools DIY Version' started by Luu Vy, Jul 15, 2025 at 03:19.

  1. Luu Vy

    Luu Vy New Member

    Joined:
    Jun 11, 2025
    Messages:
    2
    Balance:
    12Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    I have a 2 dof simulator project using Simtools to send signals to Arduino but when playing or testing in output testing, the signal can only be sent for about 1 minute then simtools does not send any new signals to Arduino anymore, but when I check the LCD displaying the Pitch, Roll, etc. values, Arduino is still connected but all data freezes at the last values it received before stopping.
  2. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,602
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    151,269Coins
    Ratings:
    +11,031 / 56 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Can you please specify what code you are using with the Arduino.
  3. Luu Vy

    Luu Vy New Member

    Joined:
    Jun 11, 2025
    Messages:
    2
    Balance:
    12Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF

    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>
    #include <PID_v1.h>


    #define MP1 10 // PWM CW
    #define MP2 11 // PWM CCW
    #define ML1 6 // PWM CW
    #define ML2 9 // PWM CCW


    #define POT_R A0
    #define POT_L A1


    char buffer_data = 0;
    int buffercount = -1;
    byte commandbuffer[7] = {0};


    int pitch = 0, sway = 0, roll = 0;
    double err_L, err_R, err_sway, err_roll, err_pitch;
    double motor_R = 100;
    double motor_L = 100;

    // -------------------- LCD ------------------------------
    LiquidCrystal_I2C lcd(0x27,20,4);

    // -------------------- PID ------------------------------
    double inputR, outputR, setpointR;
    double input, output, setpoint;
    double kp = 2.8, ki = 20 , kd = 0;

    PID pidRight(&inputR, &outputR, &setpointR, kp, ki, kd, DIRECT);
    PID pidL(&input, &output, &setpoint, kp, ki, kd, DIRECT);
    void setup() {
    Serial.begin(115200);

    lcd.init();
    lcd.backlight();
    lcd.setCursor(0,0);
    pinMode(POT_R, INPUT);
    pinMode(MP1, OUTPUT);
    pinMode(MP2, OUTPUT);
    pinMode(POT_L, INPUT);
    pinMode(ML1, OUTPUT);
    pinMode(ML2, OUTPUT);
    pidL.SetMode(AUTOMATIC);
    pidL.SetSampleTime(10);
    pidL.SetOutputLimits(-255, 255);
    pidRight.SetMode(AUTOMATIC);
    pidRight.SetSampleTime(10);
    pidRight.SetOutputLimits(-255, 255);


    }

    void loop(){
    readSimTools();
    process_signal();
    MotorLeft();
    MotorRight();
    showLCD();

    }


    void readSimTools()

    {
    while(Serial.available())
    {
    if(buffercount==-1)
    {
    buffer_data = Serial.read();
    if(buffer_data =='S')
    {// Start game
    buffercount=-1;
    }
    else if(buffer_data =='E')
    { //End game
    buffercount=-1;
    }
    else if(buffer_data =='P')
    { //"P" is the marquer. If we read P, the next data is pitch

    buffercount=0;
    }
    }
    else // if(buffercount>=0)
    {
    buffer_data = Serial.read();
    commandbuffer[buffercount]=buffer_data; // The first value next to "P" is saved in commandbuffer in the place "buffercount"
    buffercount++;
    if(buffercount > 6)
    {
    if(commandbuffer[6]=='C') // If the third data is "C", then commandbuffer is full, we can use it
    {
    pitch=(commandbuffer[0])*256+commandbuffer[1];
    sway=(commandbuffer[2])*256+commandbuffer[3];
    roll=(commandbuffer[4])*256+commandbuffer[5];
    //ma
    sway=map(sway,0,1023,0,200);
    pitch=map(pitch,0,1023,0,200);
    roll=map(roll,0,1023,0,200);
    }
    buffercount=-1; // Re-initialize buffercount.
    }
    }
    }
    }

    void process_signal()
    {
    err_pitch = pitch-100; //pitch = len doc
    err_sway = sway-100; //sway = trai phai
    err_roll = roll-100; //roll = xoay vong
    //truyen dong co
    err_R= 2*err_pitch - 3*err_sway + err_roll;
    err_L= 2*err_pitch + 3*err_sway - err_roll;
    motor_R=100 + err_R;
    motor_L=100 + err_L;


    if(motor_R>160) motor_R=160;
    else if(motor_R<40) motor_R=40;
    if(motor_L>160) motor_L=160;
    else if(motor_L<40) motor_L=40;


    }




    void MotorLeft(){
    int rawPotL = analogRead(POT_L);
    input = map(rawPotL, 0, 1023, 0, 360);
    setpoint = motor_L;
    pidL.Compute();

    if(output > 10){
    analogWrite(MP1, output);
    analogWrite(MP2, 0);

    } else if(output < -10){

    analogWrite(MP1, 0);
    analogWrite(MP2, abs(output));

    } else {
    analogWrite(MP1, 0);
    analogWrite(MP2, 0);
    }
    }


    void MotorRight(){
    int rawPotR = analogRead(POT_R);
    inputR = map(rawPotR, 0, 1023, 0, 360);
    setpointR = motor_R;
    pidRight.Compute();

    if(outputR > 10){
    analogWrite(ML1, outputR);
    analogWrite(ML2, 0);

    } else if(outputR < -10){
    analogWrite(ML1, 0);
    analogWrite(ML2, abs(outputR));

    } else {
    analogWrite(ML1, 0);
    analogWrite(ML2, 0);
    }
    }

    // =========== 3. Hiển thị LCD =========================
    void showLCD(){
    lcd.setCursor(0,0);
    lcd.print("P:"); lcd.print(pitch); lcd.print(" S:"); lcd.print(sway);
    lcd.setCursor(0,1);
    lcd.print("R:"); lcd.print(roll); lcd.print(" Pot:"); lcd.print((int)inputR);lcd.print("/");
    lcd.setCursor(0,2);
    lcd.print("SP:"); lcd.print((int)setpointR);lcd.print("/"); lcd.print(" "); lcd.print((int)outputR);lcd.print("/");
    lcd.setCursor(0,3);
    lcd.print("MR:"); lcd.print(analogRead((int)POT_R)); lcd.print(" ML:"); lcd.print(analogRead((int)POT_L));

    Serial.print(setpointR);
    Serial.print(" ");
    Serial.print(inputR);
    Serial.print(" ");
    Serial.println(outputR);
    }
  4. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,602
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    151,269Coins
    Ratings:
    +11,031 / 56 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK