Hello,
I am from India, Myself Raju Patel, I Started planning to build a custom self balancing wheel.
The problem which I am facing is that, the controller I bought is not compatible or faulty, So I ordered another one which is working fine but has missing some essential functions. and as you know the controller is the brain of my Project, which will control Forward, Backward, Speed, Stability and many other functions
I have 48v lithium battery and want to run 36v 500watt BLDC motor, for self balancing Wheel project, I almost done with my frame welding and all stuff, But stuck in controller, I tried with 48v 350watt Bldc controller, it works with 36v 500w motor but it do not support reverse function so, I brought same controller again and connect both simultaneously and one of them with reverse configuration connection, So it worked to rotate two direction but it need motor completely stop to change the direction of motor and that is the problem for self balancing scooter. because for self balancing, motor need to stop or slow down quickly and should run reverse as quickly as possible.
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);
float elapsedTime, time, timePrev;
float rad_to_deg = 180 / 3.141592654;
float PID, pwmLeft, pwmRight, error, previous_error;
float pid_p = 0;
float pid_i = 0;
float pid_d = 0;
/////////////////PID CONSTANTS/////////////////
double kp = 3.55; //3.55
double ki = 0.005; //0.003
double kd = 2.05; //2.05
///////////////////////////////////////////////
double throttle = 1000; //initial value of throttle to the motors
float desired_angle = 0; //This is the angle in which we whant the
//balance to stay steady
void setup() {
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
time = millis();
}
void loop() {
/////////////////////////////I M U/////////////////////////////////////
timePrev = time; // the previous time is stored before the actual time read
time = millis(); // actual time read
elapsedTime = (time - timePrev) / 1000;
mpu6050.update();
//Serial.print("angleX : ");
//Serial.print(mpu6050.getAngleX());
error = mpu6050.getAngleX() - desired_angle;
pid_p = kp * error;
if (-3 < error < 3)
{
pid_i = pid_i + (ki * error);
}
pid_d = kd * ((error - previous_error) / elapsedTime);
PID = pid_p + pid_i + pid_d;
//Serial.print(PID);
//Serial.print("\t");
//Serial.println(mpu6050.getAngleX());
if (PID < -1000)
{
PID = -1000;
}
if (PID > 1000)
{
PID = 1000;
}
pwmLeft = throttle + PID;
pwmRight = throttle - PID;
//Right
if (pwmRight < 1000)
{
pwmRight = 1000;
}
if (pwmRight > 2000)
{
pwmRight = 2000;
}
//Left
if (pwmLeft < 1000)
{
pwmLeft = 1000;
}
if (pwmLeft > 2000)
{
pwmLeft = 2000;
}
pwmRight = map(pwmRight, 1000, 2000, 0, 255);
analogWrite(10, pwmRight);
pwmLeft = map(pwmLeft, 1000, 2000, 0, 255);
analogWrite(11, pwmLeft);
Serial.print(pwmRight);
Serial.print("\t");
Serial.print(pwmLeft);
Serial.print("\t");
Serial.println(mpu6050.getAngleX());
previous_error = error; //Remember to store the previous error.
}
And one more problem was... i used arduino UNO for PWM signals to run both controllers, but they starts at 30% PWM signal with high speed directly (i need smooth start for self balancing scooter) , which is again controller's fault. both are chinese controllers, i don't know it's hardware or driver configuration.
So, I Thought to make a custom one for my project, But I am not having any expertise or prior knowledge about making a new custom tailored controller, where to put required value of capacitor resistor transistor (I opened one old BLDC controller but didn't get it anything why this big capacitors and small resistors are there, where they are connected and all that), I tried reaching out Google but it shows to buy very much costly controllers.
As my project was based on Arduino so I posted these request on Arduino Forum.
For balancing with MPU sensor, arduino forum already helped me a lot, thank you so much for that.
Could please anyone pcb circuit designer help me out, In big trouble ?
Seriously It would be great help if you help me out
Thank you again.