1. 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 Download Package Now!
  2. 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
  3. 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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Showroom 2 dof (Arduino - motormoster - wiper motor)

Discussion in 'DIY Motion Simulator Projects' started by IRaceSim, Jan 11, 2019.

Tags:
  1. IRaceSim

    IRaceSim Impalone

    Joined:
    Jan 5, 2018
    Messages:
    11
    Occupation:
    Geometra
    Location:
    Teramo
    Balance:
    11Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, SCN5, Arduino
    I present my "sim 2 dof". For my homemade simulator, I chose the iron rods of 35x35mm sp.2mm size for the base and 30x30mm and 20x20 sp.2mm for the upper float. The all welded.

    I will show you step by step my realization.

    P_20160322_194747_1_p.jpg P_20160322_194803_p.jpg P_20160322_194812_1_p.jpg P_20160322_194829_p.jpg


    [​IMG][​IMG]
    [​IMG]
    ______________________________________________________ Chassis
    ______________________________________________________

    The upper part of my frame

    20150429_181147.jpg 20150429_181140 - Copia.jpg
    [​IMG]

    The lower base with adjustable feet.

    20150429_181202.jpg 20150429_181206.jpg
    [​IMG]
    [​IMG]

    The cardan joint used in the assembly of the top and the bottom of the chassis.

    P_20160305_184600_1_p.jpg

    It is very important that the joint prevents rotation of the upper part.

    The result is this

    20150520_185713.jpg

    [​IMG]
    ______________________________________________________
    Electronic and motor
    ______________________________________________________

    The utilized solution to move the frame, are two wiper motors, exactly SMOLKA VALEO 404.458, powered and controlled by motomonster card and Arduino UNO, controlled by 10Kohm linear potentiometers.

    This is the assembly scheme.
    lipide512-wiringdiagram.gif

    I've got all the necessary material on various internet sites.

    Wiper motor - Smolka Valeo 404.458 12V Wiper Motor
    [​IMG]
    Linear pot 10k
    [​IMG]
    Arduino and motomoster shield
    [​IMG]
    Electric cables
    [​IMG]
    power supply 12V 50A
    [​IMG]

    The motomoster can be attached on top of the Arduino. I preferred to make them work parallel, so there is no danger of a short circuit and overheating.

    20141218_220746.jpg
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    Once the boards have been prepared, the motors are mounted on the chassis and the potentiometers are connected.
    For the assembly of the engines I have prepared some special brackets.

    20150429_183104.jpg
    20150429_184805.jpg
    20150518_225652.jpg 20150518_193218.jpg

    I inserted pieces for gaming devices

    20150506_215312.jpg
    20150506_215332.jpg

    Finished with the motor brackets and with the chassis, I proceed with the preparation of the 6mm mechanical shaft to connect the potentiometers. I disassembled the engine, created a mechanical thread which I need to screw the created mechanical shaft.

    20150518_214132.jpg 20150518_214231.jpg 20150518_214249.jpg 20150518_214323.jpg
    20150518_214349.jpg
    20150518_214504.jpg
    I created some potentiometer brackets. A flexible material is recommended

    20150518_214135.jpg

    This is the result

    20150518_193214.jpg

    As you can see, the potentiometer is connected to the transmission shaft by means of a 6mm electrical connector with clamping screws.

    Completed the mechanical and electrical assembly, I continued to load the arduino code on the board. In this operation it is very important not to power the motors, and do not tighten the connection screws between potentiometers and motors, it is sufficient to keep only the arduino board powered.

    I installed the computer program with the card via the USB cable and by selecting the card port (in my case) I entered this code.

    #define BRAKEVCC 0
    #define RV 2 //according to cable at 24/11/2011
    #define FW 1 //according to cable at 24/11/2011
    #define STOP 0
    #define BRAKEGND 3
    #define CS_THRESHOLD 253 //not use :(
    ////////////////////////////////////////////////////////////////////////////////
    #define pwmMin 128;
    #define pwmMax 250;
    #define motLeft 0
    #define motRigth 1
    #define speedPin 10
    #define potL A4
    #define potR A5

    ////////////////////////////////////////////////////////////////////////////////
    // DECLARATIONS
    ////////////////////////////////////////////////////////////////////////////////
    /* VNH2SP30 pin definitions*/
    int inApin[2] = {
    7, 4}; // INA: Clockwise input
    int inBpin[2] = {
    8, 9}; // INB: Counter-clockwise input
    int pwmpin[2] = {
    5, 6}; // PWM input
    int cspin[2] = {
    2, 3}; // CS: Current sense ANALOG input
    int enpin[2] = {
    0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;
    /* init position value*/
    int DataValueL=125; //middle position
    int DataValueR=125; //middle position

    ////////////////////////////////////////////////////////////////////////////////
    // INITIALIZATION
    ////////////////////////////////////////////////////////////////////////////////
    void setup()
    {
    /* serial initialization */
    Serial.begin(115200);
    /* motor initialization */
    pinMode(statpin, OUTPUT);
    for (int i=0; i<2; i++)
    {
    pinMode(inApin, OUTPUT);
    pinMode(inBpin, OUTPUT);
    pinMode(pwmpin, OUTPUT);
    }
    // Initialize braked for motor
    for (int i=0; i<2; i++)
    {
    digitalWrite(inApin, LOW);
    digitalWrite(inBpin, LOW);
    }
    }
    ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////// Main Loop ////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    void loop()
    {
    int sensorL,sensorR;

    serialData();
    sensorR = analogRead(A4)/4;
    sensorL = analogRead(A5)/4; // echelle 0-1000
    /* Serial.print(sensorL);
    Serial.print(" ; ");
    Serial.println(sensorR);
    motorGo(motRigth, FW, 255);
    delay(100);
    motorOff(motRigth);
    delay(1000);
    */
    motorMotion(motRigth,sensorR,DataValueR);
    motorMotion(motLeft,sensorL,DataValueL);

    }
    ////////////////////////////////////////////////////////////////////////////////
    // Procedure: wait for complete trame
    ////////////////////////////////////////////////////////////////////////////////
    void serialData()
    {
    byte Data[3]={
    '0','0','0' };
    // il faut limmitter le temps pour garder le contrôle des moteurs
    if (Serial.available()>2){ //wait a packets of 6
    //test if order R or L data type
    Data[0]=Serial.read();
    if (Data[0]=='R'){ // ordre connue ?, si non je verrais au prochain tour !
    Data[1]=Serial.read();
    Data[2]=Serial.read();
    DataValueR=NormalizeData(Data);
    }
    if (Data[0]=='L'){ // ordre connue ?, si non je verrais au prochain tour !
    Data[1]=Serial.read();
    Data[2]=Serial.read();
    DataValueL=NormalizeData(Data);

    }
    }
    if (Serial.available()>16) Serial.flush();
    }
    ////////////////////////////////////////////////////////
    void motorMotion(int numMot,int actualPos,int targetPos)
    ////////////////////////////////////////////////////////
    {
    // int potPinL=A4; //to include in header procedure
    // int potPinR=A5; //to include in header procedure

    int Tol=4;
    int difference;
    int pwm;
    int securityLow=20;
    int securityHigh=200;
    int brakeDistance=16;
    boolean move=true;

    // encadrements des valeurs
    if (targetPos<securityLow+brakeDistance) targetPos=(securityLow+brakeDistance); //software limits, but consideration speed brake.
    if (targetPos>securityHigh-brakeDistance) targetPos=(securityHigh-brakeDistance); //software limits, but consideration speed brake.
    // calculate speed about distance
    difference=abs(targetPos-actualPos);

    if (difference<=Tol) pwm=0; // to near to mov
    if (difference>Tol) pwm=168;
    if (difference>50) pwm=200;
    if (difference>75) pwm=225;
    if (difference>100) pwm=255;
    // pay attention for security for Right motor!!
    if (actualPos>securityHigh || actualPos<securityLow) move=false; //mechanicals limits
    //to near to move
    if (difference<= Tol) move=false; //to near to move
    // en avant (haut)
    if (actualPos<targetPos && move) {
    pwm=255; //need power to go up !
    motorGo(numMot, FW, pwm);
    }
    pwm=255; //test !
    // en arriere (bas)
    if (actualPos>targetPos && move) motorGo(numMot, RV, pwm);
    // ne pas bouger !
    if (move==false) motorOff(numMot);// STOP
    }
    ////////////////////////////////////////////////////////////////////////////////
    void motorOff(int motor){
    ////////////////////////////////////////////////////////////////////////////////
    digitalWrite(inApin[motor], LOW);
    digitalWrite(inBpin[motor], LOW);
    analogWrite(pwmpin[motor], 0);
    }
    ////////////////////////////////////////////////////////////////////////////////
    void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
    ////////////////////////////////////////////////////////////////////////////////
    {
    if (motor <= 1)
    {
    if (direct <=4)
    {
    // Set inA[motor]
    if (direct <=1)
    digitalWrite(inApin[motor], HIGH);
    else
    digitalWrite(inApin[motor], LOW);

    // Set inB[motor]
    if ((direct==0)||(direct==2))
    digitalWrite(inBpin[motor], HIGH);
    else
    digitalWrite(inBpin[motor], LOW);

    analogWrite(pwmpin[motor], pwm);

    }
    }
    }
    ////////////////////////////////////////////////////////////////////////////////
    // testPot
    ////////////////////////////////////////////////////////////////////////////////
    void testPot(){

    Serial.print(analogRead(A4));
    Serial.print(";");
    Serial.println(analogRead(A5));
    delay(250);

    }
    ////////////////////////////////////////////////////////////////////////////////
    void testpulse(){
    int pw=120;
    while (true){

    motorGo(motLeft, FW, pw);
    delay(250);
    motorOff(motLeft);
    delay(250);
    motorGo(motLeft, RV, pw);
    delay(250);
    motorOff(motLeft);

    delay(500);

    motorGo(motRigth, FW, pw);
    delay(250);
    motorOff(motRigth);
    delay(250);
    motorGo(motRigth, RV, pw);
    delay(250);
    motorOff(motRigth);
    Serial.println("testpulse pwm:80");
    delay(500);

    }
    }
    ////////////////////////////////////////////////////////////////////////////////
    // Function: convert Hex to Dec
    ////////////////////////////////////////////////////////////////////////////////
    int NormalizeData(byte x[3])
    ////////////////////////////////////////////////////////////////////////////////
    {
    int result;

    if (x[2]==13) //only a LSB and Carrier Return
    {
    x[2]=x[1]; //move MSB to LSB
    x[1]='0'; //clear MSB
    }
    for (int i=1; i<3; i++)
    {
    if (x>47 && x<58 ){//for xA to xF
    x=x-48;
    }
    if ( x>64 && x<71 ){//for x0 to x9
    x=x-55;
    }
    }
    result=(x[1]*16+x[2]);
    return result;
    }

    when the code was loaded, I turned the engines on. I have the potentiometers on each side in my hand, and I tried to rotate the potentiometer. With the potentiometer positioned in the same way that will be mounted, I tried to rotate, the motor started in the opposite direction (otherwise you need to reverse the power supply wires of the motor) Once this verification was completed, I rotated the potentiometers in the central position and the motors stopped. I connected everything and with the assembly of the pieces to make the upper part move.
    20150520_185655.jpg
    This in the result.

    20150708_072836.jpg


    I connected the card to the PC, I powered the engines, opened the serial warning of the Arduino program and entering these codes the simulator responded as expected.

    In the "Serial Monitor" send the following strings in Hexa and Enter:
    R7FL7F
    -> it should move the playseat in horizontal position

    R64L64
    R3FL3F
    R01L01 (max !!)
    -> it should tilt the playseat backward and a bit further

    R9BL9B
    RC1LC1
    RFFLFF (Max !!)
    -> it should tilt the playseat forward and a bit further

    You can mix for rolling movment :
    R3FLC1
    R01LFF (Max !!)
    -> roll left

    RC1L3F
    RFFL01 (Max !!)
    -> roll right

    The simulator is ready for final test.

    1°test


    I will continue to connect with simtools later on.

    a special thanks to Racing Mat which was a reference.

    Attached Files:

    Last edited: Jan 11, 2019
  2. Pramuuditha Kumara

    Pramuuditha Kumara Member

    Joined:
    Jan 6, 2019
    Messages:
    31
    Balance:
    162Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    hi nice work buddy,
    im planing almost same way.
    can please share sim tools setting to me ....
    thank you in advance...