My first use of the Arduino PID.

My balancing robot project has gotten me to a PID on speed. But it is pure bang-bang. I am hoping someone has an idea that I do not.

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID2 myPID(&Input, &Output, &Setpoint, 1, 1, 1, DIRECT);  

void PID_speed_compute(void){
  Speed = 8.0/127.0*(double)(nchuk.joyY()-127);   //  Speed Desired;  Desired Speed
  Speed_filter   = (1-0.01)*Speed_filter + 0.01*Speed;  //  Filtered Speed
  Speed_filter = constrain(Speed_filter , -8, 8);  
  
  Setpoint = Speed_filter;

  speed_now = ( Encoder_2.getCurrentSpeed() - Encoder_1.getCurrentSpeed() ) /2;

  Input = speed_now;
  myPID.Compute();
  PID_angle.Setpoint =  RELAX_ANGLE +  Output;

https://www.dropbox.com/s/5j59mrltm79ntyv/Balancing%20Robot%20Graph2.pdf?dl=0![](https://www.dropbox.com/s/5j59mrltm79ntyv/Balancing%20Robot%20Graph2.pdf?dl=0)

Your code is incomplete.

The entire program is 3000 lines long. What I am including is only the part that I am having trouble with. I also have a good graphic that I am trying to post.

The graphic is very helpfull. But, I cannot seem to post it.

Balancing Robot Graph2.pdf (101 KB)

The entire program is 3000 lines long.

That is the problem. Or large part of the problem.

If you make your picture .gif or .jpg then it can be inserted inline.

Image Guide

My balancing robot project is to use the MakeBlock build & firmware with a Nintendo nunchuck for control. The firmware has code for some 60-70 devices/sensors and the balancing code. It is 3000 lines long. I only use the code for the accelerator/gyroscope (MPU6050). This amounts to about 100 lines of code. Getting Left-Right control only took a moment. I still have not managed to get speed control to work. Makeblock's concept is to use a PID (PI) for speed and another for balance. Makeblock's speed PID links the nunchuck to the robot's instantaneous actual speed. This may initially seem like a good idea, but makes things entirely to complicated. Desired speed is in no way dependent on actual speed. And, an additional PID adds three more values to be tuned. Additionally, the speed PID, converts a smooth filtered speed to something that almost looks like PWM. (as shown in the graph) I do not see that Makeblock's concept of a speed PID is beneficial.

Does the wisdom of the forum agree?

Didn’t work. Edit your post until it does work. Use “modify” instead of “quick edit” to get the full editor with all the buttons.

Inline graphic is here (?)

https://www.dropbox.com/s/gywr29pmnj4qz3z/Balancing%20Robot%20Graph3.jpg?dl=0

https://www.dropbox.com/s/gywr29pmnj4qz3z/Balancing%20Robot%20Graph3.jpg?dl=0

But the graph will not go inline. Some security issue.

Quote and code tags don't help. You were so close but now it seems the .jpg you attached is no longer there.

Dropbox has privite links and public links. They both work for me. This one seems to be public to all.

https://www.dropbox.com/s/gywr29pmnj4qz3z/Balancing%20Robot%20Graph3.jpg?dl=0

I get the message

There was a problem during the uploading of Balancing Robot Graph3.jpg. Your post has been made, however the above attachment was not attached. Please use the Back button to edit your post and submit any required changes. Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator.

Upload it from your computer, not dropbox.

This is the file on my computer. I will post this and then edit to get the Arduino link. I get the same error.

There was a problem during the uploading of Balancing Robot Graph3.jpg.
Your post has been made, however the above attachment was not attached. Please use the Back button to edit your post and submit any required changes.
Your attachment has failed security checks and cannot be uploaded. Please consult the forum administrator.

This is a test. I opened the DropBox image and used my browser to copy the image address. Then I cropped it after jpeg

and pasted that into the Forum image link - with the following result

|500x297

The test was successful and it exactly followed the instructions in the above Image Guide link.

...R

PID2 myPID(&Input, &Output, &Setpoint, 1, 1, 1, DIRECT);

This line is creating a PID object with all three coefficients set to 1.0. There is no way for anyone here to have the first clue what the CORRECT values for the coefficients are for your system, but I can state with absolutely certainty that setting all three to 1.0 is NOT correct. The correct coefficients are totally dependent on the actual physical characteristics of your specific hardware, and MUST be individually tuned ON THAT HARDWARE. Even two theoretically identical sets of hardware will often require different coefficients, due to minor differences in friction, and other phystical factors. Without proper tuning, you will never get acceptable behavior.

Regards, Ray L.

Thanks Robin.

So what is that chart? Desired behaviour? Actual-but-undesired?

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID2 myPID(&Input, &Output, &Setpoint, 1, 1, 1, DIRECT);  

void PID_speed_compute(void){
  Speed = 8.0/127.0*(double)(nchuk.joyY()-127);   //  Speed Desired;  Desired Speed
  Speed_filter   = (1-0.01)*Speed_filter + 0.01*Speed;  //  Filtered Speed
  Speed_filter = constrain(Speed_filter , -8, 8);  
  
  Setpoint = Speed_filter;

  speed_now = ( Encoder_2.getCurrentSpeed() - Encoder_1.getCurrentSpeed() ) /2;

  Input = speed_now;
  myPID.Compute();
  PID_angle.Setpoint =  RELAX_ANGLE +  Output;

The code is earlier in the post.

The values are just a filtering of the raw nunchuk reading.

And tuning is hard. So, using a speed PID when it is not required just adds unnecessarily to the complexity. But, as a new user, this puts me in disagreement with the Makeblock experts. I just find the speed PID to be the wrong concept.

CLplaneguy:
Does the wisdom of the forum agree?

That is from Reply #5 and, combined with the graph, I don’t understand it at all.

What exactly is the role of the NunChuck?
What sort of data does it produce?
What do you want to do with that data?

…R

I have an error for posting a graphic that does not pass a security check. The graphic is at dropbox. It worded for a test graph. This file is way under the 2k limit.

Your image has personally identifying information which often includes the exact GPS position of the camera when the image was captured. Images uploaded to this forum cannot include such information.

This JPG is a graph of Arduino data produced with Veusz.