-
-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added gimbal function SetAngles * Updated proto * Fixed typo * cleaned up code * Compiler option added for raspberry pi * Generated files to compile * Added new test for the gimbal * Added roll angle to output * Fixed typo * Changed order of angels to MAVLink order * updated protos * Reverted submodule to mavlink repo * Update proto submodule, fix style Signed-off-by: Julian Oes <[email protected]> * examples: improve description Worth mentioning what the example is about. Signed-off-by: Julian Oes <[email protected]> --------- Signed-off-by: Julian Oes <[email protected]> Co-authored-by: Adrian Dummermuth <[email protected]> Co-authored-by: Julian Oes <[email protected]>
- Loading branch information
1 parent
504c977
commit 3131cc9
Showing
18 changed files
with
1,786 additions
and
200 deletions.
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
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 @@ | ||
// | ||
// Example to demonstrate how to control a gimbal including roll. | ||
// | ||
// 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.