Code breakdown and explaination

Re: Code breakdown and explaination

Postby jeruw » Thu Mar 19, 2015 10:34 pm

I wasn't sure about the joySt.buttons inclusion. Figured that might be an issue. I'll remove it from there.

I did see the reset every loop with an earlier bit of example code. Testing with some debug statements the code I uploaded appeared to be maintaining the correct state. throttleButtonState reads as one on a button press. When that reads as one the code switches the value of throttleState using the If-elseif block. Then an if statement checks to see if throttleState is triggered to 1 (locked) and overwrites the axis.

Obviously I need to test this in flight still, but at least with debugging it seemed to be behaving the way I wanted. That being that pressing the button will trigger a state change.
jeruw
 
Posts: 80
Joined: Tue Feb 17, 2015 3:10 pm

Re: Code breakdown and explaination

Postby zdayton » Fri Mar 20, 2015 2:12 am

You aren't seeing the issue because there is a 1 sec loop delay while in debug mode. Meaning the loop only activates once every second. But if you hold down the button for 10 seconds you will see that the joystick state toggles every second, aka every iteration of the loop. Once you remove the loop delay, it will toggle back and forth continuously, and there is no way of predicting what state it will be in when you remove your finger from the button.
zdayton
Site Admin
 
Posts: 81
Joined: Wed Dec 24, 2014 6:20 am

Re: Code breakdown and explaination

Postby jeruw » Fri Mar 20, 2015 2:28 am

I'm actually flying with that code right now and it's working correctly. I did have to remove the debug statement, that delay was killer on throttle response ;). But otherwise the code is working as I expected based on my tests with the serial monitor. Take another look at it.

After playing around with it, I'm tempted to only lock Z and maybe X but keep Y free. Letting go of the handle should still throttle to 0 and then forward and reverse would still function as a regular throttle. At least in ED it can be finicky to have all 3 axis unlocked when you jump to supercruise. I get "align with target" warnings frequently till I jostle to the left or right.
jeruw
 
Posts: 80
Joined: Tue Feb 17, 2015 3:10 pm

Re: Code breakdown and explaination

Postby jeruw » Fri Mar 20, 2015 2:38 pm

I flew for a few hours last night and the throttle lockout was working well. I could fly into an area, click that and all throttle input would go to 0. I'd just sit in space silently. Clicking the button a second time would unlock the throttle.

I pushed a couple changes to the fork on Github this morning. I set debug to false again in case anyone tries the code. I should probably reset the pivot and pushrod lengths as well I suppose. I added a few comments as well. The final thing I did was tweak the throttle lock to only 0 Z and X. I'll try flying with that as soon as I can, but my expectation would be that it would make the Delta behave like a standard hotas throttle. Nullifying any vertical or horizontal thrust input but allowing changes to main engine throttle. This would still let you lock out the system in supercruise or an asteroid belt and expect that you could let go of the controls and your ship isn't going to start drifting in some random direction (up, usually). But allow you to use the control to throttle up for jump into supercruise or to control speed in supercruise.
jeruw
 
Posts: 80
Joined: Tue Feb 17, 2015 3:10 pm

Re: Code breakdown and explaination

Postby Trollbug » Sat Mar 21, 2015 4:59 am

Yes, it's a good idea .
Trollbug
 
Posts: 7
Joined: Wed Jan 07, 2015 9:26 pm

Re: Code breakdown and explaination

Postby zdayton » Sat Mar 21, 2015 8:45 pm

I want to do a couple different modes I think. All on the same button. Something like:

Single press: Toggle throttle lock - lock throttle at current position
Double Press: Lock throttle at zero
Press and hold: Lock x and z while holding, or maybe do an expanded deadzone for high precision flying. This was inspired after trying to scoop cargo in E:D, which is quit difficult with the delta throttle normally.
zdayton
Site Admin
 
Posts: 81
Joined: Wed Dec 24, 2014 6:20 am

Re: Code breakdown and explaination

Postby Nemesisghost » Thu Apr 09, 2015 12:49 am

So the way to have a reliable toggle is to use interrupts. What I'm in the process of doing is having a button tied to an interrupt pin(pin 7 in my case) that toggles a boolean. Then in my loop I check that boolean, if it's one value then I'll turn on a LED & set my throttle to 0, if it's the other then it functions as normal. Since I also want to be able to recalibrate the z-axis when I turn it back on, I'll be setting an initialize flag when I flip from Off to On in my interrupt method. Then my loop can check that & re-initialize at that point.

To see a bit of what I'm working towards, here's my test code.
Code: Select all
int outPin = 6;
int inPin = 7;
int interrupt = 4;
volatile bool state = true;

void setup()
{
  pinMode(outPin, OUTPUT);
  pinMode(inPin, INPUT_PULLUP);
  attachInterrupt(interrupt, blink, FALLING);
//  Serial.begin(9600);
}

void loop()
{
  if(state)
    digitalWrite(outPin, HIGH);
  else
    digitalWrite(outPin, LOW);
}

void blink() {
  state = !state;
//  Serial.println("State Changed");
}
Nemesisghost
 
Posts: 14
Joined: Thu Apr 09, 2015 12:44 am

Re: Code breakdown and explaination

Postby Nemesisghost » Thu Apr 09, 2015 12:53 am

Oh, I forgot to add. The Arduino Pro Micro has 5 pins with interrupt capabilities(0, 1, 2, 3, 7). All but 7 are tied to other functionality, like SPI & I2C. When attachingInterrupt, you'll want to use either RISING or FALLING, so that it only fires once per button press. All the others will fire 1x when pressed & 1x when released.
Nemesisghost
 
Posts: 14
Joined: Thu Apr 09, 2015 12:44 am

Previous

Return to Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron