-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copter: First take on takeoff script #19
base: skyviper-latest
Are you sure you want to change the base?
Conversation
Before I look closely at this PR - have you reviewed ArduCopter's pre-existing take-off code? It was added for the 3DR Solo vehicle, and is currently in use on it. This is the start of relevant code in alt-hold mode: https://github.com/ardupilot/ardupilot/blob/master/ArduCopter/control_althold.cpp#L92 |
No I haven't. I shall look into it. Tridge mention that we should do it in toy_mode.cpp as there is already a throttle_control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need to stare at this state machine a lot after these changes are made.
I've a feeling we can get into funny states ATM.
Also, watch out for whitespace issues. There's trailing whitespace added in this patch (ask your editor to highlight it). You're missing the odd space here and there between closing prens and opening braces (if (foo){
).
ArduCopter/toy_mode.cpp
Outdated
@@ -405,6 +405,9 @@ void ToyMode::update() | |||
} else { | |||
throttle_low_counter = 0; | |||
} | |||
|
|||
bool takeoff_cancelled = throttle_at_min || throttle_near_max; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
takeoff_cancelled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why cancel takeoff if the throttle is near max? Is this so people can takeoff conventionally after pressing the button?
If I'm asking the question it probably deserves a comment :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably just use outside-deadzone instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check should probably move into the subroutine.
ArduCopter/toy_mode.cpp
Outdated
@@ -405,6 +405,9 @@ void ToyMode::update() | |||
} else { | |||
throttle_low_counter = 0; | |||
} | |||
|
|||
bool takeoff_cancelled = throttle_at_min || throttle_near_max; | |||
handle_takeoff_cmd(right_action_button,takeoff_cancelled); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be checking for a specific toy_mode_action, not checking whether the right button has been pressed.
So something like an ACTION_TAKEOFF_OR_CANCEL_TAKEOFF_OR_RTL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speaking of which, the button should cancel the takeoff if pressed a second time while it is still on the ground (IMO), like the current arm/disarm/rtl functionality does.
Also, need the RTL functionality....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, - in our next years drone. on the TX for copters that has GPS there is a button to toggle between launch and land and a separate button for RTL.
I was thinking maybe do this - ACTION_TAKEOFF_CANCEL_TAKEOFF_LAND instead.
ArduCopter/toy_mode.cpp
Outdated
@@ -818,6 +821,19 @@ void ToyMode::throttle_adjust(float &throttle_control) | |||
float p = (now - throttle_arm_ms) / float(soft_start_ms); | |||
throttle_control = MIN(throttle_control, throttle_start + p * (1000 - throttle_start)); | |||
} | |||
|
|||
//takeoff script to handle the throttle_control. takeoff_cmd is handled by handle_takeoff_cmd() | |||
const float takeoff_throttle_cmd = 700.0f; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm not a great fan of having relying on a timer with a constant like this. I think frame variations (bodgy motors) and environmental conditions (wind!) could lead to some unfortunate flight characteristics.
However, the current ArduCopter takeoff code relies on a good sense of the vehicle's altitude, and it is unclear as to whether we will have that on vehicles on their first flight.
Given that, this arrangement is probably required on the current SkyViper hardware.
One alternative would be to use the current ArduCopter takeoff code but capping the time allowed for it to run. This would prevent the vehicle hitting the ceiling inside while using a more elaborate and flexible (but pre-existing!) control mechanism for the takeoff. I only mention this as an alternative in case the current code doesn't work across many frames.
ArduCopter/toy_mode.cpp
Outdated
|
||
//takeoff script to handle the throttle_control. takeoff_cmd is handled by handle_takeoff_cmd() | ||
const float takeoff_throttle_cmd = 700.0f; | ||
const uint32_t takeoff_time_ms = 1500; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint16_t
? :)
ArduCopter/toy_mode.cpp
Outdated
if(now - takeoff_arm_ms < takeoff_time_ms){ | ||
throttle_control = takeoff_throttle_cmd; | ||
} else { | ||
takeoff_state = TAKEOFF_IN_AIR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite an assumption. Maybe TAKEOFF_TIMER_FINISHED
?
ArduCopter/toy_mode.cpp
Outdated
} | ||
} | ||
break; | ||
case TAKEOFF_ARMED: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly rename state to something describing what's being attempted in this state - TAKEOFF_DO_ASCEND
or TAKEOFF_DO_CLIMB
?
ArduCopter/toy_mode.cpp
Outdated
//ability to cancel takeoff cmd during take off | ||
if ((takeoff_cmd && takeoff_cancel)) { | ||
|
||
if(takeoff_cmd){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant check
ArduCopter/toy_mode.h
Outdated
@@ -97,6 +99,13 @@ class ToyMode | |||
BLINK_VSLOW = 0xF000, | |||
BLINK_MED_1 = 0xF0F0, | |||
}; | |||
|
|||
enum takeoff_states { | |||
TAKEOFF_ON_GROUND = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe TAKEOFF_INACTIVE
. You may be on the ground and spinning props menacingly.
ArduCopter/toy_mode.h
Outdated
|
||
|
||
//used for takeoff cmd | ||
uint8_t takeoff_cmd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a struct to hold these. e.g.
struct {
uint8_t state;
uint32_t arm_ms;
uint32_t last_press_ms;
} takeoff;
Then reference with `takeoff.arm_ms`
ArduCopter/toy_mode.h
Outdated
//used for takeoff cmd | ||
uint8_t takeoff_cmd; | ||
uint8_t takeoff_state; | ||
int32_t takeoff_arm_ms; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint32_t
hi Czar, |
Hi @tridge @peterbarker, for the next years drone I saw on the TX that there will be launch/land button and a separate button for rtl. Should the launch/land button also do RTL if you're in loiter? - https://drive.google.com/open?id=0B0qjKcHMJVP9SWFvSEVzU2t6OW8 |
21ec92c
to
df685df
Compare
…om a uint16_t to a uint32_t because it was overflowing
ba061ea
to
150c392
Compare
Hi @peterbarker @tridge I added a 3 second delay before the throttle is applied. @peterbarker mentioned something about this line of code where some things do not get initialised when the copter is in ALT_HOLD |
3 seconds seems like a long time to wait. Does it feel slow to use this? Maybe 0.5s or 1s would be OK, but 3s seems too long to me. |
I'll change it to 1s and see. I will ask Zech if we want this take off cmd to be on the existing streaming GPS. |
@tridge - The takeoff functionality is not planned for existing skyviper-gps. I just wanted to be preemptive on my task. I saw I had two days to do it but didn't know when that two days will start. :) |
Hi Peter or Tridge
I think one of my task for next years features are to implement a takeoff cmd assigned to a button.
Could you please review my first take on my takeoff cmd script?
At the moment I have assigned it to the right action button (photo btn).
I have tested it only indoors.
To test this PR.
1.power cycle the copter and tx
2.pair the copter and tx
3.press photo button
Thank you