-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
Full gimbal angle control #2210
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a828fdd
Added gimbal function SetAngles
002b7b6
Updated proto
89bc0a1
Fixed typo
7982fd2
cleaned up code
e8e4f5a
Compiler option added for raspberry pi
2299256
Generated files to compile
Daybreakerflint 85d0fea
Added new test for the gimbal
Daybreakerflint 0c7189d
Added roll angle to output
Daybreakerflint bcd0d4a
Fixed typo
240634e
Changed order of angels to MAVLink order
8a81ac3
updated protos
6eab502
Reverted submodule to mavlink repo
Daybreakerflint 8559741
Update proto submodule, fix style
julianoes 0d76b8f
examples: improve description
julianoes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(gimbal_full_control) | ||
|
||
add_executable(gimbal_full_control | ||
gimbal_full_control.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(gimbal_full_control | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(gimbal PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(gimbal PRIVATE -WX -W2) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// | ||
// Simple example to demonstrate how to control a gimbal. | ||
// | ||
// Can be tested against PX4 SITL with Typhoon H480: | ||
// make px4_sitl gazebo_typhoon_h480 | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/plugins/gimbal/gimbal.h> | ||
#include <mavsdk/plugins/telemetry/telemetry.h> | ||
#include <iostream> | ||
#include <future> | ||
#include <memory> | ||
#include <thread> | ||
|
||
using namespace mavsdk; | ||
using std::chrono::seconds; | ||
using std::this_thread::sleep_for; | ||
|
||
void usage(const std::string& bin_name) | ||
{ | ||
std::cerr << "Usage : " << bin_name << " <connection_url>\n" | ||
<< "Connection URL format should be :\n" | ||
<< " For TCP : tcp://[server_host][:server_port]\n" | ||
<< " For UDP : udp://[bind_host][:bind_port]\n" | ||
<< " For Serial : serial:///path/to/serial/dev[:baudrate]\n" | ||
<< "For example, to connect to the simulator use URL: udp://:14540\n"; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc != 2) { | ||
usage(argv[0]); | ||
return 1; | ||
} | ||
|
||
Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}}; | ||
ConnectionResult connection_result = mavsdk.add_any_connection(argv[1]); | ||
|
||
if (connection_result != ConnectionResult::Success) { | ||
std::cerr << "Connection failed: " << connection_result << '\n'; | ||
return 1; | ||
} | ||
|
||
auto system = mavsdk.first_autopilot(3.0); | ||
if (!system) { | ||
std::cerr << "Timed out waiting for system\n"; | ||
return 1; | ||
} | ||
|
||
// Instantiate plugins. | ||
auto telemetry = Telemetry{system.value()}; | ||
auto gimbal = Gimbal{system.value()}; | ||
|
||
// We want to listen to the camera/gimbal angle of the drone at 5 Hz. | ||
const Telemetry::Result set_rate_result = telemetry.set_rate_camera_attitude(5.0); | ||
if (set_rate_result != Telemetry::Result::Success) { | ||
std::cerr << "Setting rate failed:" << set_rate_result << '\n'; | ||
return 1; | ||
} | ||
|
||
// Set up callback to monitor camera/gimbal angle | ||
telemetry.subscribe_camera_attitude_euler([](Telemetry::EulerAngle angle) { | ||
std::cout << "Gimbal angle pitch: " << angle.pitch_deg << " deg, yaw: " << angle.yaw_deg | ||
<< " deg, roll: " << angle.roll_deg << " deg\n"; | ||
}); | ||
|
||
std::cout << "Start controlling gimbal...\n"; | ||
Gimbal::Result gimbal_result = gimbal.take_control(Gimbal::ControlMode::Primary); | ||
if (gimbal_result != Gimbal::Result::Success) { | ||
std::cerr << "Could not take gimbal control: " << gimbal_result << '\n'; | ||
return 1; | ||
} | ||
|
||
std::cout << "Set yaw mode to lock to a specific direction...\n"; | ||
gimbal_result = gimbal.set_mode(Gimbal::GimbalMode::YawLock); | ||
if (gimbal_result != Gimbal::Result::Success) { | ||
std::cerr << "Could not set to lock mode: " << gimbal_result << '\n'; | ||
return 1; | ||
} | ||
|
||
std::cout << "Test SetAngles...\n"; | ||
std::cout << "Roll=0 Pitch=0 Yaw=0\n"; | ||
gimbal.set_angles(0.0f, 0.0f, 0.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=-30 Pitch=0 Yaw=0\n"; | ||
gimbal.set_angles(-30.0f, 0.0f, 0.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=30 Pitch=0 Yaw=0\n"; | ||
gimbal.set_angles(30.0f, 0.0f, 0.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=0 Pitch=-30 Yaw=0\n"; | ||
gimbal.set_angles(0.0f, -30.0f, 0.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=0 Pitch=30 Yaw=0\n"; | ||
gimbal.set_angles(0.0f, 30.0f, 0.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=0 Pitch=0 Yaw=-30\n"; | ||
gimbal.set_angles(0.0f, 0.0f, -30.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=0 Pitch=0 Yaw=30\n"; | ||
gimbal.set_angles(0.0f, 0.0f, 30.0f); | ||
sleep_for(seconds(5)); | ||
std::cout << "Roll=0 Pitch=0 Yaw=0\n"; | ||
gimbal.set_angles(0.0f, 0.0f, 0.0f); | ||
sleep_for(seconds(2)); | ||
|
||
std::cout << "Stop controlling gimbal...\n"; | ||
gimbal_result = gimbal.release_control(); | ||
if (gimbal_result != Gimbal::Result::Success) { | ||
std::cerr << "Could not take gimbal control: " << gimbal_result << '\n'; | ||
return 1; | ||
} | ||
|
||
std::cout << "Finished.\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me merge the MAVSDK-Proto PR, then you can update that and we can merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.