37 ScheduledWorkItem(MODULE_NAME,
px4::serial_port_to_wq(port)),
70 PX4_ERR(
"invalid HW model %d.", hw_model);
80 _fd = ::open(
_port, O_RDWR | O_NOCTTY);
83 PX4_ERR(
"Error opening fd");
88 unsigned speed = B115200;
89 termios uart_config{};
92 tcgetattr(
_fd, &uart_config);
95 uart_config.c_oflag &= ~ONLCR;
98 if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) {
99 PX4_ERR(
"CFG: %d ISPD", termios_state);
104 if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) {
105 PX4_ERR(
"CFG: %d OSPD\n", termios_state);
110 if ((termios_state = tcsetattr(
_fd, TCSANOW, &uart_config)) < 0) {
111 PX4_ERR(
"baud %d ATTR", termios_state);
116 uart_config.c_cflag |= (CLOCAL | CREAD);
117 uart_config.c_cflag &= ~CSIZE;
118 uart_config.c_cflag |= CS8;
119 uart_config.c_cflag &= ~PARENB;
120 uart_config.c_cflag &= ~CSTOPB;
121 uart_config.c_cflag &= ~CRTSCTS;
124 uart_config.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
125 uart_config.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
126 uart_config.c_oflag &= ~OPOST;
129 uart_config.c_cc[VMIN] = 1;
130 uart_config.c_cc[VTIME] = 1;
133 PX4_ERR(
"FAIL: laser fd");
160 unsigned readlen =
sizeof(readbuf) - 1;
163 float distance_m = -1.0f;
166 int bytes_available = 0;
167 ::ioctl(
_fd, FIONREAD, (
unsigned long)&bytes_available);
169 if (!bytes_available) {
182 PX4_ERR(
"read err: %d", ret);
189 tcflush(
_fd, TCIFLUSH);
200 for (
int i = 0; i < ret; i++) {
205 bytes_available -= ret;
207 }
while (bytes_available > 0);
210 if (distance_m < 0.0
f) {
227 ScheduleOnInterval(100_us);
242 _fd = ::open(
_port, O_RDWR | O_NOCTTY);
249 ScheduleOnInterval(100_us, 87 * 9);
257 printf(
"Using port '%s'\n",
_port);
void set_max_distance(const float distance)
void set_fov(const float fov)
TFMINI_PARSE_STATE _parse_state
int tfmini_parse(char c, char *parserbuf, unsigned *parserbuf_index, TFMINI_PARSE_STATE *state, float *dist)
unsigned int _linebuf_index
static void read(bootloader_app_shared_t *pshared)
void update(const hrt_abstime timestamp, const float distance, const int8_t quality=-1)
void perf_count(perf_counter_t handle)
Count a performance event.
void perf_free(perf_counter_t handle)
Free a counter.
constexpr T radians(T degrees)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
void set_min_distance(const float distance)
TFMINI(const char *port, uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING)
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
PX4Rangefinder _px4_rangefinder
void perf_end(perf_counter_t handle)
End a performance event.
perf_counter_t _sample_perf
__BEGIN_DECLS typedef uint64_t hrt_abstime
Absolute time, in microsecond units.
static constexpr int kCONVERSIONINTERVAL
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
void perf_begin(perf_counter_t handle)
Begin a performance event.
perf_counter_t _comms_errors
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).