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 SMC using encoder creeps

Discussion in 'Miscellaneous' started by Eli Wizard, Jun 19, 2024.

  1. Eli Wizard

    Eli Wizard New Member

    Joined:
    Jan 22, 2017
    Messages:
    12
    Location:
    Ottawa
    Balance:
    32Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    My rig uses encoders on the motors and I'm trying to use SMC.
    I've got an UNO, IBT-2 and a small 12v motor with reduction gearbox and an osepp encoder fitted to motor shaft set up for testing.
    I've got the encoder into the SMC code and:
    -the SMC monitor displays a near perfect overlay of target and feedback
    - the motor appears to be in sync but is advancing (or regressing).
    It did not behave like this using a pot for feedback so I don't think the gears are at fault.
    Instead of keeping a constant sweep of 2 > 5, 5 > 2, 2 > 5,,, it goes something like 2 > 5, 5 > 2, 2 > 6, 6 > 3, 3 > 7,,,
    the encoder is mapped:
    SWmulti = map(SMPulseCount, -512, 512, 0, 1023);

    How may I stop creeping?

    thanks
  2. Eli Wizard

    Eli Wizard New Member

    Joined:
    Jan 22, 2017
    Messages:
    12
    Location:
    Ottawa
    Balance:
    32Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    and here's the sketch I'm inserting, I can't post the SMC sketch with it in it (too many characters)

    Code:
    
    
    int SMsensor01;
    int SMsensor02;
    int SWmulti;
    int SMstepOld;
    int SMstep;
    long SMPulseCount;
    #define SMSENSOR_A 2
    #define SMSENSOR_B 3
    
    void checkState(){
      SMsensor01 = digitalRead(SMSENSOR_A);
      SMsensor02 = digitalRead(SMSENSOR_B);
    
      if(SMsensor01 == 1 && SMsensor02 == 1){
        SMstep = 0;
        if(SMstepOld == 1){
          SMPulseCount--;
        }
        if(SMstepOld == 3){
          SMPulseCount++;
        }
        SMstepOld = 0;
      }
    
      if(SMsensor01 == 0 && SMsensor02 == 1){
        SMstep = 1;
        if(SMstepOld == 2){
          SMPulseCount--;
        }
        if(SMstepOld == 0){
          SMPulseCount++;
        }
        SMstepOld = 1;
      }
    
      if(SMsensor01 == 0 && SMsensor02 == 0){
        SMstep = 2;
        if(SMstepOld == 3){
          SMPulseCount--;
        }
        if(SMstepOld == 1){
          SMPulseCount++;
        }
        SMstepOld = 2;
      }
    
      if(SMsensor01 == 1 && SMsensor02 == 0){
        SMstep = 3;
        if(SMstepOld == 0){
          SMPulseCount--;
        }
        if(SMstepOld == 2){
          SMPulseCount++;
        }
        SMstepOld = 3;
      }
    
    }
    
    void setup() {
    
     
    
    
      attachInterrupt(0, checkState, CHANGE);
      attachInterrupt(1, checkState, CHANGE);
      //Serial.begin(9600);
      SMPulseCount = 0;
    }
    
    void loop() {
    
     
     
      if(SMPulseCount > -1){
       
      }
    
      if(SMPulseCount < 10 && SMPulseCount > -10){
    
      }
    
      if(SMPulseCount < 100 && SMPulseCount > -100){
    
      }
    
    
      if(SMsensor01 == 1){
    
      }
      else{
    
      }
    
    
    
      if(SMsensor02 == 1){
    
      }
      else{
    
      }
    
      SWmulti = (SMPulseCount - 850);
      SWmulti = constrain(SWmulti, 0, 45);
     
        Serial.print("SMPulseCount: ");
        Serial.print(SMPulseCount);
        Serial.print("\t");
        Serial.print("SWmulti: ");
        Serial.println(SWmulti);
        //Serial.print("SMPulseCount: ");
        //Serial.println(SMPulseCount);
    }