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

[WIP] Dev dshot #12634

Closed
wants to merge 38 commits into from
Closed

[WIP] Dev dshot #12634

wants to merge 38 commits into from

Conversation

Igor-Misic
Copy link
Member

@Igor-Misic Igor-Misic commented Aug 5, 2019

Describe problem solved by the proposed pull request
This PR adds drivers for Dshot protocol. (This is not full support for Dshot protocol, only drivers.)

Test data / coverage
Dshot protocol was tested on Pixracer. This still needs to be integrated into the whole system and tested.

Describe your preferred solution
We have discussed on a slack channel to add this driver support.

Describe possible alternatives
No alternative, at the moment this is how other PWM drivers work.

@dagar dagar changed the title Dev dshot [WIP] Dev dshot Aug 5, 2019
@dagar dagar self-requested a review August 5, 2019 23:40
@dagar
Copy link
Member

dagar commented Aug 6, 2019

How were you testing this?

unsigned timer = channels_timer(channel);

rARR(timer) = DSHOT_MOTOR_PWM_BIT_WIDTH;
rPSC(timer) = ((int)(io_timers[timer].clock_freq / dshot_pwm_freq)/DSHOT_MOTOR_PWM_BIT_WIDTH) - 1;;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rPSC(timer) = ((int)(io_timers[timer].clock_freq / dshot_pwm_freq)/DSHOT_MOTOR_PWM_BIT_WIDTH) - 1;;
rPSC(timer) = ((int)(io_timers[timer].clock_freq / dshot_pwm_freq)/DSHOT_MOTOR_PWM_BIT_WIDTH) - 1;

Copy link
Member Author

@Igor-Misic Igor-Misic Aug 6, 2019

Choose a reason for hiding this comment

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

With calling init function with different DSHOT frequencies.

example:

up_dshot_init(channel_mask, DSHOT1200);
up_dshot_init(channel_mask, DSHOT600);
up_dshot_init(channel_mask, DSHOT300);
up_dshot_init(channel_mask, DSHOT150);

And then sending the arming command:
up_dshot_arm(true);

Setting throttle value:

    uint16_t throttle = 100;
    up_dshot_motor_data_prepare(0,throttle, true);

And triggering the message:
up_dshot_trigger();

I've connected logic analyzer on dshot (servo wire) to see frequencies.
ESC was working for my setup Pixracer at 168 MHz on all Dshots modes. It was able to arm and to spin the motors.

For each Dshot message, frequency needs to be near selected.
For example dshot 1200, the frequency will be around 1.2 MHz. It depends on the selected system frequency, and this formula will calculate the closest one by rounding it down because of the integer.

@dagar
Copy link
Member

dagar commented Aug 6, 2019

Realistically will a user need/want to configure the equivalent of PWM_{MIN, MAX, DISARMED} when using dshot?

@mhkabir
Copy link
Member

mhkabir commented Aug 6, 2019

@dagar Nope.

Edit: Maybe only for setting the threshold for when motors start spinning, etc. (varies)

@dagar
Copy link
Member

dagar commented Aug 6, 2019

At the moment I'm thinking a simple dshot "driver" that you optionally run in place of px4fmu is going to make the most sense. That should also work well as a place to handle telemetry.

@Igor-Misic
Copy link
Member Author

Igor-Misic commented Aug 6, 2019

How were you testing this?

If you mean by the whole driver, I added some extra code inside boards/px4/fmu-v4/init.c at the end of int board_app_initialize(uintptr_t arg) function. At that point, I'm sure Nuttx initialized all NVIC and DMA2 so you can start using stream5 and code for nuttx will handle interrupts.

This is the code which I use for testing drivers

At the beginning of the file:
#include <drivers/drv_pwm_output.h>

At the end of the board_app_initialize function

    //Start debugging for dshot
    uint32_t channel_mask = 0x3F; //b0111111 -> TIM2: b0110000+ TIM1: TIM2: b0001111
    up_dshot_init(channel_mask, DSHOT1200);
    up_dshot_arm(true);
    uint16_t throttle = 100;
    up_dshot_motor_data_set(0,throttle, true);
    up_dshot_motor_data_set(1,throttle, true);
    up_dshot_motor_data_set(2,throttle, true);
    up_dshot_motor_data_set(3,throttle, true);
    up_dshot_motor_data_set(4,throttle, true);
    up_dshot_motor_data_set(5,throttle, true);

    for(uint32_t i = 0; i < 1000; i++) {
        up_dshot_trigger();
        usleep(1000);
    }

    up_dshot_arm(false);

    // This should not do anything since is disarmed.
    for(uint32_t i = 0; i < 1000; i++) {
        up_dshot_trigger();
        usleep(1000);
    }

@Igor-Misic Igor-Misic closed this Aug 15, 2019
@Igor-Misic Igor-Misic deleted the dev-dshot branch August 15, 2019 20:18
@Igor-Misic Igor-Misic restored the dev-dshot branch August 15, 2019 20:23
@Igor-Misic
Copy link
Member Author

Reopening pull request because accidentally removed branch.

Code style update 2. 


Proper address casting style. 


Code style update 3.
@dagar
Copy link
Member

dagar commented Aug 18, 2019

We'll need to go through each board and get the DMA map under control. This was a bit of a pain for SPI. #12436

@hamishwillee hamishwillee added the Documentation 📑 Anything improving the documentation of the code / ecosystem label Aug 18, 2019
@hamishwillee
Copy link
Contributor

Thanks @Igor-Misic . I have created a docs page to track here PX4/PX4-user_guide#560

That sounds like a good plan. Sounds like we don't need work on this until "end user support" is in. Please ping me when you think we're ready for that.

@jkflying
Copy link
Contributor

For ESC support, I believe BLHELI_S also supports DShot up to 600kHz, but not bidirectional.

@dagar
Copy link
Member

dagar commented Aug 31, 2019

Continued in #12854.

@dagar dagar closed this Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin: Enhancement (improvement) 💡 Documentation 📑 Anything improving the documentation of the code / ecosystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants