From 07ecf9e7bd6355209da9356f844220f14fab5aad Mon Sep 17 00:00:00 2001 From: whowechina Date: Sat, 23 Sep 2023 17:34:34 +0800 Subject: [PATCH] Better tof distance calc --- Production/Firmware/chu_pico.uf2 | Bin 119808 -> 119808 bytes firmware/src/air.c | 14 ++++++++---- firmware/src/air.h | 1 + firmware/src/cmd.c | 17 ++++++++++++++- firmware/src/config.c | 2 +- firmware/src/gp2y0e.h | 36 ++++++++++++++++++------------- 6 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Production/Firmware/chu_pico.uf2 b/Production/Firmware/chu_pico.uf2 index 8e0a02512caa40932c40ad7957f90db6354a6684..cb384b78e5ee2bcac2955ae999ddf72c7de4d1b6 100644 GIT binary patch delta 12139 zcmc(FdstIfy7yWkK!`*G0Spje=K@ARL_mvpL%*IM| z_TIns{@&YKd#%0KPVJG<+9RROPDx1kb)?L^ezHeWj%zaEyd5DXKL#<)e?v-yqzskb zb0wTpfxoKpVP+X;?L^}dlKmZZ0A!<_+Em0$cnK-*Ns)5Y5~Q47j!+1iI{E#RmT5*i zQquEHnjlH0_qUs9t`;1=O0U~%_sj$`a6s-l1U+Y_`ftHIqWAVG8Wl_IgacP z8LHp!#yNf+%GD6)!k3 zgSiGbW`en!WQa`FXPR3wlyVR^k320KUZcE#lw%6|A!X})rmi`dd#^Lv9Q3~ADE?yz z_Y1@jWRI8-VGiMLx`K8~cHyQF?ufGwce$qzx5*jCHFaWcjZ5)spLIp;Fhde=10G@XQo^^@OqZz_JhWVh+{ zVnOusr0_O3;)Z$7a}*Mp3V9WzLqUl7KI+Or zD`DiIe$^q<>k!r=xC(MlGsRnP&HmI;%bcjjg#ssiM?|Op87b4D2+CH8IgBfEB1YNf zBD4DrSnPJj7ppBZEx$VY418iw)qAoL8Cbp8WYyrKm`iaZ;{$t;7Bz)(Mi2g@1O^b| z{?z@w0}l`7k~{;^h8BvP?!M`e020%SC;|DP+vW%YMA3^R0dk1^(zk!yDOZqI2_40G zg0vBEeBePk+>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++ b/firmware/src/air.c @@ -48,9 +48,7 @@ void air_init() vl53l0x_init_tof(true); vl53l0x_start_continuous(0); } else if (tof_model[i] == 2) { - gp2y0e_write(I2C_PORT, 0xa8, 0); // Accumulation 0:1, 1:5, 2:30, 3:10 - gp2y0e_write(I2C_PORT, 0x3f, 0x30); // Filter 0x00:7, 0x10:5, 0x20:9, 0x30:1 - gp2y0e_write(I2C_PORT, 0x13, 5); // Pulse [3..7]:[40, 80, 160, 240, 320] us + gp2y03_init(I2C_PORT); } } } @@ -113,8 +111,16 @@ void air_update() if (tof_model[i] == 1) { distances[i] = readRangeContinuousMillimeters() * 10; } else if (tof_model[i] == 2) { - distances[i] = gp2y0e_dist16(I2C_PORT); + /* compensation based on observation, don't know why*/ + distances[i] = gp2y0e_dist16(I2C_PORT) * 16 / 10; } } } +uint16_t air_raw(uint8_t index) +{ + if (index >= sizeof(TOF_LIST)) { + return 0; + } + return distances[index]; +} diff --git a/firmware/src/air.h b/firmware/src/air.h index 08c00c2..8f8f618 100644 --- a/firmware/src/air.h +++ b/firmware/src/air.h @@ -12,6 +12,7 @@ void air_init(); size_t air_num(); unsigned air_value(uint8_t index); +uint16_t air_raw(uint8_t index); uint8_t air_bitmap(); void air_update(); diff --git a/firmware/src/cmd.c b/firmware/src/cmd.c index f88bde5..688ccad 100644 --- a/firmware/src/cmd.c +++ b/firmware/src/cmd.c @@ -8,6 +8,7 @@ #include "pico/stdlib.h" #include "config.h" +#include "air.h" #include "slider.h" #include "save.h" @@ -216,11 +217,20 @@ static void handle_tof(int argc, char *argv[]) const char *usage = "Usage: tof [pitch]\n" " offset: 40..255\n" " pitch: 4..50\n"; - if ((argc < 1) || (argc > 2)) { + if (argc > 2) { printf(usage); return; } + if (argc == 0) { + printf("TOF: "); + for (int i = air_num(); i > 0; i--) { + printf(" %4d", air_raw(i - 1) / 10); + } + printf("\n"); + return; + } + int offset = chu_cfg->tof.offset; int pitch = chu_cfg->tof.pitch; if (argc >= 1) { @@ -410,6 +420,11 @@ static void process_cmd() int argc; char *cmd = strtok(cmd_buf, " \n"); + + if (strlen(cmd) == 0) { + return; + } + argc = 0; while ((argc < MAX_PARAMETERS) && (argv[argc] = strtok(NULL, " \n")) != NULL) { diff --git a/firmware/src/config.c b/firmware/src/config.c index 159c6d1..79a79a3 100644 --- a/firmware/src/config.c +++ b/firmware/src/config.c @@ -27,7 +27,7 @@ static chu_cfg_t default_cfg = { }, .tof = { .offset = 64, - .pitch = 18, + .pitch = 28, }, .sense = { .filter = 0x11, diff --git a/firmware/src/gp2y0e.h b/firmware/src/gp2y0e.h index 52f7733..c5d0f5f 100644 --- a/firmware/src/gp2y0e.h +++ b/firmware/src/gp2y0e.h @@ -11,36 +11,42 @@ #define GP2Y0E_DEF_ADDR 0x40 -static inline bool gp2y0e_is_present(i2c_inst_t *i2c_port) +static inline uint16_t gp2y0e_write(i2c_inst_t *port, uint8_t addr, uint8_t val) +{ + uint8_t cmd[] = {addr, val}; + i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 2, false, time_us_64() + 1000); +} + +static inline void gp2y03_init(i2c_inst_t *port) +{ + gp2y0e_write(port, 0xa8, 0); // Accumulation 0:1, 1:5, 2:30, 3:10 + gp2y0e_write(port, 0x3f, 0x30); // Filter 0x00:7, 0x10:5, 0x20:9, 0x30:1 + gp2y0e_write(port, 0x13, 5); // Pulse [3..7]:[40, 80, 160, 240, 320] us +} + +static inline bool gp2y0e_is_present(i2c_inst_t *port) { uint8_t cmd[] = {0x5e}; - return i2c_write_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, cmd, 1, true, + return i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000) == 1; } -static inline uint16_t gp2y0e_write(i2c_inst_t *i2c_port, uint8_t addr, uint8_t val) -{ - uint8_t cmd[] = {addr, val}; - i2c_write_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, cmd, 2, false, time_us_64() + 1000); -} - -static inline uint8_t gp2y0e_dist(i2c_inst_t *i2c_port) +static inline uint8_t gp2y0e_dist(i2c_inst_t *port) { uint8_t cmd[] = {0x5e}; - i2c_write_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000); + i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000); uint8_t data; - i2c_read_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, &data, 1, false, time_us_64() + 1000); + i2c_read_blocking_until(port, GP2Y0E_DEF_ADDR, &data, 1, false, time_us_64() + 1000); return data; } - -static inline uint16_t gp2y0e_dist16(i2c_inst_t *i2c_port) +static inline uint16_t gp2y0e_dist16(i2c_inst_t *port) { uint8_t cmd[] = {0x5e}; - i2c_write_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000); + i2c_write_blocking_until(port, GP2Y0E_DEF_ADDR, cmd, 1, true, time_us_64() + 1000); uint8_t data[2]; - i2c_read_blocking_until(i2c_port, GP2Y0E_DEF_ADDR, data, 2, false, time_us_64() + 1000); + i2c_read_blocking_until(port, GP2Y0E_DEF_ADDR, data, 2, false, time_us_64() + 1000); return (data[0] << 4) | data[1]; }