forked from PX4/PX4-Autopilot
-
Notifications
You must be signed in to change notification settings - Fork 20
Voxl2_io driver expand to 8 channel pwm output #52
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
Open
dirksavage88
wants to merge
5
commits into
modalai:voxl-dev
Choose a base branch
from
dirksavage88:voxl2_io_updates
base: voxl-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cae160a
expand motor outputs to 8
dirksavage88 f740b9f
fix to packet input size for 8 channels
dirksavage88 36fcd78
revert esc number of channels
dirksavage88 766fffc
change to packet structure
dirksavage88 6528a20
update pwm packet
dirksavage88 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,4 +38,4 @@ parameters: | |
reboot_required: true | ||
num_instances: 1 | ||
instance_start: 1 | ||
default: 0 | ||
default: 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,10 @@ int Voxl2IO::load_params(voxl2_io_params_t *params) | |
param_get(param_find("VOXL2_IO_FUNC2"), ¶ms->function_map[1]); | ||
param_get(param_find("VOXL2_IO_FUNC3"), ¶ms->function_map[2]); | ||
param_get(param_find("VOXL2_IO_FUNC4"), ¶ms->function_map[3]); | ||
param_get(param_find("VOXL2_IO_FUNC5"), ¶ms->function_map[4]); | ||
param_get(param_find("VOXL2_IO_FUNC6"), ¶ms->function_map[5]); | ||
param_get(param_find("VOXL2_IO_FUNC7"), ¶ms->function_map[6]); | ||
param_get(param_find("VOXL2_IO_FUNC8"), ¶ms->function_map[7]); | ||
|
||
/* Validate PWM min and max values */ | ||
if (params->pwm_min > params->pwm_max){ | ||
|
@@ -286,8 +290,8 @@ bool Voxl2IO::updateOutputs(bool stop_motors, uint16_t outputs[input_rc_s::RC_IN | |
|
||
//in Run() we call _mixing_output.update(), which calls MixingOutput::limitAndUpdateOutputs which calls _interface.updateOutputs (this function) | ||
//So, if Run() is blocked by a custom command, this function will not be called until Run is running again | ||
int16_t _rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0}; | ||
uint8_t _led_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0}; | ||
int16_t _rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
uint8_t _led_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
int32_t _fb_idx = -1; | ||
|
||
if (num_outputs != VOXL2_IO_OUTPUT_CHANNELS) { | ||
|
@@ -313,8 +317,8 @@ bool Voxl2IO::updateOutputs(bool stop_motors, uint16_t outputs[input_rc_s::RC_IN | |
} | ||
|
||
Command cmd; | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(_rate_req[0], _rate_req[1], _rate_req[2], _rate_req[3], | ||
_led_req[0], _led_req[1], _led_req[2], _led_req[3], | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(_rate_req[0], _rate_req[1], _rate_req[2], _rate_req[3], _rate_req[4], _rate_req[5], _rate_req[6], _rate_req[7], | ||
_led_req[0], _led_req[1], _led_req[2], _led_req[3], _led_req[4], _led_req[5], _led_req[6], _led_req[7], | ||
_fb_idx, cmd.buf, sizeof(cmd.buf)); | ||
if (_pwm_on && _debug){ | ||
PX4_INFO("Mixer outputs"); | ||
|
@@ -324,7 +328,7 @@ bool Voxl2IO::updateOutputs(bool stop_motors, uint16_t outputs[input_rc_s::RC_IN | |
outputs[12], outputs[13], outputs[14], outputs[15], outputs[16], outputs[17] | ||
); | ||
|
||
// Debug messages for PWM 400Hz values sent to M0065 | ||
// Debug messages for PWM 400Hz values sent to M0065 | ||
uint16_t tics_1 = (_parameters.pwm_min + (_pwm_fullscale * ((double)outputs[0]/VOXL2_IO_MIXER_MAX))) * VOXL2_IO_TICS; | ||
PX4_INFO("\tPWM CH1: %hu::%uus::%u tics", outputs[0], tics_1/24, tics_1); | ||
uint16_t tics_2 = (_parameters.pwm_min + (_pwm_fullscale *((double)outputs[1]/VOXL2_IO_MIXER_MAX))) * VOXL2_IO_TICS; | ||
|
@@ -712,13 +716,13 @@ int Voxl2IO::task_spawn(int argc, char *argv[]) | |
|
||
bool Voxl2IO::stop_all_pwms() | ||
{ | ||
int16_t _rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0}; | ||
int16_t _led_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0}; | ||
int16_t _rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
int16_t _led_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
uint8_t _fb_idx = 0; | ||
|
||
Command cmd; | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(_rate_req[0], _rate_req[1], _rate_req[2], _rate_req[3], | ||
_led_req[0], _led_req[1], _led_req[2], _led_req[3], | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(_rate_req[0], _rate_req[1], _rate_req[2], _rate_req[3], _rate_req[4], _rate_req[5], _rate_req[6], _rate_req[7], | ||
_led_req[0], _led_req[1], _led_req[2], _led_req[3], _led_req[4], _led_req[5], _led_req[6], _led_req[7], | ||
_fb_idx, cmd.buf, sizeof(cmd.buf)); | ||
|
||
if (_uart_port->uart_write(cmd.buf, cmd.len) != cmd.len) { | ||
|
@@ -770,11 +774,11 @@ int Voxl2IO::calibrate_escs(){ | |
|
||
/* PWM MAX 3 seconds */ | ||
PX4_INFO("Writing PWM MAX for 3 seconds!"); | ||
int16_t max_pwm[4]{VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX}; | ||
if (_debug) PX4_INFO("%i %i %i %i", max_pwm[0], max_pwm[1], max_pwm[2], max_pwm[3]); | ||
int16_t led_cmd[4]{0,0,0,0}; | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(max_pwm[0], max_pwm[1], max_pwm[2], max_pwm[3], | ||
led_cmd[0], led_cmd[1], led_cmd[2], led_cmd[3], | ||
int16_t max_pwm[8]{VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX, VOXL2_IO_MIXER_MAX}; | ||
// if (_debug) PX4_INFO("%i %i %i %i %i %i %i %i", max_pwm[0], max_pwm[1], max_pwm[2], max_pwm[3], max_pwm[4], max_pwm[5], max_pwm[6], max_pwm[7]); | ||
int16_t led_cmd[8]{0,0,0,0,0,0,0,0}; | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(max_pwm[0], max_pwm[1], max_pwm[2], max_pwm[3], max_pwm[4], max_pwm[5], max_pwm[6], max_pwm[7], | ||
led_cmd[0], led_cmd[1], led_cmd[2], led_cmd[3], led_cmd[4], led_cmd[5], led_cmd[6], led_cmd[7], | ||
fb_idx, cmd.buf, sizeof(cmd.buf)); | ||
|
||
if (_uart_port->uart_write(cmd.buf, cmd.len) != cmd.len) { | ||
|
@@ -792,10 +796,10 @@ int Voxl2IO::calibrate_escs(){ | |
|
||
/* PWM MIN 4 seconds */ | ||
PX4_INFO("Writing PWM MIN for 4 seconds!"); | ||
int16_t min_pwm[4]{VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN}; | ||
if (_debug) PX4_INFO("%i %i %i %i", min_pwm[0], min_pwm[1], min_pwm[2], min_pwm[3]); | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(min_pwm[0], min_pwm[1], min_pwm[2], min_pwm[3], | ||
led_cmd[0], led_cmd[1], led_cmd[2], led_cmd[3], | ||
int16_t min_pwm[8]{VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN, VOXL2_IO_MIXER_MIN}; | ||
// if (_debug) PX4_INFO("%i %i %i %i %i %i %i %i", min_pwm[0], min_pwm[1], min_pwm[2], min_pwm[3], min_pwm[4], min_pwm[4], min_pwm[5], min_pwm[6], min_pwm[7]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
cmd.len = voxl2_io_create_pwm_packet4_fb(min_pwm[0], min_pwm[1], min_pwm[2], min_pwm[3], min_pwm[4], min_pwm[5], min_pwm[6], min_pwm[7], | ||
led_cmd[0], led_cmd[1], led_cmd[2], led_cmd[3], led_cmd[4], led_cmd[5], led_cmd[6], led_cmd[7], | ||
fb_idx, cmd.buf, sizeof(cmd.buf)); | ||
|
||
if (_uart_port->uart_write(cmd.buf, cmd.len) != cmd.len) { | ||
|
@@ -920,22 +924,26 @@ int Voxl2IO::custom_command(int argc, char *argv[]) | |
PX4_INFO("Rate: %i", rate); | ||
if (output_channel < VOXL2_IO_OUTPUT_CHANNELS) { | ||
PX4_INFO("Request PWM for Output Channel: %i - PWM: %i", output_channel, rate); | ||
int16_t rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0}; | ||
int16_t rate_req[VOXL2_IO_OUTPUT_CHANNELS] = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
uint8_t id_fb = 0; | ||
|
||
if (output_channel == 0xFF) { //WARNING: this condition is not possible due to check 'if (esc_id < MODAL_IO_OUTPUT_CHANNELS)'. | ||
rate_req[0] = rate; | ||
rate_req[1] = rate; | ||
rate_req[2] = rate; | ||
rate_req[3] = rate; | ||
rate_req[4] = rate; | ||
rate_req[5] = rate; | ||
rate_req[6] = rate; | ||
rate_req[7] = rate; | ||
|
||
} else { | ||
rate_req[output_channel] = rate; | ||
id_fb = output_channel; | ||
} | ||
|
||
cmd.len = voxl2_io_create_pwm_packet4_fb(rate_req[0], rate_req[1], rate_req[2], rate_req[3], | ||
0, 0, 0, 0, | ||
cmd.len = voxl2_io_create_pwm_packet4_fb(rate_req[0], rate_req[1], rate_req[2], rate_req[3], rate_req[4], rate_req[5], rate_req[6], rate_req[7], | ||
0, 0, 0, 0, 0, 0, 0, 0, | ||
id_fb, cmd.buf, sizeof(cmd.buf)); | ||
|
||
cmd.response = false; | ||
|
@@ -955,7 +963,7 @@ int Voxl2IO::custom_command(int argc, char *argv[]) | |
get_instance()->_packets_sent++; | ||
} | ||
} else { | ||
print_usage("Invalid Output Channel, use 0-3"); | ||
print_usage("Invalid Output Channel, use 0-7"); | ||
return 0; | ||
} | ||
} | ||
|
@@ -981,7 +989,11 @@ int Voxl2IO::print_status() | |
PX4_INFO("Params: VOXL2_IO_FUNC2: %" PRId32, _parameters.function_map[1]); | ||
PX4_INFO("Params: VOXL2_IO_FUNC3: %" PRId32, _parameters.function_map[2]); | ||
PX4_INFO("Params: VOXL2_IO_FUNC4: %" PRId32, _parameters.function_map[3]); | ||
|
||
PX4_INFO("Params: VOXL2_IO_FUNC5: %" PRId32, _parameters.function_map[4]); | ||
PX4_INFO("Params: VOXL2_IO_FUNC6: %" PRId32, _parameters.function_map[5]); | ||
PX4_INFO("Params: VOXL2_IO_FUNC7: %" PRId32, _parameters.function_map[6]); | ||
PX4_INFO("Params: VOXL2_IO_FUNC8: %" PRId32, _parameters.function_map[7]); | ||
|
||
perf_print_counter(_cycle_perf); | ||
perf_print_counter(_output_update_perf); | ||
PX4_INFO(""); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 debug statement had to be commented out due to compiler warning for formatting (too many format prints?)