problem in balancing inverted pendulum using web_camera

hi, currently im doing this project about balancing 3D inverted pendulum using web-camera on a moving cart . I'm on the implementation stage at the moment and would like to use arduino uno (all the modeling and simulation have been done in matlab simulink). so far i used openCV in C++ to measure the angle tilted by the pendulum and arduino uno to do the control (PID) .

problems

  1. how can i interface between C++ and arduino (read the angle from C++)
  2. is arduino uno capable of doing the PID calculations
  3. in my design , the output should be the speed of the motors and position of the cart . how can I archive this in arduino ? would i need to implement two pid function
  4. do i need to implement filter(kalman ) in the control..? as i have already implement one in the vision code (C++)

thanks in advanced

  1. how can i interface between C++ and arduino (read the angle from C++)

The easiest way is to use the serial interface you also use for programming the Arduino. What platform does the C++ code run on?

  1. is arduino uno capable of doing the PID calculations

You haven't told us about the speed you want to achieve but in most situations this is answered with "yes".

in my design , the output should be the speed of the motors and position of the cart . how can I archive this in arduino ?

Do you have a picture or drawing of your setup? Although I have some imagination about how this looks like I don't know exactly which motors or carts you're talking about.

  1. do i need to implement filter(kalman ) in the control..? as i have already implement one in the vision code (C++)

How about posting your current code? We cannot answer this as long as we don't know more details about the project (see point 3).

hi , thanks for getting back .
What platform does the C++ code run on?

-visual studio

You haven't told us about the speed you want to achieve but in most situations this is answered with "yes".
i would like to archive the speed of just below 1sec, the inverted pendulum pendulum im going to balance has length of 1.5m
and weigh=0.7kg

Do you have a picture or drawing of your setup? Although I have some imagination about how this looks like I don't know exactly which motors or carts you're talking about.[/b]
- the cart is made up of four omni wheels so that it can move in 3D and motor are dc
How about posting your current code? We cannot answer this as long as we don't know more details about the project
,//control code//
//Define Variable
int MotorIN_A = 8;
int MotorIN_B = 12;
int MotorPWM = 11; // ENABLE to digital pin 11
int sensorPin = ; // input from C++ , im not sure what to put it here
/working variables/
double PV, Output, Setpoint;
double kp, ki, kd;
double errSum, lastErr;
void setup(){
//Controller Parameter
kp = 0.0;
ki = 0.0;
kd = 0.0;
pinMode(Motor_INA1, OUTPUT);
pinMode(Motor_INB1, OUTPUT);
pinMode(Motor_PWM, OUTPUT);
pinMode(, INPUT); // im not sure what to put here
}
void loop(){
sensorValue = digitalRead(sensorPin); //read the value
Setpoint = 0 ; //zero degree vertical upright
compute(); // Find controller output
//Send command to DC motor
if(Output > 0) {
analogWrite(MotorPWM, Output);
CC();
}
else if(Output<-0){
analogWrite(MotorPWM, -Output);
CCW();
}
else{
STOP();
}
Motor Control Function
void CC(){
digitalWrite(MotorIN_A,HIGH);
digitalWrite(MotorIN_B,LOW);
}
void CCW(){
digitalWrite(MotorIN_A,LOW);
digitalWrite(MotorIN_B,HIGH);
}
void STOP(){
analogWrite(MotorPWM, 0);
digitalWrite(MotorIN_A,LOW);
digitalWrite(MotorIN_B,LOW);
}
//Compute controller output by PID algorithm
void compute()
{
/How long since we last calculated/
double dT = (double)(now - lastTime); //Our Sampling time
/Compute all the working error variables/
double error = Setpoint - PV;
errSum += (error * dT);
double dErr = (error - lastErr) / dT;
/Compute PID Output/
Output = kp * error + ki * errSum + kd * dErr;
/Max 255, Min -255/
if(Output>255){Output = 255;}
else if(Output <-255){Output = -255;}
else{}
/Remember some variables for next time/
lastErr = error;
lastTime = now;
}
thanks

-visual studio

That probably means Windows. I'm the Linux guy so I'm not very helpful on the PC side for you. Find out how to access the serial interface from Visual Studio and how to send values to it.

i would like to archive the speed of just below 1sec, the inverted pendulum pendulum im going to balance has length of 1.5m
and weigh=0.7kg

1 second is incredibly long in computer terms, so if you want to correct your values just once a second and Arduino is more than powerful enough. Although I doubt a bit that one second reaction time is matching your needs.

  • the cart is made up of four omni wheels so that it can move in 3D and motor are dc

That doesn't help much. Please take a picture and post it. I cannot imagine how you can move in 3D with just 4 wheels.

What exactly do you expect to get from the "sensorPin"? Just an on/off value? What should it be used for? Where do you set PV? What do you want sensorValue to be used for?