diff --git a/libraries/AP_Gripper/AP_Gripper.cpp b/libraries/AP_Gripper/AP_Gripper.cpp index 83e7f6a0db..0cabe2c3f6 100644 --- a/libraries/AP_Gripper/AP_Gripper.cpp +++ b/libraries/AP_Gripper/AP_Gripper.cpp @@ -1,5 +1,7 @@ #include "AP_Gripper.h" +#if AP_GRIPPER_ENABLED + #include "AP_Gripper_Servo.h" #include "AP_Gripper_EPM.h" @@ -109,12 +111,16 @@ void AP_Gripper::init() switch(config.type.get()) { case 0: break; +#if AP_GRIPPER_SERVO_ENABLED case 1: backend = new AP_Gripper_Servo(config); break; +#endif +#if AP_GRIPPER_EPM_ENABLED case 2: backend = new AP_Gripper_EPM(config); break; +#endif default: break; } @@ -168,3 +174,5 @@ AP_Gripper *gripper() } }; + +#endif // AP_GRIPPER_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper.h b/libraries/AP_Gripper/AP_Gripper.h index 3f6036557d..95f887875d 100644 --- a/libraries/AP_Gripper/AP_Gripper.h +++ b/libraries/AP_Gripper/AP_Gripper.h @@ -15,6 +15,10 @@ #pragma once +#include "AP_Gripper_config.h" + +#if AP_GRIPPER_ENABLED + #include class AP_Gripper_Backend; @@ -85,3 +89,5 @@ private: namespace AP { AP_Gripper *gripper(); }; + +#endif // AP_GRIPPER_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_Backend.cpp b/libraries/AP_Gripper/AP_Gripper_Backend.cpp index 3c4680651a..fc5aabe4fe 100644 --- a/libraries/AP_Gripper/AP_Gripper_Backend.cpp +++ b/libraries/AP_Gripper/AP_Gripper_Backend.cpp @@ -1,7 +1,8 @@ #include "AP_Gripper_Backend.h" -#include -extern const AP_HAL::HAL& hal; +#if AP_GRIPPER_ENABLED + +#include void AP_Gripper_Backend::init() { @@ -20,3 +21,5 @@ void AP_Gripper_Backend::update() grab(); } } + +#endif // AP_GRIPPER_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_Backend.h b/libraries/AP_Gripper/AP_Gripper_Backend.h index 4557ee8988..1607289130 100644 --- a/libraries/AP_Gripper/AP_Gripper_Backend.h +++ b/libraries/AP_Gripper/AP_Gripper_Backend.h @@ -17,6 +17,8 @@ #include +#if AP_GRIPPER_ENABLED + class AP_Gripper_Backend { public: AP_Gripper_Backend(struct AP_Gripper::Backend_Config &_config) : @@ -55,3 +57,5 @@ protected: struct AP_Gripper::Backend_Config &config; }; + +#endif // AP_GRIPPER_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_EPM.cpp b/libraries/AP_Gripper/AP_Gripper_EPM.cpp index 66b715eb04..7ee41b537c 100644 --- a/libraries/AP_Gripper/AP_Gripper_EPM.cpp +++ b/libraries/AP_Gripper/AP_Gripper_EPM.cpp @@ -8,6 +8,9 @@ */ #include "AP_Gripper_EPM.h" + +#if AP_GRIPPER_EPM_ENABLED + #include #include #include @@ -142,3 +145,5 @@ bool AP_Gripper_EPM::grabbed() const return (config.state == AP_Gripper::STATE_GRABBED || config.state == AP_Gripper::STATE_GRABBING); } + +#endif // AP_GRIPPER_EPM_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_EPM.h b/libraries/AP_Gripper/AP_Gripper_EPM.h index 587c011620..65ae6a4732 100644 --- a/libraries/AP_Gripper/AP_Gripper_EPM.h +++ b/libraries/AP_Gripper/AP_Gripper_EPM.h @@ -14,6 +14,9 @@ #pragma once #include "AP_Gripper.h" + +#if AP_GRIPPER_EPM_ENABLED + #include "AP_Gripper_Backend.h" #include @@ -57,3 +60,5 @@ private: // UAVCAN driver fd int _uavcan_fd = -1; }; + +#endif // AP_GRIPPER_EPM_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_Servo.cpp b/libraries/AP_Gripper/AP_Gripper_Servo.cpp index 6c6f43eb1c..45bb387fa3 100644 --- a/libraries/AP_Gripper/AP_Gripper_Servo.cpp +++ b/libraries/AP_Gripper/AP_Gripper_Servo.cpp @@ -1,4 +1,7 @@ #include + +#if AP_GRIPPER_SERVO_ENABLED + #include #include @@ -115,3 +118,5 @@ bool AP_Gripper_Servo::valid() const } return true; } + +#endif // AP_GRIPPER_SERVO_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_Servo.h b/libraries/AP_Gripper/AP_Gripper_Servo.h index a98b0ca03c..33042c0e93 100644 --- a/libraries/AP_Gripper/AP_Gripper_Servo.h +++ b/libraries/AP_Gripper/AP_Gripper_Servo.h @@ -16,6 +16,9 @@ #pragma once #include + +#if AP_GRIPPER_SERVO_ENABLED + #include #define SERVO_ACTUATION_TIME 500 // Time for servo to move to target position during grab or release in milliseconds @@ -53,3 +56,5 @@ private: bool has_state_pwm(const uint16_t pwm) const; }; + +#endif // AP_GRIPPER_SERVO_ENABLED diff --git a/libraries/AP_Gripper/AP_Gripper_config.h b/libraries/AP_Gripper/AP_Gripper_config.h new file mode 100644 index 0000000000..b632afb01a --- /dev/null +++ b/libraries/AP_Gripper/AP_Gripper_config.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#ifndef AP_GRIPPER_ENABLED +#define AP_GRIPPER_ENABLED !HAL_MINIMIZE_FEATURES +#endif + +#ifndef AP_GRIPPER_BACKEND_DEFAULT_ENABLED +#define AP_GRIPPER_BACKEND_DEFAULT_ENABLED AP_GRIPPER_ENABLED +#endif + +#ifndef AP_GRIPPER_SERVO_ENABLED +#define AP_GRIPPER_SERVO_ENABLED AP_GRIPPER_BACKEND_DEFAULT_ENABLED +#endif + +#ifndef AP_GRIPPER_EPM_ENABLED +#define AP_GRIPPER_EPM_ENABLED AP_GRIPPER_BACKEND_DEFAULT_ENABLED +#endif