48 #include <px4_platform_common/getopt.h> 49 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 56 #define IRLOCK_I2C_BUS PX4_I2C_BUS_EXPANSION 57 #define IRLOCK_I2C_ADDRESS 0x54 58 #define IRLOCK_CONVERSION_INTERVAL_US 20000U 60 #define IRLOCK_SYNC 0xAA55 61 #define IRLOCK_RESYNC 0x5500 62 #define IRLOCK_ADJUST 0xAA 64 #define IRLOCK_RES_X 320 65 #define IRLOCK_RES_Y 200 67 #define IRLOCK_CENTER_X (IRLOCK_RES_X/2) // the x-axis center pixel position 68 #define IRLOCK_CENTER_Y (IRLOCK_RES_Y/2) // the y-axis center pixel position 70 #define IRLOCK_FOV_X (60.0f*M_PI_F/180.0f) 71 #define IRLOCK_FOV_Y (35.0f*M_PI_F/180.0f) 73 #define IRLOCK_TAN_HALF_FOV_X 0.57735026919f // tan(0.5 * 60 * pi/180) 74 #define IRLOCK_TAN_HALF_FOV_Y 0.31529878887f // tan(0.5 * 35 * pi/180) 76 #define IRLOCK_TAN_ANG_PER_PIXEL_X (2*IRLOCK_TAN_HALF_FOV_X/IRLOCK_RES_X) 77 #define IRLOCK_TAN_ANG_PER_PIXEL_Y (2*IRLOCK_TAN_HALF_FOV_Y/IRLOCK_RES_Y) 79 #define IRLOCK_BASE_DEVICE_PATH "/dev/irlock" 80 #define IRLOCK0_DEVICE_PATH "/dev/irlock0" 82 #define IRLOCK_OBJECTS_MAX 5 99 class IRLOCK :
public device::I2C,
public px4::ScheduledWorkItem
110 virtual ssize_t
read(
struct file *filp,
char *buffer,
size_t buflen);
126 int read_device_word(uint16_t *word);
141 IRLOCK *g_irlock =
nullptr;
151 ScheduledWorkItem(MODULE_NAME,
px4::device_bus_to_wq(get_device_id())),
155 _orb_class_instance(-1),
156 _irlock_report_topic(nullptr)
205 if (transfer(
nullptr, 0, &byte, 1) !=
OK) {
215 if (g_irlock ==
nullptr) {
216 errx(1,
"irlock device driver is not running");
221 _reports->print_info(
"report queue: ");
225 warnx(
"sensor is not healthy");
235 if (g_irlock ==
nullptr) {
236 errx(1,
"irlock device driver is not running");
241 errx(1,
"sensor is not healthy");
245 warnx(
"searching for object for 10 seconds");
255 warnx(
"sig:%d x:%4.3f y:%4.3f width:%4.3f height:%4.3f",
298 unsigned count = buflen /
sizeof(
struct irlock_s);
309 ret +=
sizeof(*rbuf);
314 return ret ? ret : -EAGAIN;
330 transfer(
nullptr, 0, &sync_byte, 1);
385 DEVICE_LOG(
"failed to create irlock_report object. Did you start uOrb?");
397 memset(bytes, 0,
sizeof bytes);
399 int status = transfer(
nullptr, 0, &bytes[0], 2);
400 *word = bytes[1] << 8 | bytes[0];
409 memset(bytes, 0,
sizeof bytes);
411 int status = transfer(
nullptr, 0, &bytes[0], 12);
412 uint16_t checksum = bytes[1] << 8 | bytes[0];
413 uint16_t
signature = bytes[3] << 8 | bytes[2];
414 uint16_t pixel_x = bytes[5] << 8 | bytes[4];
415 uint16_t pixel_y = bytes[7] << 8 | bytes[6];
416 uint16_t pixel_size_x = bytes[9] << 8 | bytes[8];
417 uint16_t pixel_size_y = bytes[11] << 8 | bytes[10];
420 if (signature + pixel_x + pixel_y + pixel_size_x + pixel_size_y != checksum) {
436 warnx(
"missing command: try 'start', 'stop', 'info', 'test'");
447 const char *myoptarg =
nullptr;
449 while ((ch = px4_getopt(argc, argv,
"b:", &myoptind, &myoptarg)) != EOF) {
452 i2cdevice = (uint8_t)atoi(myoptarg);
456 PX4_WARN(
"Unknown option!");
461 if (myoptind >= argc) {
466 const char *
command = argv[myoptind];
469 if (!strcmp(command,
"start")) {
470 if (g_irlock !=
nullptr) {
471 errx(1,
"driver has already been started");
477 if (g_irlock ==
nullptr) {
478 errx(1,
"failed to allocated memory for driver");
482 if (g_irlock->init() !=
OK) {
483 IRLOCK *tmp_irlock = g_irlock;
486 errx(1,
"failed to initialize device, stopping driver");
493 if (g_irlock ==
nullptr) {
494 warnx(
"not started");
500 if (!strcmp(command,
"stop")) {
501 IRLOCK *tmp_irlock = g_irlock;
504 warnx(
"irlock stopped");
509 if (!strcmp(command,
"info")) {
515 if (!strcmp(command,
"test")) {
orb_advert_t _irlock_report_topic
float pos_y
x-axis distance from center of image to center of target in units of tan(theta)
void start()
start periodic reads from sensor
int read_device_word(uint16_t *word)
read a word (two bytes) from sensor
static struct vehicle_status_s status
virtual int init()
initialise driver to communicate with sensor
int read_device()
low level communication with sensor
API for the uORB lightweight object broker.
float pos_x
target signature
bool sync_device()
sync device to ensure reading starts at new frame
int info()
Print a little info about the driver.
#define IRLOCK_OBJECTS_MAX
#define IRLOCK_TAN_ANG_PER_PIXEL_X
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen)
#define IRLOCK_I2C_BUS
Configuration Constants.
virtual ~IRLOCK()
destructor
virtual int test()
test driver
static void read(bootloader_app_shared_t *pshared)
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
#define IRLOCK_CONVERSION_INTERVAL_US
void init()
Activates/configures the hardware registers.
#define DEVICE_LOG(FMT,...)
__EXPORT int irlock_main(int argc, char *argv[])
virtual int info()
display driver info
int read_device_block(struct irlock_target_s *block)
read a single block (a full frame) from sensor
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
void test(enum LPS25H_BUS busid)
Perform some basic functional tests on the driver; make sure we can collect data from the sensor in p...
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
ringbuffer::RingBuffer * _reports
internal variables
float size_y
size of target along x-axis in units of tan(theta)
#define IRLOCK_TAN_ANG_PER_PIXEL_Y
struct irlock_target_s targets[IRLOCK_OBJECTS_MAX]
void Run() override
read from device and schedule next read
irlock_s structure returned from read calls
struct @83::@85::@87 file
#define IRLOCK0_DEVICE_PATH
IRLOCK(int bus=IRLOCK_I2C_BUS, int address=IRLOCK_I2C_ADDRESS)
constructor
#define IRLOCK_I2C_ADDRESS
void stop()
stop periodic reads from sensor
orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, int priority)
uint8_t num_targets
microseconds since system start
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
float size_x
y-axis distance from center of image to center of target in units of tan(theta)
virtual int probe()
probe the device is on the I2C bus
Base class for devices connected via I2C.