Chieftain kit arrival
-
- Posts: 2180
- Joined: Wed Nov 15, 2017 1:43 pm
- Location: Malta
- Has liked: 762 times
- Been liked: 1738 times
Re: Chieftain kit arrival
With those turret turn and barrel speeds the stabilization should look perfect.
Vince
Vince
- John Clarke
- Posts: 1631
- Joined: Sun Oct 17, 2010 10:06 pm
- Location: Staffordshire
- Been liked: 1729 times
Re: Chieftain kit arrival
Very impressive, love the motor sounds, it'll be great to see it fully stabilized.
But do you think the crew will be issued with vomit bags?
But do you think the crew will be issued with vomit bags?
Oh Man, I only ride em I don't know what makes them work,
Definatley an Anti-Social type
Definatley an Anti-Social type
-
- Posts: 4268
- Joined: Mon Mar 01, 2010 4:48 pm
- Location: Cornwall
- Has liked: 2259 times
- Been liked: 7147 times
Re: Chieftain kit arrival
Love it very impressive! A question, how or what will you lock the barrel onto? I think you may need a program to create a realistic "search", "aquire", "lock"," engage" etc etc?
This is ground breaking!
This is ground breaking!
Mechanical engineer.
2 Youtube channels, Phil Woollard and Magpiespyro. Facebook/ Phil Woollard.
Commission builds considered. Pm for my email.
2 Youtube channels, Phil Woollard and Magpiespyro. Facebook/ Phil Woollard.
Commission builds considered. Pm for my email.
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
I'm also curious about Adrian's interests.Adrian Harris wrote: ↑Thu Apr 23, 2020 1:37 pmI will be interested to see how the buck converter handles changes in battery voltage, as I would have thought it will collapse if the input voltage drops below about 25.5V.
Adrian.
The stepdown dc-dc converter I purchased should always have a voltage greater than 1V input than the voltage used.
I still don't know at what voltage my lithium battery BMS shuts off the power supply.
So I installed the sensor to display the battery voltage on my flysky transmitter.
The Armortek power distribution system also showed a slight voltage drop.
I am going to check the status of the voltage from time to time by walking all the loads such as the smoke system.
And I am considering applying "AnyVolt 3" step up & down free converter if necessary to keep the output constant regardless of the high or low voltage on the input side.
Youngjae
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
Recently, I have been planning a motion test by creating a separate model and attaching a sensor to implement all the processes including stabilization of the main gun and prevention of collision. During the process, I changed the microprocessor from Arduino Uno to Arduino Mega, and now I'm sketching a new program using C language. So far, the RC system, Arduino and motion controller B, ultrasonic sensors to detect collision prevention of artillery and body, color sensors to detect collision area and safety area, and 9-axis sensors to detect XYZ and rotationality have been completed to monitor the values required.
I plan to make model cannons on wooden boards, configure all the hardware in a series of experiments, and modify debugging work to make modules to install on my chieftain and kingtiger if there is no problem. It's slow, but I'll share the progress from time to time.
The source code below is being sent by referring to the open source of each component and will be opened with the annotation after verification.
Youngjae
I plan to make model cannons on wooden boards, configure all the hardware in a series of experiments, and modify debugging work to make modules to install on my chieftain and kingtiger if there is no problem. It's slow, but I'll share the progress from time to time.
The source code below is being sent by referring to the open source of each component and will be opened with the annotation after verification.
Youngjae
Last edited by Youngjae Bae on Wed Jul 08, 2020 1:35 am, edited 4 times in total.
-
- Posts: 2180
- Joined: Wed Nov 15, 2017 1:43 pm
- Location: Malta
- Has liked: 762 times
- Been liked: 1738 times
Re: Chieftain kit arrival
Best of luck Youngjae. I could not get a good yaw reading with my sketch. Pitch reading was OK. Looking forward to more updates.
Vince
Vince
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
Case 1: RC + Arduino + Motion Controller B (Sabertooth) + MPU9250(measurement only)
Case 2: RC + Arduino + SZDLT(L298N) + MPU9250(measurement only)
I completed the sketch of the most basic "RC + Arduino + Motor controller + MPU9250(measurement only)" as follows.
The phenomenon of fine shaking at the neutral point of the transmitter stick was also fixed by setting deadzone.
This is a code that has proven integrated behavior.
This post will continue to be revised and updated in the future.
Youngjae
//////////////////////////////////// Case A: //////////////////////////////////////////
/* Main Control Parameters - The sensitivity or intensity of the test is adjusted here.*/
#define CheckTime 240 // (milliseconds) The shorter the time to check the displacement, the more vibration it can reflect.
#define deadzone 150 // (PWM) Anything between -150 and 150 is stop
#define SerialDebug true
///////////////////////////////////////////////////////////////////////////////////////
/* 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 400000 // 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
/* Using MPU9250 named internal classes ad IMU function */
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL);
/*To use Sabertooth(Motion Controller B) */
#include <Servo.h>
/* Definition of the connection pin between RC receiver and Arduino */
#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
/* Definition of the connection pin between Sabertooth and Arduino */
#define S1 2 // Arduino Pin 2 -> Sabertooth S1, Arduino GND -> Sabertooth 0V
#define S2 3 // Arduino Pin 3 -> Sabertooth S2, Arduino VIN <- Sabertooth 5V (OPTION)
/* Definition servo channel of Sabertooth */
Servo STS1; // To name the Sabertooth servo channel objects STS1 and STS2
Servo STS2; // Dip switch on are 2, 3, 5 The rest are off
/* Parameters for radio control */
int pulse;
int AUX1;
void setup() {
/* Define a Pin Using Arduino */
pinMode(THRO_PIN, INPUT);
pinMode(RUDD_PIN, INPUT);
pinMode(AUX1_PIN, INPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
/* Attach pulse width value to servo channel */
STS1.attach(S1, 1000, 2000); // Sabertooth accepts servo pulses from 1000us to 2000us.
STS2.attach(S2, 1000, 2000); // I need to specify the pulse widths in attach().
/* 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 Communications for Debug */
Serial.begin(115200); // Specify serial communication calls and baud rates
}
void loop() {
mpu9250();
/* Convert RC pulse to switch signal (0 and 1) */
AUX1 = constrain(map((pulseIn(AUX1_PIN, HIGH)), 1058, 1887, 0, 1), 0, 1);
if(SerialDebug) {
Serial.print("AUX1 =");
Serial.println(AUX1);
Serial.println();
}
if(AUX1 == 0) { // Tansmitter turned off or switch off
STS1.writeMicroseconds(1500); // Stops the main gun un and down
STS2.writeMicroseconds(1500); // Stops the turret turn
}else{ // Tansmitter turned on and switch on
/* Convert RC pulse and write to servo channel */
STS1.writeMicroseconds(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
STS2.writeMicroseconds(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
if(SerialDebug) {
Serial.println("THRO PULSE =");
Serial.print(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
Serial.println();
Serial.println("RUDD PULSE =");
Serial.print(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
Serial.println();
}
}
}
/* Convert DX6 Transmitter pulse to servo pulse*/
int pulseTopulse(int pulse_r) {
if (pulse > 900) {
pulse = constrain(map(pulse_r, 1058, 1887, 1000, 2000), 1000, 2000);
} else {
return pulse = 1500; // Stop and hold position
}
if (abs(pulse - 1500) <= deadzone ) { // Anything in deadzone should stop the motor
return pulse = 1500; // Stop and hold position
} else {
return pulse;
}
}
void mpu9250() {
IMU.readAccelData(IMU.accelCount); // Read the x/y/z adc values
IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - IMU.accelBias[0];
IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - IMU.accelBias[1];
IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - IMU.accelBias[2];
IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values
IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes;
IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes;
IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes;
IMU.readMagData(IMU.magCount); // Read the x/y/z adc values
IMU.mx = (float)IMU.magCount[0] * IMU.mRes * IMU.factoryMagCalibration[0] - IMU.magBias[0];
IMU.my = (float)IMU.magCount[1] * IMU.mRes * IMU.factoryMagCalibration[1] - IMU.magBias[1];
IMU.mz = (float)IMU.magCount[2] * IMU.mRes * IMU.factoryMagCalibration[2] - IMU.magBias[2];
IMU.updateTime();// Must be called before updating quaternions!
/* Conversion to quaternions */
MahonyQuaternionUpdate(IMU.ax, IMU.ay, IMU.az, IMU.gx * DEG_TO_RAD, IMU.gy * DEG_TO_RAD, IMU.gz * DEG_TO_RAD, IMU.my, IMU.mx, IMU.mz, IMU.deltat);
IMU.delt_t = millis() - IMU.count;
if (IMU.delt_t > CheckTime) {
IMU.yaw = (atan2(2.0f * (*(getQ()+1) * *(getQ()+2) + *getQ()* *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1)* *(getQ()+1) - *(getQ()+2) * *(getQ()+2) - *(getQ()+3)* *(getQ()+3)))*RAD_TO_DEG;
IMU.pitch = (-asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ()* *(getQ()+2))))*RAD_TO_DEG;
if(SerialDebug) {
Serial.println("Pitch position:");
Serial.println();
Serial.print(IMU.pitch);
Serial.println(" ");
Serial.println("Yaw position:");
Serial.println();
Serial.print(IMU.yaw);
Serial.print(" ");
}
IMU.count = millis();
IMU.sumCount = 0;
IMU.sum = 0;
}
}
//////////////////////////////////// Case B: //////////////////////////////////////////
/* Main Control Parameters - The sensitivity or intensity of the test is adjusted here. */
#define CheckTime 240 // (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
#define SerialDebug true // Set to true to get Serial output for debugging
///////////////////////////////////////////////////////////////////////////////////////
/* 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 400000 // 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
/* Using MPU9250 named internal classes ad IMU function */
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL);
/* Definition of the connection pin between RC receiver and Arduino */
#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
/* Definition of the connection pin between SZDLT and Arduino */
#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 // Two G's of the driver are connected to the G of the Arduino
#define B1_PIN 5 // and one of the two 5Vs is connected to the VIN of the Arduino later to provide power.
#define B2_PIN 6
#define PB_PIN 7
/* Parameters for radio control */
int AUX1, THRO, RUDD, pulse;
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 Communications for Debug */
Serial.begin(115200); // Specify serial communication calls and baud rates
}
void loop() {
mpu9250();
/* Convert RC pulse to switch signal (0 and 1) */
AUX1 = constrain(map((pulseIn(AUX1_PIN, HIGH)), 1058, 1887, 0, 1), 0, 1);
if(SerialDebug) {
Serial.print("AUX1 =");
Serial.println(AUX1);
Serial.println();
}
if(AUX1 == 0) { // Tansmitter turned off or switch off
THRO == 0; // Stops the main gun un and down
RUDD == 0; // Stops the turret turn
}else{ // Tansmitter turned on and switch on
/* Convert RC pulse and write to SZDLT */
drive(THRO, RUDD);
if(SerialDebug) {
Serial.println("THRO PULSE =");
Serial.print(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
Serial.println();
Serial.println("RUDD PULSE =");
Serial.print(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
Serial.println();
}
}
}
void drive(int THRO, int RUDD) { // Positive for forward, negative for reverse
// Limit speed between -ConstrainLimit and ConstrainLimit
THRO = constrain(pulseTopulse(pulseIn(THRO_PIN, HIGH)), -constrainLimit, constrainLimit);
RUDD = constrain(pulseTopulse(pulseIn(RUDD_PIN, HIGH)), -constrainLimit, constrainLimit);
/* Set direction for motor A */
if ( THRO == 0 ) {
digitalWrite(A1_PIN, LOW);
digitalWrite(A2_PIN, LOW);
} else if ( THRO > 0 ) {
digitalWrite(A1_PIN, HIGH);
digitalWrite(A2_PIN, LOW);
} else {
digitalWrite(A1_PIN, LOW);
digitalWrite(A2_PIN, HIGH);
}
/* Set direction for motor B */
if ( RUDD == 0 ) {
digitalWrite(B1_PIN, LOW);
digitalWrite(B2_PIN, LOW);
} else if ( RUDD > 0 ) {
digitalWrite(B1_PIN, HIGH);
digitalWrite(B2_PIN, LOW);
} else {
digitalWrite(B1_PIN, LOW);
digitalWrite(B2_PIN, HIGH);
}
/* Set speed */
analogWrite(PA_PIN, abs(THRO));
analogWrite(PB_PIN, abs(RUDD));
}
/* Convert DX6 Transmitter pulse to servo pulse*/
int pulseTopulse(int pulse_r) {
if (pulse > 900) {
pulse = map(pulse_r, 1058, 1877, -constrainLimit, constrainLimit);
} else {
return pulse = 0; // Stop and hold position
}
if (abs(pulse - 0) <= deadzone ) { // Anything in deadzone should stop the motor
return pulse = 0; // Stop and hold position
} else {
return pulse;
}
}
void mpu9250() {
IMU.readAccelData(IMU.accelCount); // Read the x/y/z adc values
IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - IMU.accelBias[0];
IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - IMU.accelBias[1];
IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - IMU.accelBias[2];
IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values
IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes;
IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes;
IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes;
IMU.readMagData(IMU.magCount); // Read the x/y/z adc values
IMU.mx = (float)IMU.magCount[0] * IMU.mRes * IMU.factoryMagCalibration[0] - IMU.magBias[0];
IMU.my = (float)IMU.magCount[1] * IMU.mRes * IMU.factoryMagCalibration[1] - IMU.magBias[1];
IMU.mz = (float)IMU.magCount[2] * IMU.mRes * IMU.factoryMagCalibration[2] - IMU.magBias[2];
IMU.updateTime();// Must be called before updating quaternions!
/* Conversion to quaternions */
MahonyQuaternionUpdate(IMU.ax, IMU.ay, IMU.az, IMU.gx * DEG_TO_RAD, IMU.gy * DEG_TO_RAD, IMU.gz * DEG_TO_RAD, IMU.my, IMU.mx, IMU.mz, IMU.deltat);
IMU.delt_t = millis() - IMU.count;
if (IMU.delt_t > CheckTime) {
IMU.yaw = (atan2(2.0f * (*(getQ()+1) * *(getQ()+2) + *getQ()* *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1)* *(getQ()+1) - *(getQ()+2) * *(getQ()+2) - *(getQ()+3)* *(getQ()+3)))*RAD_TO_DEG;
IMU.pitch = (-asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ()* *(getQ()+2))))*RAD_TO_DEG;
if(SerialDebug) {
Serial.println("This value is a GUN position.");
Serial.println();
Serial.print(IMU.pitch);
Serial.println(" ");
Serial.println("This value is a Turrte position.");
Serial.println();
Serial.print(IMU.yaw);
Serial.print(" ");
}
IMU.count = millis();
IMU.sumCount = 0;
IMU.sum = 0;
}
}
Case 2: RC + Arduino + SZDLT(L298N) + MPU9250(measurement only)
I completed the sketch of the most basic "RC + Arduino + Motor controller + MPU9250(measurement only)" as follows.
The phenomenon of fine shaking at the neutral point of the transmitter stick was also fixed by setting deadzone.
This is a code that has proven integrated behavior.
This post will continue to be revised and updated in the future.
Youngjae
//////////////////////////////////// Case A: //////////////////////////////////////////
/* Main Control Parameters - The sensitivity or intensity of the test is adjusted here.*/
#define CheckTime 240 // (milliseconds) The shorter the time to check the displacement, the more vibration it can reflect.
#define deadzone 150 // (PWM) Anything between -150 and 150 is stop
#define SerialDebug true
///////////////////////////////////////////////////////////////////////////////////////
/* 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 400000 // 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
/* Using MPU9250 named internal classes ad IMU function */
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL);
/*To use Sabertooth(Motion Controller B) */
#include <Servo.h>
/* Definition of the connection pin between RC receiver and Arduino */
#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
/* Definition of the connection pin between Sabertooth and Arduino */
#define S1 2 // Arduino Pin 2 -> Sabertooth S1, Arduino GND -> Sabertooth 0V
#define S2 3 // Arduino Pin 3 -> Sabertooth S2, Arduino VIN <- Sabertooth 5V (OPTION)
/* Definition servo channel of Sabertooth */
Servo STS1; // To name the Sabertooth servo channel objects STS1 and STS2
Servo STS2; // Dip switch on are 2, 3, 5 The rest are off
/* Parameters for radio control */
int pulse;
int AUX1;
void setup() {
/* Define a Pin Using Arduino */
pinMode(THRO_PIN, INPUT);
pinMode(RUDD_PIN, INPUT);
pinMode(AUX1_PIN, INPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
/* Attach pulse width value to servo channel */
STS1.attach(S1, 1000, 2000); // Sabertooth accepts servo pulses from 1000us to 2000us.
STS2.attach(S2, 1000, 2000); // I need to specify the pulse widths in attach().
/* 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 Communications for Debug */
Serial.begin(115200); // Specify serial communication calls and baud rates
}
void loop() {
mpu9250();
/* Convert RC pulse to switch signal (0 and 1) */
AUX1 = constrain(map((pulseIn(AUX1_PIN, HIGH)), 1058, 1887, 0, 1), 0, 1);
if(SerialDebug) {
Serial.print("AUX1 =");
Serial.println(AUX1);
Serial.println();
}
if(AUX1 == 0) { // Tansmitter turned off or switch off
STS1.writeMicroseconds(1500); // Stops the main gun un and down
STS2.writeMicroseconds(1500); // Stops the turret turn
}else{ // Tansmitter turned on and switch on
/* Convert RC pulse and write to servo channel */
STS1.writeMicroseconds(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
STS2.writeMicroseconds(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
if(SerialDebug) {
Serial.println("THRO PULSE =");
Serial.print(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
Serial.println();
Serial.println("RUDD PULSE =");
Serial.print(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
Serial.println();
}
}
}
/* Convert DX6 Transmitter pulse to servo pulse*/
int pulseTopulse(int pulse_r) {
if (pulse > 900) {
pulse = constrain(map(pulse_r, 1058, 1887, 1000, 2000), 1000, 2000);
} else {
return pulse = 1500; // Stop and hold position
}
if (abs(pulse - 1500) <= deadzone ) { // Anything in deadzone should stop the motor
return pulse = 1500; // Stop and hold position
} else {
return pulse;
}
}
void mpu9250() {
IMU.readAccelData(IMU.accelCount); // Read the x/y/z adc values
IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - IMU.accelBias[0];
IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - IMU.accelBias[1];
IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - IMU.accelBias[2];
IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values
IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes;
IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes;
IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes;
IMU.readMagData(IMU.magCount); // Read the x/y/z adc values
IMU.mx = (float)IMU.magCount[0] * IMU.mRes * IMU.factoryMagCalibration[0] - IMU.magBias[0];
IMU.my = (float)IMU.magCount[1] * IMU.mRes * IMU.factoryMagCalibration[1] - IMU.magBias[1];
IMU.mz = (float)IMU.magCount[2] * IMU.mRes * IMU.factoryMagCalibration[2] - IMU.magBias[2];
IMU.updateTime();// Must be called before updating quaternions!
/* Conversion to quaternions */
MahonyQuaternionUpdate(IMU.ax, IMU.ay, IMU.az, IMU.gx * DEG_TO_RAD, IMU.gy * DEG_TO_RAD, IMU.gz * DEG_TO_RAD, IMU.my, IMU.mx, IMU.mz, IMU.deltat);
IMU.delt_t = millis() - IMU.count;
if (IMU.delt_t > CheckTime) {
IMU.yaw = (atan2(2.0f * (*(getQ()+1) * *(getQ()+2) + *getQ()* *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1)* *(getQ()+1) - *(getQ()+2) * *(getQ()+2) - *(getQ()+3)* *(getQ()+3)))*RAD_TO_DEG;
IMU.pitch = (-asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ()* *(getQ()+2))))*RAD_TO_DEG;
if(SerialDebug) {
Serial.println("Pitch position:");
Serial.println();
Serial.print(IMU.pitch);
Serial.println(" ");
Serial.println("Yaw position:");
Serial.println();
Serial.print(IMU.yaw);
Serial.print(" ");
}
IMU.count = millis();
IMU.sumCount = 0;
IMU.sum = 0;
}
}
//////////////////////////////////// Case B: //////////////////////////////////////////
/* Main Control Parameters - The sensitivity or intensity of the test is adjusted here. */
#define CheckTime 240 // (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
#define SerialDebug true // Set to true to get Serial output for debugging
///////////////////////////////////////////////////////////////////////////////////////
/* 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 400000 // 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
/* Using MPU9250 named internal classes ad IMU function */
MPU9250 IMU(MPU9250_ADDRESS, SDA, SCL);
/* Definition of the connection pin between RC receiver and Arduino */
#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
/* Definition of the connection pin between SZDLT and Arduino */
#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 // Two G's of the driver are connected to the G of the Arduino
#define B1_PIN 5 // and one of the two 5Vs is connected to the VIN of the Arduino later to provide power.
#define B2_PIN 6
#define PB_PIN 7
/* Parameters for radio control */
int AUX1, THRO, RUDD, pulse;
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 Communications for Debug */
Serial.begin(115200); // Specify serial communication calls and baud rates
}
void loop() {
mpu9250();
/* Convert RC pulse to switch signal (0 and 1) */
AUX1 = constrain(map((pulseIn(AUX1_PIN, HIGH)), 1058, 1887, 0, 1), 0, 1);
if(SerialDebug) {
Serial.print("AUX1 =");
Serial.println(AUX1);
Serial.println();
}
if(AUX1 == 0) { // Tansmitter turned off or switch off
THRO == 0; // Stops the main gun un and down
RUDD == 0; // Stops the turret turn
}else{ // Tansmitter turned on and switch on
/* Convert RC pulse and write to SZDLT */
drive(THRO, RUDD);
if(SerialDebug) {
Serial.println("THRO PULSE =");
Serial.print(pulseTopulse(pulseIn(THRO_PIN, HIGH)));
Serial.println();
Serial.println("RUDD PULSE =");
Serial.print(pulseTopulse(pulseIn(RUDD_PIN, HIGH)));
Serial.println();
}
}
}
void drive(int THRO, int RUDD) { // Positive for forward, negative for reverse
// Limit speed between -ConstrainLimit and ConstrainLimit
THRO = constrain(pulseTopulse(pulseIn(THRO_PIN, HIGH)), -constrainLimit, constrainLimit);
RUDD = constrain(pulseTopulse(pulseIn(RUDD_PIN, HIGH)), -constrainLimit, constrainLimit);
/* Set direction for motor A */
if ( THRO == 0 ) {
digitalWrite(A1_PIN, LOW);
digitalWrite(A2_PIN, LOW);
} else if ( THRO > 0 ) {
digitalWrite(A1_PIN, HIGH);
digitalWrite(A2_PIN, LOW);
} else {
digitalWrite(A1_PIN, LOW);
digitalWrite(A2_PIN, HIGH);
}
/* Set direction for motor B */
if ( RUDD == 0 ) {
digitalWrite(B1_PIN, LOW);
digitalWrite(B2_PIN, LOW);
} else if ( RUDD > 0 ) {
digitalWrite(B1_PIN, HIGH);
digitalWrite(B2_PIN, LOW);
} else {
digitalWrite(B1_PIN, LOW);
digitalWrite(B2_PIN, HIGH);
}
/* Set speed */
analogWrite(PA_PIN, abs(THRO));
analogWrite(PB_PIN, abs(RUDD));
}
/* Convert DX6 Transmitter pulse to servo pulse*/
int pulseTopulse(int pulse_r) {
if (pulse > 900) {
pulse = map(pulse_r, 1058, 1877, -constrainLimit, constrainLimit);
} else {
return pulse = 0; // Stop and hold position
}
if (abs(pulse - 0) <= deadzone ) { // Anything in deadzone should stop the motor
return pulse = 0; // Stop and hold position
} else {
return pulse;
}
}
void mpu9250() {
IMU.readAccelData(IMU.accelCount); // Read the x/y/z adc values
IMU.ax = (float)IMU.accelCount[0] * IMU.aRes; // - IMU.accelBias[0];
IMU.ay = (float)IMU.accelCount[1] * IMU.aRes; // - IMU.accelBias[1];
IMU.az = (float)IMU.accelCount[2] * IMU.aRes; // - IMU.accelBias[2];
IMU.readGyroData(IMU.gyroCount); // Read the x/y/z adc values
IMU.gx = (float)IMU.gyroCount[0] * IMU.gRes;
IMU.gy = (float)IMU.gyroCount[1] * IMU.gRes;
IMU.gz = (float)IMU.gyroCount[2] * IMU.gRes;
IMU.readMagData(IMU.magCount); // Read the x/y/z adc values
IMU.mx = (float)IMU.magCount[0] * IMU.mRes * IMU.factoryMagCalibration[0] - IMU.magBias[0];
IMU.my = (float)IMU.magCount[1] * IMU.mRes * IMU.factoryMagCalibration[1] - IMU.magBias[1];
IMU.mz = (float)IMU.magCount[2] * IMU.mRes * IMU.factoryMagCalibration[2] - IMU.magBias[2];
IMU.updateTime();// Must be called before updating quaternions!
/* Conversion to quaternions */
MahonyQuaternionUpdate(IMU.ax, IMU.ay, IMU.az, IMU.gx * DEG_TO_RAD, IMU.gy * DEG_TO_RAD, IMU.gz * DEG_TO_RAD, IMU.my, IMU.mx, IMU.mz, IMU.deltat);
IMU.delt_t = millis() - IMU.count;
if (IMU.delt_t > CheckTime) {
IMU.yaw = (atan2(2.0f * (*(getQ()+1) * *(getQ()+2) + *getQ()* *(getQ()+3)), *getQ() * *getQ() + *(getQ()+1)* *(getQ()+1) - *(getQ()+2) * *(getQ()+2) - *(getQ()+3)* *(getQ()+3)))*RAD_TO_DEG;
IMU.pitch = (-asin(2.0f * (*(getQ()+1) * *(getQ()+3) - *getQ()* *(getQ()+2))))*RAD_TO_DEG;
if(SerialDebug) {
Serial.println("This value is a GUN position.");
Serial.println();
Serial.print(IMU.pitch);
Serial.println(" ");
Serial.println("This value is a Turrte position.");
Serial.println();
Serial.print(IMU.yaw);
Serial.print(" ");
}
IMU.count = millis();
IMU.sumCount = 0;
IMU.sum = 0;
}
}
Last edited by Youngjae Bae on Thu Jul 09, 2020 12:35 am, edited 13 times in total.
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
I installed a vibration-proof mount of a small pneumatic compressor to be installed in the turret.
And I made a servotrigger for the recoil movement.
This week, I'll finally be able to complete a very nice Recoil feature.
I'll share the motion with you in a video.
Youngjae
And I made a servotrigger for the recoil movement.
This week, I'll finally be able to complete a very nice Recoil feature.
I'll share the motion with you in a video.
Youngjae
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
Completion of pneumatic recoil system!
I've finally completed a complete retrofit of the Recoil system.
Next, the main gun smoke will be implemented using recoil exhaust by connecting the electronic cigarette power to the servotrigger.
Youngjae
I've finally completed a complete retrofit of the Recoil system.
Next, the main gun smoke will be implemented using recoil exhaust by connecting the electronic cigarette power to the servotrigger.
Youngjae
-
- Posts: 2180
- Joined: Wed Nov 15, 2017 1:43 pm
- Location: Malta
- Has liked: 762 times
- Been liked: 1738 times
Re: Chieftain kit arrival
There seems to be a delay between the gun sound and the actual recoil. That blue servo arm takes some time to activate the pneumatic switch.
Vince
Vince
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
As Vince points out, there is a slight delay in the sound and motion of the main gun.
This is the result of the incorrect selection of the solenoid valve for pneumatic use and temporary installation.
Today I program the motion angle of the drier servo motor to reduce the difference slightly.
But when the new solenoid valve arrives, it will be replaced.
My Chieftain came back in the morning running about a kilometer through my village.
I was impressed by the way young children liked it very much.
In the afternoon, I implemented various movements in the yard under the summer sun.
I had a great time today because of my chieftain.
Youngjae
-
- Posts: 2180
- Joined: Wed Nov 15, 2017 1:43 pm
- Location: Malta
- Has liked: 762 times
- Been liked: 1738 times
Re: Chieftain kit arrival
Synchronization between the sound and recoil looks so much better now.
Always amazed at how fast the turret and barrel moved.
Sent you something via email.
Vince
Always amazed at how fast the turret and barrel moved.
Sent you something via email.
Vince
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times
Re: Chieftain kit arrival
I got a very nice present from Vince.
I'll print it out in the office today and install it in my Chieftain.
Once again, thank Vince.
Youngjae
I'll print it out in the office today and install it in my Chieftain.
Once again, thank Vince.
Youngjae
- Youngjae Bae
- Posts: 274
- Joined: Sun Jan 27, 2019 12:01 am
- Location: South Korea
- Has liked: 747 times
- Been liked: 594 times