Inline Packet Config For Crazyradio2: Boost Performance!

by Alex Johnson 57 views

Currently, the Crazyradio2 firmware handles all packet configurations via USB setup requests. This method can be time-consuming and potentially lead to issues, such as the one mentioned in issue #22. To address these challenges and enhance performance, implementing inline packet configuration is a promising solution. This article explores the concept of inline packet configuration for Crazyradio2, its benefits, and a draft specification for its implementation.

The Problem with USB Setup Requests

The existing approach of using USB setup requests for packet configuration in Crazyradio2 has several drawbacks:

  • Time-Consuming: USB setup requests introduce significant overhead, increasing the time required to configure each packet.
  • Potential Issues: The delays associated with USB setup requests can lead to race conditions and other problems, as highlighted in issue #22.
  • Performance Bottleneck: The reliance on USB setup requests limits the overall performance of Crazyradio2, especially in scenarios with high packet transmission rates.

Inline Packet Configuration: A Solution

To overcome the limitations of USB setup requests, inline packet configuration offers a more efficient alternative. By embedding packet parameters directly within the packet data itself, this approach ensures that each packet is transmitted with the correct settings. This eliminates the possibility of race conditions and significantly improves Crazyradio performance.

Guaranteeing Correct Parameters: Inline configuration ensures that every packet is sent with the right parameters, eliminating race conditions.

Performance Improvement: Early experiments show significant performance gains with inline packet configuration.

Performance Evaluation

Early experiments with a prototype demonstrate the potential performance benefits of inline packet configuration. A synthetic benchmark was conducted to evaluate the performance of the new approach. The results are summarized in the table below:

n_crazyflies ping time packet/sec per Crazyflie total accumulated packet/sec
1 3ms 1274 1274
2 5.7ms 685 1370
3 8ms 456 1368

The results indicate that inline packet configuration can significantly improve packet transmission rates, especially when dealing with multiple Crazyflies. For example, with three Crazyflies, the total accumulated packet rate reaches 1368 packets per second.

Draft Specification for Inline Packet Configuration

The following is a draft specification for the new inline packet configuration functionality. Please note that this specification may be subject to change during implementation and based on feedback.

Integration with Legacy USB Protocol: The new mode will be added to the existing 'legacy' USB protocol, ensuring compatibility with existing systems.

Enabling Inline Packet Configuration: A setup flag will be used to enable inline packet configuration, reusing the existing set_mode() function used by Crazyradio PA to set PRX mode.

Packet Format

When the inline-packet-configuration flag is set, the data on the Bulk OUT endpoint will follow the following format:

| channel(1) | datarate(1) | ack_enable(1) | address(5) | Packet payload(1..32) |
  • channel(1): The channel number (1 byte).
  • datarate(1): The data rate (1 byte).
  • ack_enable(1): A flag indicating whether acknowledgment is enabled (1 byte). Setting this to 0 will disable the Bulk IN ack.
  • address(5): The address (5 bytes).
  • Packet payload(1..32): The actual packet data (1 to 32 bytes).

Impact on Ack Format: The format of Bulk IN acknowledgments remains unchanged.

Overhead: This adds 8 bytes to the packet size and disables the special dual packet mode used by Crazyswarm 1.

Design Considerations

To simplify implementation on both sides, the format is kept byte-aligned. While bit-packing parameters could potentially save one or two bytes, the USB overhead is considered negligible. Therefore, byte alignment is preferred for ease of development.

Backward Compatibility: All other setup requests will remain valid even in the inline packet configuration mode. However, any parameters set inline within the packet will override those set by other setup requests.

Radio State: Disabling the inline packet configuration mode will keep the radio in the setting set by the last packet sent.

Benefits of Inline Packet Configuration

Inline packet configuration offers several advantages over the traditional USB setup request method:

  • Improved Performance: By eliminating the overhead of USB setup requests, inline packet configuration significantly improves packet transmission rates.
  • Reduced Latency: The reduced overhead also translates to lower latency, which is crucial for real-time applications.
  • Elimination of Race Conditions: Inline packet configuration ensures that each packet is transmitted with the correct settings, preventing race conditions and other related issues.
  • Simplified Implementation: The byte-aligned format simplifies implementation on both the host and device sides.

Challenges and Considerations

While inline packet configuration offers numerous benefits, there are also some challenges and considerations to keep in mind:

  • Increased Packet Size: The addition of packet parameters increases the overall packet size, which may impact bandwidth utilization.
  • Compatibility: Ensuring compatibility with existing systems and protocols is crucial for a smooth transition.
  • Complexity: Implementing inline packet configuration may require modifications to both the host and device firmware.

Conclusion

Implementing inline packet configuration for Crazyradio2 firmware is a promising approach to enhance performance and address the limitations of USB setup requests. By embedding packet parameters directly within the packet data, this method ensures that each packet is transmitted with the correct settings, eliminating race conditions and improving packet transmission rates. While there are some challenges and considerations to keep in mind, the potential benefits of inline packet configuration make it a worthwhile endeavor. As the implementation progresses and feedback is gathered, the draft specification may be refined to optimize performance and ensure compatibility.

For more information on Crazyradio and related projects, visit the Bitcraze website.