Line data Source code
1 : #pragma once 2 : 3 : /* 4 : Simulator for the MaxsonarI2XL rangefinder 5 : 6 : ./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduCopter --speedup=1 7 : 8 : param set RNGFND1_TYPE 2 9 : graph RANGEFINDER.distance 10 : graph GLOBAL_POSITION_INT.relative_alt/1000-RANGEFINDER.distance 11 : reboot 12 : 13 : arm throttle 14 : rc 3 1600 15 : */ 16 : 17 : #include "SIM_config.h" 18 : 19 : #if AP_SIM_MAXSONAR_I2C_XL_ENABLED 20 : 21 : #include "SIM_I2CDevice.h" 22 : 23 : namespace SITL { 24 : 25 : class MaxSonarI2CXL : public I2CDevice, public I2CCommandResponseDevice 26 : { 27 : public: 28 : 29 : // methods to make I2CCommandResponseDevice happy: 30 4510 : uint8_t command_take_reading() const override { return 0x51; } 31 4502 : uint16_t reading() const override { 32 4502 : return rangefinder_range * 100; 33 : }; 34 : 35 357519884 : void update(const class Aircraft &aircraft) override { 36 357519884 : rangefinder_range = aircraft.rangefinder_range(); 37 357519884 : } 38 : 39 9012 : int rdwr(I2C::i2c_rdwr_ioctl_data *&data) override { 40 9012 : return I2CCommandResponseDevice::rdwr(data); 41 : } 42 : 43 : 44 : private: 45 : 46 : float rangefinder_range; 47 : }; 48 : 49 : } // namespace SITL 50 : 51 : #endif // AP_SIM_MAXSONAR_I2C_XL_ENABLED