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 proper broadcast version check to support Crazyradio 2.0 broadcasting #35

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ if (BUILD_CPP_EXAMPLES)
target_link_libraries(example_broadcast
crazyflieLinkCpp
)

# example_broadcast_and_console
add_executable(example_broadcast_and_console
examples/broadcast_and_console.cpp
)
target_link_libraries(example_broadcast_and_console
crazyflieLinkCpp
)
endif()

if (BUILD_PYTHON_BINDINGS)
Expand Down
63 changes: 63 additions & 0 deletions examples/broadcast_and_console.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
#include <thread>

#include "crazyflieLinkCpp/Connection.h"
#include "PacketUtils.hpp"

using namespace bitcraze::crazyflieLinkCpp;

void run1()
{
Connection con("radio://0/80/2M/E7E7E7E7E7");

const auto start = std::chrono::high_resolution_clock::now();
while (true) {
Packet p = con.recv(0);
if (p.port() == 0 && p.channel() == 0) {
std::string str((const char*)p.payload(), (size_t)p.payloadSize());
std::cout << str;
}

const auto end = std::chrono::high_resolution_clock::now();
const std::chrono::duration<double, std::milli> elapsed = end - start;
if (elapsed.count() > 5000) {
break;
}
}
}

void run2()
{
/* Creates a connection that will broadcast to all
* crazyflies on channel 80. Note that this requires
* updating the Crazyradio firmware from its factory version
*/
Connection broadcastConnection("radiobroadcast://*/80/2M");

// Requires high level commander enabled (param commander.enHighLevel == 1)
std::cout << "Taking off..." << std::endl;
broadcastConnection.send(PacketUtils::takeoffCommand(0.5f, 0.0f, 3.0f));
std::this_thread::sleep_for(std::chrono::milliseconds(3250));

std::cout << "Landing..." << std::endl;
broadcastConnection.send(PacketUtils::landCommand(0.0f, 0.0f, 3.0f));
std::this_thread::sleep_for(std::chrono::milliseconds(3250));

std::cout << "Stopping..." << std::endl;
broadcastConnection.send(PacketUtils::stopCommand());
std::this_thread::sleep_for(std::chrono::milliseconds(500));

broadcastConnection.close();
std::cout << "Done." << std::endl;
}

int main()
{
std::thread t1(run1);
std::thread t2(run2);

t1.join();
t2.join();

return 0;
}
4 changes: 3 additions & 1 deletion src/CrazyradioThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ void CrazyradioThread::run()
{
Crazyradio radio(dev_);
const auto version = radio.version();
bool supports_broadcasts = version.second >= 0x55;
bool supports_broadcasts =
(version.first == 0x99 && version.second >= 0x55) // Crazyradio PA with latest official firmware
|| (version.first == 3 && version.second >= 2); // Crazyradio 2.0;

const uint8_t enableSafelink[] = {0xFF, 0x05, 1};
const uint8_t ping[] = {0xFF};
Expand Down