View Single Post
  #43  
Old 12-28-2020, 05:53 PM
Originalrob Originalrob is offline
Newbie
 
Join Date: Apr 2019
Posts: 53
Originalrob is on a distinguished road
Default Re: Newbie Scratch Build - D575A Dozer

Which brings us back to electronics !

So i did have this running ( up off the tracks on a stand) using a 2x32a Sabertooth controller from my openTX transmitter ( Radiomaster 16 channel) and it ran as expected (very well). The only problem was when i was at full stick forward the RPM of the track was about 30RPM at the sprocket. Far to fast for what i wanted. With the sabertooth, you can just ease off the stick to slow down but that comes at the cost of torque as the controller just turns down the voltage, slowing the motors. A 24v motor running at 9 v just isnt as strong at one at full power.

Thought about gearing the motors down further ( way to much work and i really didn't want to go back to the drawing board on the transmission!) but i remembered another build thread that talked about PWM control of DC motors. Main benefit being that you just pulse the motors very fast for a percentage of time so that the motors slow but are still getting 24v ( but only for very rapid short bursts)
So after a few weeks i ditched the sabertooth in favour of the following PWM setup:



OpenTX radio talks to two channels on the receiver.
2 channels on the receiver are connected to inputs onto an Arduino microprocessor
Outputs from the Arduino are PWM signals for motor speed and another for motor direction which get connected to a PWM capable motor driver.

That's the easy part ! The hard part was writing the code for the Arduino.

After a couple weeks of Arduino code for dummies and watching every youtube tutorial possible i was able to write the code for differiantial/tank steering.

its a steep learning curve but well worth the effort. Its not just the benefits of PWM motor control but also being able to control lighting, sound or anything really you wanted. I will post the code below so that hopefully it may help someone else one day.


Setup:
Open TX TX16s transmitter (2 channels for drive motors)
10ch receiver
Arduino Uno (Elegoo starter kit)
Cytron MDD10A Dual Motor Driver (PWM input)
2x24v brushed DC motors with 1:72 planetary gearboxes
7s LiPo at 24 v

Code:

int dir1 = 7;
int dir2 = 4;
//the following are all ~PWM capable ports
int pwm1 = 6;
int rc_channel4 = A0;
int pwm2 = 5;
int rc_channel2 = A1;
void setup() {

TCCR0B = TCCR0B & B11111000 | B00000010; // for PWM frequency of 7812.50 Hz (Output pins 5,6)
pinMode(rc_channel4, INPUT);
pinMode(dir1, OUTPUT);
pinMode(pwm1, OUTPUT);
pinMode(rc_channel2, INPUT);
pinMode(dir2, OUTPUT);
pinMode(pwm2, OUTPUT);
Serial.begin(9600);
}


void loop() {

int pwmA = 0;
int rc4 = pulseIn(rc_channel4, HIGH, 35000);
int pwmB = 0;
int rc2 = pulseIn(rc_channel2, HIGH, 35000);

Serial.print(" raw channel4: ");
Serial.print(rc4);
Serial.print(" raw channel2: ");
Serial.print(rc2);
delay(100);

if (rc4<1450 && rc4>1400) {
Serial.println(" stick centered");
analogWrite(pwm1, 0);

}
if (rc2<1450 && rc2>1400) {
Serial.println(" stick centered");
analogWrite(pwm2, 0);
}
if(rc4 > 1450){ //right stick
pwmA = map(rc4, 1450, 1910, 0, 255); //map our speed to 0-255 range
digitalWrite(dir1, LOW);
analogWrite(pwm1, pwmA);
pwmA = constrain(pwmA,0,255);
Serial.print(" right stick speed: ");
Serial.println(pwmA);
}
if(rc2 > 1450){ //left stick
pwmB = map(rc2, 1450, 1910, 0, 255); //map our speed to 0-255 range
digitalWrite(dir2, HIGH);
analogWrite(pwm2, pwmB);
pwmB = constrain(pwmB,0,255);
Serial.print(" left stick speed: ");
Serial.println(pwmB);
}
if(rc4 < 1400){
pwmA = map(rc4, 1400, 920, 0, 255); //map our speed to 0-255 range

digitalWrite(dir1, HIGH);
analogWrite(pwm1, pwmA);
pwmA = constrain(pwmA,0,255);
Serial.print(" right stick speed: ");
Serial.println(pwmA);
}
if(rc2 < 1400){
pwmB = map(rc2, 1400, 920, 0, 255); //map our speed to 0-255 range

digitalWrite(dir2, LOW);
analogWrite(pwm2, pwmB);
pwmB = constrain(pwmB,0,255);
Serial.print(" left stick speed: ");
Serial.println(pwmB);
}


delay(10);
}


I raised the frequency of the PWM to remove the high pitch whine and increase driver efficiency but not necessary. I have this working on my desktop (image) and its working as i would want. once its installed i may have to tweak the steering inputs but generally its a good starting point.

Thats enough for one day !

feel free to ask questions if needed

Rob
Reply With Quote