From 6c4bf1ac8bcc6a03b43e0fe6bee6d0a49c0be59a Mon Sep 17 00:00:00 2001 From: Andre Phu-Van Nguyen Date: Wed, 3 May 2017 17:16:56 -0400 Subject: [PATCH] fix unused params warning --- AirLib/include/common/StateReporter.hpp | 2 ++ AirLib/include/common/UpdatableObject.hpp | 1 + AirLib/include/common/common_utils/AsyncTasker.hpp | 4 +++- AirLib/include/common/common_utils/Utils.hpp | 4 ++++ AirLib/include/controllers/ControllerBase.hpp | 2 ++ .../controllers/rosflight/AirSimRosFlightBoard.hpp | 14 ++++++++++++++ .../rosflight/AirSimRosFlightCommLink.hpp | 6 ++++++ AirLib/include/vehicles/MultiRotor.hpp | 2 ++ AirLib/include/vehicles/MultiRotorParams.hpp | 2 ++ AirLib/src/controllers/DroneControllerBase.cpp | 2 ++ AirLib/src/controllers/MavLinkDroneController.cpp | 12 ++++++++++++ DroneShell/include/SimpleShell.hpp | 3 +++ 12 files changed, 53 insertions(+), 1 deletion(-) diff --git a/AirLib/include/common/StateReporter.hpp b/AirLib/include/common/StateReporter.hpp index 34c4a91f84..1cdc0e8661 100644 --- a/AirLib/include/common/StateReporter.hpp +++ b/AirLib/include/common/StateReporter.hpp @@ -54,6 +54,8 @@ class StateReporter { //TODO: need better line end handling void startHeading(string heading, uint heading_size, uint columns = 20) { + unused(heading_size); + unused(columns); ss_ << "\n"; ss_ << heading; } diff --git a/AirLib/include/common/UpdatableObject.hpp b/AirLib/include/common/UpdatableObject.hpp index 33782dac31..a05b1ad802 100644 --- a/AirLib/include/common/UpdatableObject.hpp +++ b/AirLib/include/common/UpdatableObject.hpp @@ -18,6 +18,7 @@ class UpdatableObject { virtual void reportState(StateReporter& reporter) { + unused(reporter); //default implementation doesn't do anything } diff --git a/AirLib/include/common/common_utils/AsyncTasker.hpp b/AirLib/include/common/common_utils/AsyncTasker.hpp index 5608d9c885..c995377529 100644 --- a/AirLib/include/common/common_utils/AsyncTasker.hpp +++ b/AirLib/include/common/common_utils/AsyncTasker.hpp @@ -10,7 +10,7 @@ class AsyncTasker { public: AsyncTasker(unsigned int thread_count = 4) - : threads_(thread_count), error_handler_([](std::exception e) {}) + : threads_(thread_count), error_handler_([](std::exception e) {unused(e);}) { } @@ -26,6 +26,7 @@ class AsyncTasker { if (iterations == 1) { threads_.push([=](int i) { + unused(i); try { func(); } @@ -36,6 +37,7 @@ class AsyncTasker { } else { threads_.push([=](int i) { + unused(i); try { for (unsigned int itr = 0; itr < iterations; ++itr) { func(); diff --git a/AirLib/include/common/common_utils/Utils.hpp b/AirLib/include/common/common_utils/Utils.hpp index f2632a5169..755d171904 100644 --- a/AirLib/include/common/common_utils/Utils.hpp +++ b/AirLib/include/common/common_utils/Utils.hpp @@ -79,6 +79,10 @@ static int _vscprintf(const char * format, va_list pargs) } #endif +// Call this on a function parameter to suppress the unused paramter warning +template inline +void unused(T const & result) { static_cast(result); } + namespace common_utils { class Utils { diff --git a/AirLib/include/controllers/ControllerBase.hpp b/AirLib/include/controllers/ControllerBase.hpp index 9854b2a61c..ad0549b731 100644 --- a/AirLib/include/controllers/ControllerBase.hpp +++ b/AirLib/include/controllers/ControllerBase.hpp @@ -30,6 +30,7 @@ class ControllerBase : public UpdatableObject { virtual void getStatusMessages(std::vector& messages) { + unused(messages); //default implementation } @@ -46,6 +47,7 @@ class ControllerBase : public UpdatableObject { virtual void reportTelemetry(float renderTime) { + unused(renderTime); //no default action } diff --git a/AirLib/include/controllers/rosflight/AirSimRosFlightBoard.hpp b/AirLib/include/controllers/rosflight/AirSimRosFlightBoard.hpp index 4300d68971..5db4edf135 100644 --- a/AirLib/include/controllers/rosflight/AirSimRosFlightBoard.hpp +++ b/AirLib/include/controllers/rosflight/AirSimRosFlightBoard.hpp @@ -86,6 +86,11 @@ class AirSimRosFlightBoard : public rosflight::Board { virtual void pwmInit(bool useCPPM, bool usePwmFilter, bool fastPWM, uint32_t motorPwmRate, uint16_t idlePulseUsec) override { + unused(useCPPM); + unused(usePwmFilter); + unused(fastPWM); + unused(motorPwmRate); + unused(idlePulseUsec); for (uint i = 0; i < OutputMotorCount; ++i) motors_pwm_[i] = 1000; for (uint i = 0; i < InputChannelCount; ++i) @@ -109,11 +114,14 @@ class AirSimRosFlightBoard : public rosflight::Board { virtual void set_led(uint8_t index, bool is_on) override { //ignored for now + unused(index); + unused(is_on); } virtual void toggle_led(uint8_t index) override { //ignored for now + unused(index); } virtual void init_params() override @@ -128,11 +136,13 @@ class AirSimRosFlightBoard : public rosflight::Board { virtual bool write_params(bool blink_led) override { + unused(blink_led); return false; } virtual void init_imu(uint16_t& acc1G, float& gyroScale, int boardVersion) override { + unused(boardVersion); //same as mpu6050_init acc1G = kAccelAdcBits; gyroScale = kGyroScale; @@ -173,6 +183,9 @@ class AirSimRosFlightBoard : public rosflight::Board { virtual void read_diff_pressure(float& differential_pressure, float& temp, float& velocity) override { + unused(differential_pressure); + unused(temp); + unused(velocity); throw std::runtime_error("Diff pressure sensor is not available"); } @@ -202,6 +215,7 @@ class AirSimRosFlightBoard : public rosflight::Board { virtual void system_reset(bool toBootloader) override { + unused(toBootloader); //no internal state to reset } diff --git a/AirLib/include/controllers/rosflight/AirSimRosFlightCommLink.hpp b/AirLib/include/controllers/rosflight/AirSimRosFlightCommLink.hpp index 73e7867454..7fe7abd755 100644 --- a/AirLib/include/controllers/rosflight/AirSimRosFlightCommLink.hpp +++ b/AirLib/include/controllers/rosflight/AirSimRosFlightCommLink.hpp @@ -36,18 +36,24 @@ class AirSimRosFlightCommLink : public rosflight::CommLink { virtual void set_sys_id(int32_t sys_id) { + unused(sys_id); } virtual void set_streaming_rate(uint16_t param_id, int32_t rate) { + unused(param_id); + unused(rate); } virtual void notify_param_change(uint16_t param_id, int32_t value) { + unused(param_id); + unused(value); } virtual void log_message(const char* message, uint8_t error_level) { + unused(error_level); messages_.push_back(std::string(message)); } diff --git a/AirLib/include/vehicles/MultiRotor.hpp b/AirLib/include/vehicles/MultiRotor.hpp index a2a64e6e2f..17ba965196 100644 --- a/AirLib/include/vehicles/MultiRotor.hpp +++ b/AirLib/include/vehicles/MultiRotor.hpp @@ -167,6 +167,8 @@ class MultiRotor : public PhysicsBody { void updateSensors(MultiRotorParams& params, const Kinematics::State& state, const Environment& environment) { + unused(state); + unused(environment); params.getSensors().update(); } diff --git a/AirLib/include/vehicles/MultiRotorParams.hpp b/AirLib/include/vehicles/MultiRotorParams.hpp index 2bd11504a4..7affed7783 100644 --- a/AirLib/include/vehicles/MultiRotorParams.hpp +++ b/AirLib/include/vehicles/MultiRotorParams.hpp @@ -94,6 +94,8 @@ class MultiRotorParams { //below method is needed to support firmwares without state estimation. In future, we should probably remove this support. virtual void initializePhysics(const Environment* environment, const Kinematics::State* kinematics) { + unused(environment); + unused(kinematics); //by default don't use it. If derived class needs this, it should override. } diff --git a/AirLib/src/controllers/DroneControllerBase.cpp b/AirLib/src/controllers/DroneControllerBase.cpp index 5ed6358699..02460126e7 100644 --- a/AirLib/src/controllers/DroneControllerBase.cpp +++ b/AirLib/src/controllers/DroneControllerBase.cpp @@ -30,6 +30,7 @@ float DroneControllerBase::getAutoLookahead(float velocity, float adaptive_looka float DroneControllerBase::getObsAvoidanceVelocity(float risk_dist, float max_obs_avoidance_vel) { + unused(risk_dist); return max_obs_avoidance_vel; } @@ -605,6 +606,7 @@ void DroneControllerBase::adjustYaw(float x, float y, DrivetrainType drivetrain, void DroneControllerBase::moveToPathPosition(const Vector3r& dest, float velocity, DrivetrainType drivetrain, /* pass by value */ YawMode yaw_mode, float last_z) { + unused(last_z); //validate dest if (dest.hasNaN()) throw std::invalid_argument(VectorMath::toString(dest,"dest vector cannot have NaN: ")); diff --git a/AirLib/src/controllers/MavLinkDroneController.cpp b/AirLib/src/controllers/MavLinkDroneController.cpp index 2b59f6af07..f6f07855da 100644 --- a/AirLib/src/controllers/MavLinkDroneController.cpp +++ b/AirLib/src/controllers/MavLinkDroneController.cpp @@ -44,6 +44,7 @@ class MavLinkLogViewerLog : public MavLinkLog proxy_ = proxy; } void write(const mavlinkcom::MavLinkMessage& msg, uint64_t timestamp = 0) override { + unused(timestamp); MavLinkMessage copy; ::memcpy(©, &msg, sizeof(MavLinkMessage)); proxy_->sendMessage(copy); @@ -146,6 +147,7 @@ struct MavLinkDroneController::impl { Utils::setValue(rotor_controls_, 0.0f); //TODO: main_node_->setMessageInterval(...); connection_->subscribe([=](std::shared_ptr connection, const MavLinkMessage& msg){ + unused(connection); processMavMessages(msg); }); @@ -153,6 +155,7 @@ struct MavLinkDroneController::impl { auto mavcon = mav_vehicle_->getConnection(); if (mavcon != connection_) { mavcon->subscribe([=](std::shared_ptr connection, const MavLinkMessage& msg) { + unused(connection); processMavMessages(msg); }); } @@ -217,6 +220,7 @@ struct MavLinkDroneController::impl { } else { connection->subscribe([=](std::shared_ptr connection_val, const MavLinkMessage& msg){ + unused(connection_val); processQgcMessages(msg); }); } @@ -799,6 +803,8 @@ struct MavLinkDroneController::impl { bool armDisarm(bool arm, CancelableBase& cancelable_action) { + unused(arm); + unused(cancelable_action); bool rc = false; mav_vehicle_->armDisarm(arm).wait(10000, &rc); return rc; @@ -838,6 +844,8 @@ struct MavLinkDroneController::impl { bool takeoff(float max_wait_seconds, CancelableBase& cancelable_action) { + unused(cancelable_action); + bool rc = false; auto vec = getPosition(); float z = vec.z() + getTakeoffZ(); @@ -871,6 +879,7 @@ struct MavLinkDroneController::impl { bool land(CancelableBase& cancelable_action) { + unused(cancelable_action); // bugbug: really need a downward pointing distance to ground sensor to do this properly, for now // we assume the ground is relatively flat an we are landing roughly at the home altitude. updateState(); @@ -905,6 +914,7 @@ struct MavLinkDroneController::impl { bool goHome(CancelableBase& cancelable_action) { + unused(cancelable_action); bool rc = false; if (!mav_vehicle_->returnToHome().wait(10000, &rc)) { throw VehicleMoveException("goHome - timeout waiting for response from drone"); @@ -948,11 +958,13 @@ struct MavLinkDroneController::impl { void setRCData(const RCData& rcData) { + unused(rcData); //TODO: use RC data to control MavLink drone } bool validateRCData(const RCData& rc_data) { + unused(rc_data); return true; } diff --git a/DroneShell/include/SimpleShell.hpp b/DroneShell/include/SimpleShell.hpp index a20aaa40b1..05b3fdd13c 100644 --- a/DroneShell/include/SimpleShell.hpp +++ b/DroneShell/include/SimpleShell.hpp @@ -129,6 +129,7 @@ class SimpleShell { private: ShellCommand(){} ShellCommand(ShellCommand& other){ + unused(other); } }; @@ -204,6 +205,7 @@ class SimpleShell { bool execute(const ShellCommandParameters& params) { + unused(params); return false; } }; @@ -218,6 +220,7 @@ class SimpleShell { bool execute(const ShellCommandParameters& params) { + unused(params); return true; } };