42 #include <px4_platform_common/px4_config.h> 43 #include <px4_platform_common/defines.h> 47 #define DIR_READ (1<<7) 48 #define DIR_WRITE (0<<7) 49 #define ADDR_INCREMENT (1<<6) 52 #define CONVERSION_INTERVAL (1000000 / 100) 62 #define LSM303AGR_TIMER_REDUCTION 200 65 SPI(
"LSM303AGR", path, bus, device,
SPIDEV_MODE3, 8 * 1000 * 1000),
66 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
73 _device_id.devid = _device_id.devid;
106 PX4_ERR(
"SPI init failed");
145 uint8_t status_m = 0;
154 uint16_t OUTX_NOST = 0;
155 uint16_t OUTY_NOST = 0;
156 uint16_t OUTZ_NOST = 0;
160 for (
int i = 0; i < 50; i++) {
186 uint16_t OUTX_ST = 0;
187 uint16_t OUTY_ST = 0;
188 uint16_t OUTZ_ST = 0;
192 for (
int i = 0; i < 50; i++) {
201 const uint16_t abs_x =
abs(OUTX_ST - OUTX_NOST);
202 const uint16_t abs_y =
abs(OUTY_ST - OUTY_NOST);
203 const uint16_t abs_z =
abs(OUTZ_ST - OUTZ_NOST);
206 const bool x_valid = (abs_x > 0 && abs_x < UINT16_MAX);
207 const bool y_valid = (abs_y > 0 && abs_y < UINT16_MAX);
208 const bool z_valid = (abs_z > 0 && abs_z < UINT16_MAX);
210 if (!x_valid || !y_valid || !z_valid) {
212 PX4_ERR(
"self-test failed");
214 PX4_INFO(
"STATUS_M: %X", status_m);
215 PX4_INFO(
"ABS(OUTX_ST - OUTX_NOST) = %d", abs_x);
216 PX4_INFO(
"ABS(OUTY_ST - OUTY_NOST) = %d", abs_y);
217 PX4_INFO(
"ABS(OUTZ_ST - OUTZ_NOST) = %d", abs_z);
275 unsigned interval = (1000000 / arg);
314 return CDev::ioctl(filp, cmd, arg);
326 transfer(cmd, cmd,
sizeof(cmd));
339 transfer(cmd,
nullptr,
sizeof(cmd));
434 float xraw_f = mag_report.x_raw;
435 float yraw_f = mag_report.y_raw;
436 float zraw_f = mag_report.z_raw;
451 mag_report.device_id = _device_id.devid;
452 mag_report.is_external = external();
454 if (!(_pub_blocked)) {
void write_reg(unsigned reg, uint8_t value)
Write a register in the LSM303AGR.
#define MAGIOCGSCALE
copy the mag scaling constants to the structure pointed to by (arg)
#define MAGIOCGEXTERNAL
determine if mag is external or onboard
virtual int ioctl(struct file *filp, int cmd, unsigned long arg)
static constexpr uint8_t CFG_REG_C_M_I2C_DIS
void measure()
Issue a measurement command.
static struct vehicle_status_s status
measure the time elapsed performing an event
Definition of geo / math functions to perform geodesic calculations.
static constexpr uint8_t CFG_REG_A_M_ODR0
static constexpr uint8_t LSM303AGR_WHO_AM_I_M
void stop()
Stop automatic measurement.
uint8_t read_reg(unsigned reg)
Read a register from the LSM303AGR.
#define SENSOR_POLLRATE_DEFAULT
poll at driver normal rate
__EXPORT void rotate_3f(enum Rotation rot, float &x, float &y, float &z)
rotate a 3 element float vector in-place
mag scaling factors; Vout = (Vin * Vscale) + Voffset
static constexpr uint8_t OUTY_H_REG_M
void Run() override
Perform a poll cycle; collect from the previous measurement and start a new one.
Namespace encapsulating all device framework classes, functions and data.
count the number of times an event occurs
int _mag_orb_class_instance
void start()
Start automatic measurement.
static constexpr uint8_t CFG_REG_A_M
static constexpr uint8_t WHO_AM_I_M
perf_counter_t _bad_values
#define SENSORIOCSPOLLRATE
Set the driver polling rate to (arg) Hz, or one of the SENSOR_POLLRATE constants. ...
static constexpr uint8_t CFG_REG_B_M_OFF_CANC
#define CONVERSION_INTERVAL
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
#define DRV_MAG_DEVTYPE_LSM303AGR
#define MAGIOCSSCALE
set the mag scaling constants to the structure pointed to by (arg)
void perf_free(perf_counter_t handle)
Free a counter.
#define MAG_BASE_DEVICE_PATH
void init()
Activates/configures the hardware registers.
static constexpr uint8_t CFG_REG_A_M_ODR1
Rotation
Enum for board and external compass rotations.
static constexpr uint8_t CFG_REG_C_M
unsigned _measure_interval
void perf_end(perf_counter_t handle)
End a performance event.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
static constexpr uint8_t OUTY_L_REG_M
static constexpr uint8_t OUTX_L_REG_M
mag_calibration_s _mag_scale
static constexpr uint8_t OUTZ_L_REG_M
static constexpr uint8_t OUTZ_H_REG_M
struct @83::@85::@87 file
perf_counter_t _mag_sample_perf
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
#define SENSORIOCRESET
Reset the sensor to its default configuration.
uint64_t perf_event_count(perf_counter_t handle)
Return current event_count.
LSM303AGR(int bus, const char *path, uint32_t device, enum Rotation rotation)
void print_info()
Diagnostics - print some basic information about the driver.
static constexpr uint8_t STATUS_REG_M_Zyxda
int collect()
Collect the result of the most recent measurement.
static constexpr uint8_t STATUS_REG_M
Dual< Scalar, N > abs(const Dual< Scalar, N > &a)
static constexpr uint8_t CFG_REG_B_M
orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority)
static constexpr uint8_t CFG_REG_B_M_OFF_LPF
void perf_begin(perf_counter_t handle)
Begin a performance event.
perf_counter_t _bad_registers
#define DEVICE_DEBUG(FMT,...)
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static constexpr uint8_t OUTX_H_REG_M
static constexpr uint8_t CFG_REG_A_M_MD0
static constexpr float _mag_range_scale