Ok, take the pitch calculation. Now that you have +/- error values depending on whether the tri is pitching up or down, when that value is fed to the PID it's output will also change.
PID_pitch_output will sometimes be negative and sometimes positive depending on the pitch error. So there's no need for "if the output is positive" etc.
If you forget about whether it's a tri, quad, hex or whatever and just treat it as a generalized multicopter with pitch, roll, yaw (and vertical speed), you can do all the PID stuff in those three axes then map it to the motor commands at the end. Here's the motor command calc for a tricopter from the Aeroquad code:
Notice your pitch calc for the rear motor is the same apart from the scaling factor. Your front motor calcs are almost correct except with one you add the roll command and the other you subtract the roll command, since one motor has to lift up while the other goes down.
It may be due to this line. Goes from 0 - 180, maybe I should change it to -180 - 180.
Code:
myPID_Pitch_Plus.SetOutputLimits(0,180);
However if that will fix it, should I make a IF statement (for the roll axis)
You shouldn't need an if statement. But yes map the stick values so 0 degrees is center position. So you get positive or negative values when it's rolled to the left or right. And the same for pitch, yaw. Same with sensors - when the tri is perfectly horizontal read that as 0 deg pitch and roll.
Is it drifting off-course because it's overshooting the target heading? For example, say it's pointing 90 deg (East) and the target heading is 0 deg (North). Does it turn anti-clockwise but go too far?
If the thrust vector is offset to either side then the vessel is accelerating in roll and you probably want to try to bring it back into balance.
That's why I said use PID controllers. The only problem with that is if the payload (mass) changes significantly, such as a different pilot who ways more, it would (probably) have to use different PID coefficients.
Peter, what about using differential pressure sensors to measure ride height like I mentioned? Don't you think that would work?
I just tried it on the laptop, telling the site to remember me, closed firefox then opened it again and the timezone was correct. But after logging out and back in it reset back to offset 5 instead of 16. I've cleared cookies etc several times but it keeps happening.
I searched about this but couldn't find anything. I'm in Australia so set the Time Offset to 16. It works fine at first. But after coming back to the site later on the offset is put back to 5. This happens on both my laptop and desktop. I'm using Firefox on both. Is this a known problem?
Yes, I would very much like it to lean in turns but how with bolt upright electronics.
That's what I thought. Have a look at this simulation I did a while ago:
I was only animating the target lean angle of the bike. A PID controller took care of applying torque to a motor on the forks, steering to keep the bike at the commanded angle.
But in your case, if the 4 foils are independently controlled couldn't you think of it as a quadcopter (with rudder) with altitude and attitude hold? Except for yaw which is manually controlled. Then couple the yaw to roll through a nested PID. It would be fun (and wet) tuning it
If you do this, don't fill it with hydrogen in this manner.
I agree. Although we used to fill 75 liter garbage bags using a slightly different (but just as dangerous) reaction. Everything was weighed accurately and cold water baths used to control the reaction rate. But I studied chemistry so was aware of the dangers, and what was the quickest way to the shower, and to the hospital. Still a silly thing to do.
BTW, hydrogen will ignite over a huge range of O2 concentrations. Even a few percent of oxygen could likely turn your blimp into a bomb.
If you do decide to make this with Arduino and H-Bridge shields, I wrote this code the other day as a learning experience (I'm new to Arduino) until I realized you wanted a non-MCU solution. Don't have an H-Bridge to test but seems to give proportional bi-directional control. This is just for the "horizontal" motor.
Code:
int deadZone = 50; // joystick deadzone rangec int maxPWMValue = 255; // maximum PWM value. 255 for built-in PWM int horizPotPin = A0; // Analog pin for horizontal pot sense
int horizPWMPin = 9; // Horiz motor speed control connected to this pinr int horizDirPin = 2; // directional control connected here. HIGH = forward, LOW = reverse
void loop() { int horizPWM = 0; // holds the pwm output for 'horizontal' motor boolean forwardDir = true; // direction for 'horizontal' motor. true = forward, false = reverse
// read horizontal pot value int horizPot = analogRead(horizPotPin);
// map the analog value of 0..1023 to -255..+255 // If the direction and speed go in the wrong direction compared to joystick movement, // just switch the sign of the last two parameters int h = map(horizPot, 0, 1023, -maxPWMValue, maxPWMValue);
// check if joy in reverse position if (h < 0) { forwardDir = false; h *= -1; }
// only set final PWM output if joy is outside of deadzone range if (h > deadZone) horizPWM = h;
// set pwm and direction digitalWrite(horizDirPin, forwardDir); analogWrite(horizPWMPin, horizPWM);