Skip to content
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

Add 60k RPM support to voxl-esc driver #49

Merged
merged 22 commits into from
Dec 8, 2023
Merged

Add 60k RPM support to voxl-esc driver #49

merged 22 commits into from
Dec 8, 2023

Conversation

modaljc
Copy link

@modaljc modaljc commented Dec 6, 2023

Changes

  • Added new packet header for extended RPM range commands
  • Added new packet packing function for extended RPM range commands
  • Implemented ESC firmware version check at driver start up to determine which type of RPM command to send
  • Added voxl-esc driver back to voxl2 build (removing this had removed the voxl-esc section from the Actuators tab in QGC)
  • Add Voxl2 IO default parameters

Testing

  • Acro and Manual mode flights were successful
  • Successfully spun motors on bench with props attached and verified that RPMs were higher than 32k (./voxl-esc-spin.py --id 0 --rpm 35000 --ramp-time 3.0 --enable-extended-rpm-cmd 1)
  • Successfully spun motors on bench with props attached via Actuators tab
  • Validated that standard range RPM commands are sent when using old ESC firmware and extended range commands are sent when using new ESC firmware (SW version>=39)


// Limit RPMs to prevent overflow when converting to int16_t
if (rpm0 > UINT16_MAX) { rpm0 = UINT16_MAX-5; } if (rpm1 > UINT16_MAX) { rpm1 = UINT16_MAX-5; }
if (rpm2 > UINT16_MAX) { rpm2 = UINT16_MAX-5; } if (rpm3 > UINT16_MAX) { rpm3 = UINT16_MAX-5; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing to me. The comment says it is trying to prevent overflow of int16_t. So why would UINT16_MAX-5 accomplish that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using extended range rpm command we divide the value passed in by 2 before sending to the ESC. Requested rpms passed in can theoretically be larger than UINT16_MAX since they are int32_t (RPMs can be negative), which would mean that it's possible when we divide the value for extended range packet that it is still larger than UINT16_MAX, which would cause overflow when assigning the value to the data array (int16_t). I.e. if a value of 2,000,000 is passed in, the divided value is 1,000,000 which is still above UINT16_MAX but when assigned to the int16_t data variable it would be truncated to 16960.

After thinking about it more, I think it might be a good idea to add some range limiting to the negative end of the range as well as maybe limit the standard range too since the input is int32_t... or we could leave it up to the user to input the correct values... thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's let Alex submit his comments to see what his ideas are.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From Alex:
in the limit values for regular (not extended rpm) the limits should be +-/32k (2^15), not UINT16_MAX . For the extended rpm range, the limit will be +/- 65K (but lets use slightly smaller limit as you already started doing)

I updated this in my latest commit (3dd7d21). I added max and min for both the standard and extended range... -32k to 32k and -65k to 65k, respectively

@@ -1038,6 +1063,12 @@ bool VoxlEsc::updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS],
_esc_chans[i].rate_req = 0;

} else {
if (_extended_rpm) {
if (outputs[i] > 65530) outputs[i] = 65530;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a constant definition of 65530 and 32766 with some comments about why those values were chosen

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make this happen

@modaljc
Copy link
Author

modaljc commented Dec 7, 2023

From Alex (referring to qc_esc_packet.c line 154) :
it is not necessary to cast to doubles when scaling the rpms, integer math is good

I updated this in the latest commit (3dd7d21) and removed the double and int16_t casts

@katzfey katzfey merged commit d4f025b into voxl-dev Dec 8, 2023
15 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants