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 Matek Serialshot protocol #4646

Merged
merged 5 commits into from
May 11, 2019
Merged

Add Matek Serialshot protocol #4646

merged 5 commits into from
May 11, 2019

Conversation

digitalentity
Copy link
Member

Initial cut on MATEK's SerialShort protocol.
No telemetry (we don't support ESC telemetry yet).
Not tested. May break DSHOT.

@digitalentity digitalentity added this to the 2.2 milestone Apr 25, 2019
@digitalentity
Copy link
Member Author

@MATEKSYS FYI

@MATEKSYS
Copy link
Contributor

Thank you. we will test it and try supporting telemetry with a workaround

@digitalentity
Copy link
Member Author

@MATEKSYS I would recommend doing some changes to the protocol to make it more robust. I'll publish a proposed throttle packet format soon.

I'm also happy to make tweaks to your ESC code if necessary.

@digitalentity
Copy link
Member Author

digitalentity commented Apr 30, 2019

Suggested packet format:

typedef struct __attribute__((packed)) {
    uint8_t hdr;			// Header/version marker
    uint8_t motorData[6];	// 12 bit per motor
    uint8_t crc;			// CRC8/DVB-T of hdr & motorData
} serialShortPacket_t;

// Motor throttle values encoding
motorData[0] = motor[0] & 0x00FF;
motorData[1] = motor[1] & 0x00FF;
motorData[2] = motor[2] & 0x00FF;
motorData[3] = motor[3] & 0x00FF;
motorData[4] = (((motor[0] & 0xF00) >> 8) << 0) | (((motor[1] & 0xF00) >> 8) << 4);
motorData[5] = (((motor[2] & 0xF00) >> 8) << 0) | (((motor[3] & 0xF00) >> 8) << 4);

// Motor throttle value decoding
motor[0] = motorData[0] | (((uint16_t)((motorData[4] >> 0) & 0x0F)) << 8);
motor[1] = motorData[1] | (((uint16_t)((motorData[4] >> 4) & 0x0F)) << 8);
motor[2] = motorData[2] | (((uint16_t)((motorData[4] >> 0) & 0x0F)) << 8);
motor[3] = motorData[3] | (((uint16_t)((motorData[4] >> 4) & 0x0F)) << 8);

Pros:

  • Packet size of 8 byte (same as now).
  • 12 bit throttle resolution (0...4096) which is plenty to accommodate raw DSHOT throttle values/commands.
  • Extendability - we can have different header values to indicate different type of packet data (i.e. motors 5-8, or servo data).
  • Robust. Even if we have bit errors - CRC will detect them. Also, CRC is more robust compared to simple addition.

Cons:

  • Slightly higher encoding/decoding overhead due to bit manipulation and CRC calculation. Shouldn't be an issue.

@digitalentity
Copy link
Member Author

@MATEKSYS what do you think about changing the ESC protocol to make it more error-immune?

@MATEKSYS
Copy link
Contributor

MATEKSYS commented May 5, 2019

We have modified the protocol according to your suggestion. need to test it.

@digitalentity
Copy link
Member Author

@MATEKSYS this is super cool!!! Thanks!

@digitalentity
Copy link
Member Author

@MATEKSYS see the last commit for reference implementation of new throttle packet format.
Verified to generate correct DSHOT throttle values on all 4 motors.

Also, I missed the fact that new on-wire packet is 1 byte smaller (just 8 bytes now instead of 9)

@digitalentity
Copy link
Member Author

Verified to be working. Guidelines for setup for MATEKF405 board with ESC connected to UART1

serial 0 262144 115200 115200 0 115200
set min_throttle = 1050
set max_throttle = 2000
set motor_pwm_rate = 2000
set motor_pwm_protocol = SERIALSHOT

@digitalentity
Copy link
Member Author

Checked that DSHOT still works. Ready to merge.

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.

None yet

2 participants