Skip to content

Commit

Permalink
Merge pull request #24 from julianoes/pr-add-gimbal-mode
Browse files Browse the repository at this point in the history
siyi_cli: add gimbal mode
  • Loading branch information
julianoes authored May 29, 2024
2 parents 9bf2b7a + 6fa5acb commit 151a950
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
27 changes: 26 additions & 1 deletion camera-manager/siyi_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void print_usage(const std::string_view& bin_name)
<< " version Show camera and gimbal version\n\n"
<< " take_picture Take a picture to SD card\n\n"
<< " toggle_recording Toggle start/stop video recording to SD card\n\n"
<< " gimbal mode <follow|lock|fpv> Set gimbal mode to follow, lock, or FPV\n\n"
<< " gimbal neutral Set gimbal forward\n\n"
<< " gimbal angle <pitch_value> <yaw_value> Set gimbal angles pitch (in degees, negative down)\n"
<< " and yaw (in degrees, positive is to the right)\n\n"
Expand Down Expand Up @@ -85,7 +86,31 @@ int main(int argc, char* argv[])
} else if (action == "gimbal") {
if (argc >= 3) {
const std::string_view command {argv[2]};
if (command == "neutral") {
if (command == "mode") {
if (argc == 4) {
const std::string_view mode {argv[3]};
siyi::SetGimbalMode set_gimbal_mode{};
if (mode == "lock") {
set_gimbal_mode.mode = siyi::SetGimbalMode::Mode::Lock;
} else if (mode == "follow") {
set_gimbal_mode.mode = siyi::SetGimbalMode::Mode::Follow;
} else if (mode == "fpv") {
set_gimbal_mode.mode = siyi::SetGimbalMode::Mode::Fpv;
} else {
std::cout << "Unkown mode: " << mode << std::endl;
print_usage(argv[0]);
return 1;
}
std::cout << "Set gimbal mode to " << mode << std::endl;
siyi_messager.send(siyi_serializer.assemble_message(set_gimbal_mode));
//(void)siyi_messager.receive();
} else {
std::cout << "Not enough arguments" << std::endl;
print_usage(argv[0]);
return 1;
}

} else if (command == "neutral") {
std::cout << "Set gimbal neutral" << std::endl;
siyi_messager.send(siyi_serializer.assemble_message(siyi::GimbalCenter{}));
(void)siyi_messager.receive();
Expand Down
19 changes: 19 additions & 0 deletions camera-manager/siyi_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ class ToggleRecording : public Payload<ToggleRecording> {
const std::uint8_t _func_type{2};
};

class SetGimbalMode : public Payload<SetGimbalMode> {
public:
[[nodiscard]] std::vector<std::uint8_t> bytes_impl() const {
std::vector<std::uint8_t> result;
result.push_back(static_cast<std::uint8_t>(mode));
return result;
}

static std::uint8_t cmd_id_impl() {
return 0x0C;
}

enum class Mode : std::uint8_t {
Lock = 3,
Follow = 4,
Fpv = 5,
} mode{Mode::Follow};
};

class GetStreamSettings : public Payload<GetStreamSettings> {
public:
[[nodiscard]] std::vector<std::uint8_t> bytes_impl() const {
Expand Down

0 comments on commit 151a950

Please sign in to comment.