This topic has 7 replies, 3 voices, and was last updated 7 years, 4 months ago by SuperDroid.

  • Author
    Posts
  • #4118
     Jerry
    Participant

    Hello , is possible to control DC motors with Sabertooth 2X12 connected to PWM pins ( rspi 3 B => GPIO16 , GPIO 19) ?

    GPIO16 will be connected to S1
    GPIO19 will be connected to S2

    Sabertooth DIP Settings 1 OFF 2 ON 3 ON 4 OFF 5 ON 6 OFF

    Am I right ? Coding structure given below, I don’t know how to control, what’s wrong with my program ?

    #define Motr1 4   // GPIO 16
    #define Motr2 12 // GPIO 19
    
    pinMode(Motr1, OUTPUT);
    pinMode(Motr2, OUTPUT);
    
    softPwmCreate(Motr1,0,100); // PWM Initialization
    softPwmCreate(Motr2,0,100); 
    
    void RobotMotion::Forward_Manual_Motion()
    {
     softPwmWrite(Motr2, 13);
     softPwmWrite(Motr1, 13);
    }
    
    void RobotMotion::Stop_motion()
    {
     softPwmWrite(Motr1,14);
     softPwmWrite(Motr2,14);
     delay(1000);
    }
    
    void RobotMotion::Backward_motion()
    {
     softPwmWrite(Motr1, 16);
     softPwmWrite(Motr2, 16);
    }

    How to control direction ? I have tried with this programming but motor not stopping properly. Kindly help me to solve the problem.

    Thanks

    #4120
     SuperDroid
    Keymaster

    Hello Jerry. This is possible. If switch 4 on the Sabertooth is in the ON position, it will enable mixing mode. S1 will act as the drive forward/backwards signal input and S2 will be the turn left/right signal input. With switch 4 OFF, you will have to compute the mixing in order to drive/turn in different directions.

    Since you have the Sabertooth in Microcontroller mode (switch 6 OFF), the timeout feature is disabled. This will have to be implemented on your end. Without a timeout, the motor controller will act on the last valid command until a new one is received.

    All of this information can be found within the 2×12 datasheet.

    #4121
     Jerry
    Participant

    Can you please tell me exact DIP switch setting ? Whether my program correct or not ? If any problem in my code, can you please tell me what I want to change ?

    #4122
     SuperDroid
    Keymaster

    If you want to control with RC mode, set 1 off, 2 on, 3 on, 4 off, 5 on, 6 off. Note that to use RC mode, you will need to make sure your PWM signal matches the characteristics of an RC signal: https://en.wikipedia.org/wiki/Servo_control.

    Pulse widths must range from about 1 to 2 ms. 1 ms as the smallest width (not 0), 2 ms as the largest width. 1.5 ms pulse width means stop, 1.5-2.0 means spin forward, 1.0-1.5 means spin backward. Frequency should be in the neighborhood of 50 Hz.

    If you can’t get the rspi to output PWM with these characteristics then you need to use a different control method. One option is to set the Sabertooth to analog input mode and use an RC low-pass filter circuit to convert your PWM signal into an analog voltage. Another (better) option is to just run the Sabertooth in serial mode (dip switches 1 and 2 down). This gives you the advantages of noiseless control inputs, better failsafes, and a true zero command.

    EDIT: One other thing I forgot to mention is that the Sabertooth is designed to operate with 5V control inputs. The raspberry pi GPIO uses 3.3V, so you may run into issues there. It -might- work as is, but you would be better off level-shifting your 3.3V stuff to 5V.

    #4142
     Jerry
    Participant

    I have tried this method, “RC low-pass filter circuit to convert PWM signal into an analog voltage”, but I didn’t received proper response from sabertooth. One motor moving very high speed and another motor moving very less speed.

    Similar way I have tried with sabertooth in serial mode but there is no positive response.

    So return to RC mode, set 1 off, 2 on, 3 on, 4 off, 5 on, 6 off. I will try to write a program in servo style. That may work to solve the problem. But I am not sure, I have a confusion. Can you suggest programmatic changes. If possible kindly provide your contact details. That will help me to interact with you.

    If I didn’t use Logic level converter, it will affect Raspberry pi GPIO pins ?

    #4145
     SuperDroid
    Keymaster

    The raspberry pi GPIO operates on 3.3 Volt communication. The Sabertooth calls for 5 Volt communication. It would be in your best interest to implement level shifting in order for your logic voltages to be compatible. If you make this change and it still doesn’t work, then making changes in the software will be the next step.

    You can make this setup work in RC mode. However, it going to be better to use serial communication when sending commands to a motor controller with a MCU. As laid out in our last post, you’re going to have noiseless control inputs with a better failsafe with serial.

    #4214
     Rodd Starr
    Participant

    Hi…i am a new user here. As per my knowledge If switch 4 on the Sabertooth is in the ON position, it will enable mixing mode. S1 will act as the drive forward/backwards signal input and S2 will be the turn left/right signal input. With switch 4 OFF, you will have to compute the mixing in order to drive/turn in different directions.

    #4215
     SuperDroid
    Keymaster

    When Switch 4 is in the UP position, Mixed mode is selected. In this mode, the R/C signal fed to the S1 input controls the forward/backwards motion of the vehicle. This is usually connected to the throttle channel of a pistol grip transmitter, or the elevator channel of a dual stick transmitter. The R/C signal fed to the S2 input controls the turning of the vehicle. When switch 4 is in the DOWN position, Independent mode is selected. In this mode, the signal fed to the S1 input directly controls Motor 1 (M1A and M1B) and the signal fed to S2 controls Motor 2.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

Login Register

©2024 SDRobots.com | All rights reserved.

Log in with your credentials

or    

Forgot your details?

Create Account