Great work Youngjae. I will have to try that code someday. If I can suggest something that I learnt from bitter experience.
I can guarantee that lines of code that make sense today, will next week make no sense at all. Been there and experienced it myself. So, the more comments you put in your code the better to understand what you did in 2 weeks time. Comments are not compiled with the code so they do not take up any space.
Vince
Re: Chieftain kit arrival
Posted: Fri Jun 19, 2020 9:52 am
by andymusgrove
Wow that is awesome and if i knew how to use it fully i would appreciate it more im sure, would love to be able to use it and may well do - does anyone out there fully understand this and be able to offer a kit of parts or similar??
Re: Chieftain kit arrival
Posted: Fri Jun 19, 2020 7:09 pm
by Richard Goodwin
Great effort YoungJae, well done.
I would agree with the comment made by Vince about having more comments though; nothing worse when going through code and trying to fathom out why you did it that way! I found that comments almost at every step, would allow me to go to the correct area every time and was extremely useful later on if I had to revisit.
I would agree with the comment made by Vince about having more comments though; nothing worse when going through code and trying to fathom out why you did it that way! I found that comments almost at every step, would allow me to go to the correct area every time and was extremely useful later on if I had to revisit.
I agree with Vince and Richard.
I will use our motion controller to raise the source code to version 2, and attach the notes and the experimental value to all the phrases in version 1 that I posted yesterday.
I will try to finish this series as soon as possible.
However, if the hardware changes, I have to modify the source code and experiment, especially since I have to call a new head-up file.
Vince, your detail and concentration are so touching.
I corrected some typos and annotated them.
I added the function to fix the turret and main gun by adding the switch channel number 52.
By adding this function, the main gun and turret can be safely secured even when the transmitter is turned off by mistake.
Youngjae
Re: Chieftain kit arrival
Posted: Sat Jun 20, 2020 3:25 pm
by Youngjae Bae
/* 2020-06-19
* This source code was written by Youngjae Bae to reduce unnecessary elements and stabilize
* the main gun and turret of the big-scale model tank by referring to the code of
* Kris Winer and the condition statement of Vince Cutajar.
*
* Based on the Arduino Mega, the power of the transmitter must be turned on by dust and
* supplied by the receiver and Arduino, and when switched off,
* the power of the transmitter must be shut off at the end.
*
* The transmitters and receivers for RC use spectrum DX6 and AR610.
* The motor driver used the SZDLT or L298N two-channel driver.
*/
// Main Control Parameters - The sensitivity or intensity of the test is adjusted here.
#define PitchPower 254 // (PWM) Defines the power of the motor for pitch and yaw control.
#define YawPower 254 // (PWM) The maximum value is 255 or mid-range and is determined according to your taste.
#define PitchAngle 3 // (degree) A dead band of 1 degree is created so that
#define YawAngle 3 // (degree) the dc motor will not hunt when reaching desired pitch
#define CheckTime 120 // (milliseconds) The shorter the time to check the displacement, the more vibration it can reflect.
#define deadzone 50 //(PWM) Anything between -50 and 50 is stop
#define ConstrainLimit 254 //(PWM) Constrain limits, Maximum of the strength of the motor rotation, usually 255
///////////////////////////////////////////////////////////////////////////////////////
// File call to use MPU9250 and quadrant formula
#include "MPU9250.h" // Make sure to upload the first head-up file of Kris Winer..
#include "quaternionFilters.h" // There are many head-up files of the same name, and if this is misselected, it is impossible to compile.
// MPU9250 setup
#define SCL 700000 // Pre-defined serial clock rate
#define SDA Wire // Use the built-in Wire Library for I2C communication
#define MPU9250_ADDRESS 0x68 // Address for using MPU9250 as 5V
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL); // Using MPU9250 named internal classes as IMU functions
// Transmitter connections
#define THRO_PIN 22 // THRO PIN IN AR610 CONNECTED TO Aduino Mega No.22
#define RUDD_PIN 23 // Can be replaced with your preferred pins
#define AUX1_PIN 52 // A switch that holds the main gun and turret
// Motor driver pins
#define A1_PIN 3 // Connect to each pin of the Arduino and SZDLT or L298N two-channel driver.
#define A2_PIN 4 // Can be replaced with your preferred pins
#define PA_PIN 2
#define B1_PIN 5
#define B2_PIN 6
#define PB_PIN 7
// Declaration of Variables for Stabilization
float OldPitch, NewPitch, DiffPitch; // real-type variable associated with pitch
float OldYaw, NewYaw, DiffYaw; // real-type variable associated with yaw
int THRO, RUDD, AUX1 = 0; // Declares the rudder and throttle channels as integer variables and defines zero
// Set to true to get Serial output for debugging
#define SerialDebug true
void setup() {
// Define a Pin Using Arduino
pinMode(THRO_PIN, INPUT); //Determine the input or output of the pins used by Arduino
pinMode(RUDD_PIN, INPUT);
pinMode(AUX1_PIN, INPUT);
pinMode(A1_PIN, OUTPUT);
pinMode(A2_PIN, OUTPUT);
pinMode(PA_PIN, OUTPUT);
pinMode(B1_PIN, OUTPUT);
pinMode(B2_PIN, OUTPUT);
pinMode(PB_PIN, OUTPUT);
// Settings for MPU9250 sensor Usage
IMU.initAK8963(IMU.factoryMagCalibration); // Initialize compass
IMU.initMPU9250(); // Initialize acceleration, gyro, etc.
IMU.getAres(); // Define Acceleration Usage Functions
IMU.getGres(); // Definition of gyro function
IMU.getMres(); // Magnetism Usage Definitions
Serial.begin(115200); // Specify serial communication calls and baud rates
// Convert to PWM value (-ConstrainLimit to ConstrainLimit)
THRO = pulseToPWM(THRO);
RUDD = pulseToPWM(RUDD);
AUX1 = pulseToPWM(AUX1);
if(SerialDebug) {
Serial.print(THRO);
Serial.print(" ");
Serial.print(RUDD);
Serial.println("This value is a GUN position.");
Serial.println();
Serial.print(RUDD);
Serial.print(" ");
Serial.print(RUDD);
Serial.println("This value is a TURRET position.");
Serial.println();
}
if (AUX1 == 0) { // The ability to hold the main gun and turret forcibly
digitalWrite(A1_PIN, LOW); // if the transmitter signal is missing or required.
digitalWrite(A2_PIN, LOW);
digitalWrite(B1_PIN, LOW);
digitalWrite(B2_PIN, LOW);
} else {
if( THRO != 0 || RUDD != 0 ) {
// THRO and RUDD Drive motor move
drive(THRO, RUDD);
// Anything in deadzone should stop the motor
if ( abs(pulse - 0) <= deadzone ) {
pulse = 0;
}
return pulse;
}
Re: Chieftain kit arrival
Posted: Sun Jun 21, 2020 1:42 am
by Youngjae Bae
/* 2020-06-21
* This source code was written by Youngjae Bae to reduce unnecessary elements and stabilize
* the main gun and turret of the big-scale model tank by referring to the code of
* Kris Winer and the condition statement of Vince Cutajar.
*
* Based on the Arduino Mega, the power of the transmitter must be turned on by dust and
* supplied by the receiver and Arduino, and when switched off,
* the power of the transmitter must be shut off at the end.
*
* The transmitters and receivers for RC use spectrum DX6 and AR610.
* The motor driver used the SABERTOOTH(MOTION CONTROLLER B) driver.
* Turn on 2, 3 and 5 deep switches and turn off 1, 4 and 6.
*/
// Main Control Parameters - The sensitivity or intensity of the test is adjusted here.
#define ServoPower 200 // (PULSE)) Defines the power of the motor for pitch and yaw control.
#define PitchAngle 1 // (degree) A dead band of 1 degree is created so that
#define YawAngle 1 // (degree) the dc motor will not hunt when reaching desired pitch
#define CheckTime 1 // (milliseconds) The shorter the time to check the displacement, the more vibration it can reflect.
#define deadzone 150 //(PULSE) Anything between -150 and 150 is stop
// File call to use MPU9250 and quadrant formula
#include "MPU9250.h" // Make sure to upload the first head-up file of Kris Winer.
#include "quaternionFilters.h" // There are many head-up files of the same name, and if this is misselected, it is impossible to compile.
// Servo Library for Using SABERTOOH
#include <Servo.h> // Use motion controller B using angle mode
// MPU9250 setup
#define SCL 700000 // Pre-defined serial clock rate
#define SDA Wire // Use the built-in Wire Library for I2C communication
#define MPU9250_ADDRESS 0x68 // Address for using MPU9250 as 5V
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL); // Using MPU9250 named internal classes as IMU functions
// Transmitter connections
#define THRO_PIN 22 // THRO PIN IN AR610 CONNECTED TO Aduino Mega No.22
#define RUDD_PIN 23 // Can be replaced with your preferred pins
#define AUX1_PIN 52 // A switch that holds the main gun and turret
// Motor driver pins
#define S1_PIN 3 // Connect to each pin of the Arduino and SZDLT or L298N two-channel driver.
#define S2_PIN 2 // Can be replaced with your preferred pins,
// Servo library channel declaration
Servo STS1; // I'll name the Sabertooth servo channel objects STS1 and STS2.
Servo STS2; // Connections to make: Dip switch on are 2, 3, 5 The rest are off.
// Arduino Pin 2 -> Sabertooth S1
// Arduino Pin 3 -> Sabertooth S2
// Arduino GND -> Sabertooth 0V
// Arduino VIN -> Sabertooth 5V(OPTION)
// Declaration of Variables for Stabilization
float OldPitch, NewPitch, DiffPitch; // real-type variable associated with pitch
float OldYaw, NewYaw, DiffYaw; // real-type variable associated with yaw
int THRO, RUDD, AUX1 = 0; // Declares the rudder and throttle channels as integer variables and defines zero
// Set to true to get Serial output for debugging
#define SerialDebug true
void setup() {
// Define a Pin Using Arduino
pinMode(THRO_PIN, INPUT); //Determine the input or output of the pins used by Arduino
pinMode(RUDD_PIN, INPUT);
pinMode(AUX1_PIN, INPUT);
pinMode(S1_PIN, OUTPUT);
pinMode(S2_PIN, OUTPUT);
// Attach pulse width value to servo channel
STS1.attach(S1_PIN, 1000, 2000); // Sabertooth accepts servo pulses from 1000us to 2000us.
STS2.attach(S2_PIN, 1000, 2000); //
// Settings for MPU9250 sensor Usage
IMU.initAK8963(IMU.factoryMagCalibration); // Initialize compass
IMU.initMPU9250(); // Initialize acceleration, gyro, etc.
IMU.getAres(); // Define Acceleration Usage Functions
IMU.getGres(); // Definition of gyro function
IMU.getMres(); // Magnetism Usage Definitions
Serial.begin(115200); // Specify serial communication calls and baud rates
//Convert pulse to pulse (1000 to 2000)
THRO = pulseTopulse(THRO);
RUDD = pulseTopulse(RUDD);
AUX1 = pulseTopulse(AUX1);
if(SerialDebug) {
Serial.print(THRO);
Serial.print(" ");
Serial.print(RUDD);
Serial.println("This value is a GUN position.");
Serial.println();
Serial.print(RUDD);
Serial.print(" ");
Serial.print(RUDD);
Serial.println("This value is a TURRET position.");
Serial.println();
}
if (AUX1 == 0) { // The ability to hold the main gun and turret forcibly
STS1.writeMicroseconds(1500);
STS2.writeMicroseconds(1500);
} else {
if( THRO != 1500 || RUDD != 1500 ) {
// THRO and RUDD Drive motor move
STS1.writeMicroseconds(THRO);
STS2.writeMicroseconds(RUDD);
I also share the code for SABERTOOTH as above.
However, SABRTTOOTH has its own signal processing function, and amplification occurs between MPU9250 signals.
I couldn't solve this problem.
However, the two-channel motor driver, which does not have its own computation function, has been directly confirmed that there is no such negative problem because Arduino controls the direction and size.
So I will use this passive motor controller.
I reinforced L298N's insufficient power with SZDLT 2 channel 500W motor controller, which costs about 25USD.
Youngjae
Re: Chieftain kit arrival
Posted: Sun Jun 21, 2020 4:42 am
by Vince Cutajar
Even though I don't have a Chieftain I am still following your progress in turret and barrel stabilization with great interest. I think it is a good idea to replace the L298N with SZDLT 2 channel 500W motor controller.
Do you have an internet link with more information about this new motor controller?
Even though I don't have a Chieftain I am still following your progress in turret and barrel stabilization with great interest. I think it is a good idea to replace the L298N with SZDLT 2 channel 500W motor controller.
Do you have an internet link with more information about this new motor controller?
As usual, I bought it from Alli Express.
Please refer to it.
Aluminium heat shield must be purchased separately.
Stabilization will be available for all tanks as well as for Chieftain.
I will apply it to my kingtiger, too.
I will make a turret with wood and make a main gun and test the motion next week and apply it to the my Chieftain when the direction of all the movements is perfect.
Youngjae
Re: Chieftain kit arrival
Posted: Mon Jun 22, 2020 2:08 am
by Youngjae Bae
Today, I made a wooden cannon to test the movement.
After work, I will test the range and speed of the transmitter by installing MPU9250 sensor and actuator on this cannon.
After everything has been verified, I am planning to install it directly in my Chieftain.
Youngjae
Re: Chieftain kit arrival
Posted: Mon Jun 22, 2020 1:04 pm
by Youngjae Bae
Today I started making a simple model cannon test bed to test the main gun stabilizer.
I installed the sensor and started to find the best conditions for all variables.
These tests will be repeated several times and the most meaningful values will be derived as constants.
I found it very difficult to understand the state of the sensor because it is more sensitive than I thought.
I will be patient and get the best results.
Youngjae
Re: Chieftain kit arrival
Posted: Mon Jun 22, 2020 1:51 pm
by Adrian Harris
I love the test rig
It looks to me as though the actuator operates much faster when controlled by the receiver than by the Arduino. Do you think that is the case ?
I don't think Google understood what you said here: "I found that sensors are more sensitive than raw giggles"
Adrian.
Re: Chieftain kit arrival
Posted: Mon Jun 22, 2020 2:11 pm
by John Clarke
Hi Youngjae, I do find you post really entertaining, instructive and sometimes "whoosh" right over my head.
I know that you wish to crack the stabilization thing, but have you had a look at this , "GSU 2 Axis Gun Stabilize Unit - 35 RC Tank".
Or the recently seen "K12 - 35 RC Tank"- RC Conversion Kit for TAMIYA 1/35 Challenger 2, with MTC-2, ACU and GSU"
Could they be adapted? It has 2 axis control and deck sensing to raise gun all in one package.
I may look into them myself, I had thought I'll probably be using a simple "Sub leveler" on the single Y axis, it would give a crude form of stabilization, gun forward only though.