Hi,
I am currently making a paraglider(Several cons and pros for that approach, but I wanted todo something different:) I want to use pixhawk to control it. So the paraglider is like a plane with rudder,elevator and motor. My problem is that the rudder is operated by a brushless motor with a gearbox and a potentiometer as feedback. So I could attach an arduino nano read in the pwm signal from pixhawk and potentiometer and generate a modified pwm out. However I would rather modify the arduplane code, the question is which file to modify:)
So if the potentiometer reads out a value of 512 the esc should get a pulse of 1500 if the stick is in neutral, if the stick is slightly to the left then the potentiometer should read less then 512 and so on.
My pseudo code is shown below:
void setup() {
// put your setup code here, to run once:
deadVal = 50; //if we are close to desired value we will
//save energy by not running motor, i.e a dead pulsewidt
kp = 0.5; //gain to adjust motor input
}
void loop() {
// put your main code here, to run repeatedly:
actualVal = map(analogRead(A0),1000,2000);
desiredVal = pwmRead();//Where can this value be read??
if (abs(desiredVal-actualVal)<deadVal) {
pulseOut(1500);
}
else if (desiredVal<actualVal) {
pulseOut(1500-kp*(actualVal-desiredVal))
}
else{
pulseOut(1500+kp*(desiredVal-actualVal))
}
}
Any help will be highly appreciated.
Replies