烧写flash出错:Bytes mismatch 0x00不等于0xFF

本文介绍了一种常见的烧写Flash过程中遇到的BytesMismatch问题,即0x00!=0xFF的情况,并给出了一个简单的解决方案:重启Vivado通常可以解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 问题

烧写flash 出现bytes mismatch 0x00 != 0xFF 之类的问题。

2 解决

暂时重启vivado可以解决。

hi309a /lib/udrivers # cat /proc/interrupts | grep i2c 87: 0 0 0 0 0 0 0 0 GICv3 294 Level hisi-i2c 88: 0 0 0 0 0 0 0 0 GICv3 295 Level hisi-i2c 89: 0 0 0 0 0 0 0 0 GICv3 297 Level hisi-i2c 90: 0 0 0 0 0 0 0 0 GICv3 298 Level hisi-i2c 91: 0 0 0 0 0 0 0 0 GICv3 299 Level hisi-i2c 92: 0 0 0 0 0 0 0 0 GICv3 300 Level hisi-i2c 93: 0 0 0 0 0 0 0 0 GICv3 301 Level hisi-i2c 94: 0 0 0 0 0 0 0 0 GICv3 686 Level hisi-i2c 95: 0 0 0 0 0 0 0 0 GICv3 687 Level hisi-i2c hi309a /lib/udrivers # dmesg | grep -e "iWare" -e "PMBUS" [ 10.511319] [iWare][Info] IOMUX register size (4 bytes) [ 10.519453] hgpio fa540000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.526277] hgpio fa550000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.533075] hgpio fa560000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.539847] hgpio fa570000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.546656] hgpio fa580000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.553439] hgpio fa590000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.560210] hgpio fa5a0000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.567034] hgpio fa5b0000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.573814] hgpio faa90000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.580559] hgpio faaa0000.gpio: [iWare][Info] hisi_gpio_probe: start [ 10.590111] hisi_spi_drv fa400000.spi: [iWare] can't get clk-freq, use default value [ 10.597941] hisi_spi_drv fa400000.spi: [iWare][Info] [hisi spi_get_clk_rst_info] get rst clk success [ 10.607234] hisi_spi_drv fa400000.spi: [iWare][Info] spi reset success [ 10.614459] hisi_spi_drv fa410000.spi: [iWare] can't get clk-freq, use default value [ 10.622295] hisi_spi_drv fa410000.spi: [iWare][Info] [hisi spi_get_clk_rst_info] get rst clk success [ 10.631589] hisi_spi_drv fa410000.spi: [iWare][Info] spi reset success [ 10.638791] hisi_spi_drv fa420000.spi: [iWare] can't get clk-freq, use default value [ 10.646633] hisi_spi_drv fa420000.spi: [iWare][Info] [hisi spi_get_clk_rst_info] get rst clk success [ 10.655934] hisi_spi_drv fa420000.spi: [iWare][Info] spi reset success [ 10.663149] hisi_spi_drv fa430000.spi: [iWare] can't get clk-freq, use default value [ 10.670998] hisi_spi_drv fa430000.spi: [iWare][Info] [hisi spi_get_clk_rst_info] get rst clk success [ 10.680292] hisi_spi_drv fa430000.spi: [iWare][Info] spi reset success [ 10.690479] hisi-i2c fa380000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.697006] hisi-i2c fa380000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.703944] hisi-i2c fa380000.i2c: [iWare][Info] get rst and clk from dts [ 10.719963] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 10.732890] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 10.742442] hisi-i2c fa380000.i2c: [iWare][Info] hisi_i2c_probe end [ 10.749010] hisi-i2c fa390000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.755526] hisi-i2c fa390000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.762448] hisi-i2c fa390000.i2c: [iWare][Info] get rst and clk from dts [ 10.778437] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 10.791367] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 10.800891] hisi-i2c fa390000.i2c: [iWare][Info] hisi_i2c_probe end [ 10.807415] hisi-i2c fa3b0000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.813923] hisi-i2c fa3b0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.820847] hisi-i2c fa3b0000.i2c: [iWare][Info] get rst and clk from dts [ 10.836836] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 10.849764] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 10.859275] hisi-i2c fa3b0000.i2c: [iWare][Info] hisi_i2c_probe end [ 10.865787] hisi-i2c fa3c0000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.872298] hisi-i2c fa3c0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.879223] hisi-i2c fa3c0000.i2c: [iWare][Info] get rst and clk from dts [ 10.895207] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 10.908133] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 10.917641] hisi-i2c fa3c0000.i2c: [iWare][Info] hisi_i2c_probe end [ 10.924135] hisi-i2c fa3d0000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.930644] hisi-i2c fa3d0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.937559] hisi-i2c fa3d0000.i2c: [iWare][Info] get rst and clk from dts [ 10.953538] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 10.966464] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 10.975986] hisi-i2c fa3d0000.i2c: [iWare][Info] hisi_i2c_probe end [ 10.982483] hisi-i2c fa3e0000.i2c: [iWare][Info] hisi_i2c_probe start [ 10.988993] hisi-i2c fa3e0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 10.995908] hisi-i2c fa3e0000.i2c: [iWare][Info] get rst and clk from dts [ 11.011896] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 11.024821] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 11.034336] hisi-i2c fa3e0000.i2c: [iWare][Info] hisi_i2c_probe end [ 11.040848] hisi-i2c fa3f0000.i2c: [iWare][Info] hisi_i2c_probe start [ 11.047359] hisi-i2c fa3f0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 11.054275] hisi-i2c fa3f0000.i2c: [iWare][Info] get rst and clk from dts [ 11.070263] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 11.083190] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 11.092704] hisi-i2c fa3f0000.i2c: [iWare][Info] hisi_i2c_probe end [ 11.099221] hisi-i2c faab0000.i2c: [iWare][Info] hisi_i2c_probe start [ 11.105733] hisi-i2c faab0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 11.112649] hisi-i2c faab0000.i2c: [iWare][Info] get rst and clk from dts [ 11.128636] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 11.141563] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 11.151068] hisi-i2c faab0000.i2c: [iWare][Info] hisi_i2c_probe end [ 11.157580] hisi-i2c faac0000.i2c: [iWare][Info] hisi_i2c_probe start [ 11.164093] hisi-i2c faac0000.i2c: [iWare][Info] i2c scl_high_ratio no cfg [ 11.171009] hisi-i2c faac0000.i2c: [iWare][Info] get rst and clk from dts [ 11.186998] [iWare][Info] hisi_i2c_calcu_cfg_cnt bus_freq_hz 100000, scl_fall_cnt 60 scl_rise_cnt 60 total_cnt 2000 scl_hcnt 920 scl_lcnt 1080 [ 11.199925] [iWare][Info] hisi_i2c_calcu_cfg_cnt sda_hold_cnt 80 spk_len 5 scl_hcnt 848 scl_lcnt 1019 [ 11.209444] hisi-i2c faac0000.i2c: [iWare][Info] hisi_i2c_probe end [ 11.218700] pmbus_drv fa870000.pmbus0: [iWare][Info] hisi_pmbus_probe:start [ 11.225815] pmbus_drv fa870000.pmbus0: [iWare][Info] clk_freq 200 bus_freq 100000 scl_high_ratio 50, timeout_ms 35 high_idle_us 100 hold_time_ns 625 [ 11.239267] pmbus_drv fa870000.pmbus0: [iWare][Info] avs_wr_unlock_key 0x5a5a5a5a pmbus_wr_unlock_key 0x5a5a5a5a i2c_unlock_key 0x5a5a5a5a [ 11.251844] [iWare][Info] total_cnt 2000, hcnt=1000, lcnt=1000 hold_cnt=125, timeout_cnt=7000000, idle_cnt=20000, [ 11.262158] pmbus_drv fa870000.pmbus0: [iWare][Info] hisi_pmbus_probe: end [ 11.269205] pmbus_drv fa880000.pmbus1: [iWare][Info] hisi_pmbus_probe:start [ 11.276309] pmbus_drv fa880000.pmbus1: [iWare][Info] clk_freq 200 bus_freq 100000 scl_high_ratio 50, timeout_ms 35 high_idle_us 100 hold_time_ns 625 [ 11.289760] pmbus_drv fa880000.pmbus1: [iWare][Info] avs_wr_unlock_key 0x5a5a5a5a pmbus_wr_unlock_key 0x5a5a5a5a i2c_unlock_key 0x5a5a5a5a [ 11.302337] [iWare][Info] total_cnt 2000, hcnt=1000, lcnt=1000 hold_cnt=125, timeout_cnt=7000000, idle_cnt=20000, [ 11.312651] pmbus_drv fa880000.pmbus1: [iWare][Info] hisi_pmbus_probe: end [ 11.319689] pmbus_drv fa890000.pmbus2: [iWare][Info] hisi_pmbus_probe:start [ 11.326788] pmbus_drv fa890000.pmbus2: [iWare][Info] clk_freq 200 bus_freq 100000 scl_high_ratio 50, timeout_ms 35 high_idle_us 100 hold_time_ns 625 [ 11.340247] pmbus_drv fa890000.pmbus2: [iWare][Info] avs_wr_unlock_key 0x5a5a5a5a pmbus_wr_unlock_key 0x5a5a5a5a i2c_unlock_key 0x5a5a5a5a [ 11.352823] [iWare][Info] total_cnt 2000, hcnt=1000, lcnt=1000 hold_cnt=125, timeout_cnt=7000000, idle_cnt=20000, [ 11.363138] pmbus_drv fa890000.pmbus2: [iWare][Info] hisi_pmbus_probe: end [ 11.370173] pmbus_drv fa8a0000.pmbus3: [iWare][Info] hisi_pmbus_probe:start [ 11.377269] pmbus_drv fa8a0000.pmbus3: [iWare][Info] clk_freq 200 bus_freq 100000 scl_high_ratio 50, timeout_ms 35 high_idle_us 100 hold_time_ns 625 [ 11.390720] pmbus_drv fa8a0000.pmbus3: [iWare][Info] avs_wr_unlock_key 0x5a5a5a5a pmbus_wr_unlock_key 0x5a5a5a5a i2c_unlock_key 0x5a5a5a5a [ 11.403295] [iWare][Info] total_cnt 2000, hcnt=1000, lcnt=1000 hold_cnt=125, timeout_cnt=7000000, idle_cnt=20000, [ 11.413609] pmbus_drv fa8a0000.pmbus3: [iWare][Info] hisi_pmbus_probe: end [ 11.423408] sfc_drv fa5c0000.sfc0: [iWare][Info]sfc skip_host_reset 0, 0, 0, 0 [ 11.430719] sfc_drv fa5c0000.sfc0: [iWare][Info]clk_div= 2, hsfc->dummy_cnt= 4! 0, 0 [ 11.438504] sfc_drv fa5c0000.sfc0: [iWare][Info]hisi_sfc_register_nor! 0, 0, 0, 0 [ 11.446026] sfc_drv fa5c0000.sfc0: [iWare][Info]sfc-rx-bus-width = 1, 0, 0, 0 [ 11.453193] sfc_drv fa5c0000.sfc0: [iWare][Info]sfc-tx-bus-width = 1, 0, 0, 0 [ 11.466267] sfc_drv fa5c0000.sfc0: [iWare][Info]after spi_nor_scan read_proto(0x10101),write_proto(0x10101)addr_width(0x4),erase_op(0x21) [ 11.478678] sfc_drv fa5c0000.sfc0: [iWare][Info]read_op(0x13), dummy(0x0),pp_op(0x12),erasesize 4096 [ 11.520738] sfc_drv fa5c0000.sfc0: [iWare][Info]hisi_sfc_register_nor! 0, 0, 0, 0 [ 11.528272] sfc_drv fa5c0000.sfc0: [iWare][Info]sfc-rx-bus-width = 1, 0, 0, 0 [ 11.535443] sfc_drv fa5c0000.sfc0: [iWare][Info]sfc-tx-bus-width = 1, 0, 0, 0 [ 11.550161] sfc_drv fa5c0000.sfc0: [iWare][Error]cs 1 spi_nor_scan fail! 0, 0, 0 [ 11.557594] sfc_drv fa5c0000.sfc0: [iWare][Error]hisi_sfc_register_nor fail! 0, 0, 0, 0 [ 11.565636] sfc_drv fa5c0000.sfc0: [iWare][Info]total_blk_num =16384, 0, 0, 0 [ 11.572806] [iWare][Info]hisi_sfc_dfx_count_init, use malloc mem! 0, 0, 0, 0 [ 11.579930] [iWare][Info]init_mem_area inited success! 0, 0, 0, 0 [ 11.586324] [iWare][Info]init_mem_area inited success! 0, 0, 0, 0 [ 11.600428] hilink serdes: [iWare][Info]clock_route_mode not config, use default mode 0, 0000 [ 11.609108] hilink serdes: [iWare][Info]lane 0 dfe_param not cfg! defalut dfe = <1 1> 000 [ 11.617414] hilink serdes: [iWare][Info]lane 1 dfe_param not cfg! defalut dfe = <1 1> 000 [ 11.625717] hilink serdes: [iWare][Info]lane 8 dfe_param not cfg! defalut dfe = <1 1> 000 [ 11.634020] hilink serdes: [iWare][Info]lane 9 dfe_param not cfg! defalut dfe = <1 1> 000 [ 11.649135] hilink serdes: [iWare][Info]hserdes->reset_mode 0, 000 [ 11.655377] [iWare][Info]chip0 sema_wr init ... pass! [ 11.655383] [iWare][Info]chip_serdes_hardware_init ok [ 11.665533] [iWare][Info]Serdes init from dts, lane_mask = 0x3ff pcie_gen4_link_mode=0 00 [ 11.673748] [iWare][Info]macro_id=2, pcie_cnt=2, sata_cnt=0, 0 [ 11.679699] [iWare][Info]macro_id=2 serdes_reinit, 000 [ 11.684948] [iWare][Info]serdes_reinit:macro_id=2 lane_id=0, mac_id 5 rate:11 pcie_mode 2, pcie_width 2 [ 11.694474] [iWare][Info]serdes_reinit:macro_id=2 lane_id=1, mac_id 5 rate:11 pcie_mode 2, pcie_width 2 [ 11.704009] [iWare][Info]hisds_cs_init_det match, sds_id 6 cs need init [ 11.710658] [iWare][Info]hisds_cs_init_det match, sds_id 7 cs need init [ 11.717325] [iWare][Info]chip30_serdes_par_init_process line 142 macro 2 powerup [ 11.766898] [iWare][Info][macro_fw_init_calibration]Macro calibration success [ 11.776892] [iWare][Info]Adapt Config success! [ 11.776897] [iWare][Info]serdes_macro_init, macro_id=2 single_lane_init_mask=0xc 00 [ 11.789225] [iWare][Info]macro_id:2, lane:2,serdes_single_lane_init 00 [ 11.795875] [iWare][Info]chip_serdes_lane_init phy_sds_id 8 cs need init [ 11.802699] [iWare][Info]csinfo: macro_id = 2, pll_id = 0, rate = 6, refclk = 156250, refclk_sel = 0, vco_freq = 15000000, hs_clk = 10000000, use_mode = 64 [ 11.821475] [iWare][Info]Clockslice calibration success! [ 11.827123] [iWare][Info]ds 2 firmware reset success! [ 11.840429] [iWare][Info]macro_id:2, lane:3,serdes_single_lane_init 00 [ 11.852146] [iWare][Info]chip_serdes_lane_init phy_sds_id 9 cs no need init [ 11.859238] [iWare][Info]ds 3 firmware reset success! [ 11.873344] [iWare][Info]macro_id=0, pcie_cnt=0, sata_cnt=0, 0 [ 11.884364] [iWare][Info]macro_id=0 serdes_reinit, 000 [ 11.889613] [iWare][Info]serdes_reinit:macro_id=0 lane_id=0, mac_id 4 rate:2 pcie_mode 0, pcie_width 0 [ 11.899048] [iWare][Info]serdes_reinit:macro_id=0 lane_id=1, mac_id 5 rate:2 pcie_mode 0, pcie_width 0 [ 11.908483] [iWare][Info]serdes_reinit:macro_id=0 lane_id=2, mac_id 0 rate:18 pcie_mode 0, pcie_width 0 [ 11.918006] [iWare][Info]serdes_reinit:macro_id=0 lane_id=3, mac_id 1 rate:18 pcie_mode 0, pcie_width 0 [ 11.927536] [iWare][Info]hisds_cs_init_det match, sds_id 0 cs need init [ 11.934183] [iWare][Info]hisds_cs_init_det match, sds_id 1 cs need init [ 11.940830] [iWare][Info]hisds_cs_init_det match, sds_id 2 cs need init [ 11.947476] [iWare][Info]hisds_cs_init_det match, sds_id 3 cs need init [ 11.954142] [iWare][Info]chip30_serdes_par_init_process line 142 macro 0 powerup [ 12.008900] [iWare][Info][macro_fw_init_calibration]Macro calibration success [ 12.018886] [iWare][Info]Adapt Config success! [ 12.018890] [iWare][Info]serdes_macro_init, macro_id=0 single_lane_init_mask=0x0 00 [ 12.031220] [iWare][Info]macro_id=1, pcie_cnt=1, sata_cnt=1, 0 [ 12.037168] [iWare][Info]macro_id=1 serdes_reinit, 000 [ 12.042417] [iWare][Info]serdes_reinit:macro_id=1 lane_id=1, mac_id 0 rate:13 pcie_mode 2, pcie_width 1 [ 12.051947] [iWare][Info]hisds_cs_init_det match, sds_id 5 cs need init [ 12.058614] [iWare][Info]chip30_serdes_par_init_process line 142 macro 1 powerup [ 12.109900] [iWare][Info][macro_fw_init_calibration]Macro calibration success [ 12.119886] [iWare][Info]Adapt Config success! [ 12.119890] [iWare][Info]serdes_macro_init, macro_id=1 single_lane_init_mask=0x1 00 [ 12.132220] [iWare][Info]macro_id:1, lane:0,serdes_single_lane_init 00 [ 12.138866] [iWare][Info]chip_serdes_lane_init phy_sds_id 4 cs need init [ 12.145690] [iWare][Info]csinfo: macro_id = 1, pll_id = 0, rate = 17, refclk = 100000, refclk_sel = 1, vco_freq = 12000000, hs_clk = 6000000, use_mode = 2 [ 12.164643] [iWare][Info]Clockslice calibration success! [ 12.170081] [iWare][Info]ds 0 firmware reset success! [ 12.181352] [iWare][Info]serdes_ds_dfe_init: macro(0) ds(0) dfe init 1 1 [ 12.193266] [iWare][Info]serdes_ds_dfe_init: macro(0) ds(1) dfe init 1 1 [ 12.200006] [iWare][Info]serdes_ds_dfe_init: macro(2) ds(2) dfe init 1 1 [ 12.206846] [iWare][Info]serdes_ds_dfe_init: macro(2) ds(3) dfe init 1 1 [ 12.217692] udrv-pcie b00000000.pcie: [iWare] no declare type support, default rp mode [ 12.240709] [iWare][Info] host_id: 0x0 [ 12.244913] [iWare][Info] host_support_type_mask: 0x2 [ 12.249989] [iWare][Info] core_version: 0x0 [ 12.254190] [iWare][Info] msi_irq: 0x45 [ 12.258479] [iWare][Info] clk_num: 0x2 [ 12.262681] [iWare][Info] rst_num: 0x1 [ 12.266884] [iWare][Info] port_id: 0x0 [ 12.271085] [iWare][Info] port_type: 0x1 [ 12.275286] [iWare][Info] lport_id: 0x0 [ 12.279487] [iWare][Info] idr: 0x0 [ 12.283689] [iWare][Info] core_id: 0x0 [ 12.287891] [iWare][Info] lane_num: 0x1 [ 12.292092] [iWare][Info] target_speed: 0x1 [ 12.296294] [iWare][Info] max_lanes: 0x1 [ 12.300495] [iWare][Info] max_speed: 0x3 [ 12.304697] [iWare][Info] is_probe: 0x1 [ 12.308898] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 12.424354] udrv-pcie b00000000.pcie: [iWare][Info] msi#0 address_hi 0x0 address_lo 0x700000 [ 12.432847] udrv-pcie b00000000.pcie: [iWare][Info] msi#1 address_hi 0x0 address_lo 0x700000 [ 12.441324] udrv-pcie b00000000.pcie: [iWare][Info] msi#2 address_hi 0x0 address_lo 0x700000 [ 12.449801] udrv-pcie b00000000.pcie: [iWare][Info] msi#3 address_hi 0x0 address_lo 0x700000 [ 12.458278] udrv-pcie b00000000.pcie: [iWare][Info] msi#4 address_hi 0x0 address_lo 0x700000 [ 12.466755] udrv-pcie b00000000.pcie: [iWare][Info] msi#5 address_hi 0x0 address_lo 0x700000 [ 12.475232] udrv-pcie b00000000.pcie: [iWare][Info] msi#6 address_hi 0x0 address_lo 0x700000 [ 12.483708] udrv-pcie b00000000.pcie: [iWare][Info] msi#7 address_hi 0x0 address_lo 0x700000 [ 12.492185] udrv-pcie b00000000.pcie: [iWare][Info] msi#8 address_hi 0x0 address_lo 0x700000 [ 12.500662] udrv-pcie b00000000.pcie: [iWare][Info] msi#9 address_hi 0x0 address_lo 0x700000 [ 12.509139] udrv-pcie b00000000.pcie: [iWare][Info] msi#10 address_hi 0x0 address_lo 0x700000 [ 12.517703] udrv-pcie b00000000.pcie: [iWare][Info] msi#11 address_hi 0x0 address_lo 0x700000 [ 12.526267] udrv-pcie b00000000.pcie: [iWare][Info] msi#12 address_hi 0x0 address_lo 0x700000 [ 12.534830] udrv-pcie b00000000.pcie: [iWare][Info] msi#13 address_hi 0x0 address_lo 0x700000 [ 12.543394] udrv-pcie b00000000.pcie: [iWare][Info] msi#14 address_hi 0x0 address_lo 0x700000 [ 12.551958] udrv-pcie b00000000.pcie: [iWare][Info] msi#15 address_hi 0x0 address_lo 0x700000 [ 12.560521] udrv-pcie b00000000.pcie: [iWare][Info] msi#16 address_hi 0x0 address_lo 0x700000 [ 12.569085] udrv-pcie b00000000.pcie: [iWare][Info] msi#17 address_hi 0x0 address_lo 0x700000 [ 12.577648] udrv-pcie b00000000.pcie: [iWare][Info] msi#18 address_hi 0x0 address_lo 0x700000 [ 12.586212] udrv-pcie b00000000.pcie: [iWare][Info] msi#19 address_hi 0x0 address_lo 0x700000 [ 12.594775] udrv-pcie b00000000.pcie: [iWare][Info] msi#20 address_hi 0x0 address_lo 0x700000 [ 12.603349] udrv-pcie b00000000.pcie: [iWare][Info] msi#21 address_hi 0x0 address_lo 0x700000 [ 12.611914] udrv-pcie b00000000.pcie: [iWare][Info] msi#22 address_hi 0x0 address_lo 0x700000 [ 12.620478] udrv-pcie b00000000.pcie: [iWare][Info] msi#23 address_hi 0x0 address_lo 0x700000 [ 12.629042] udrv-pcie b00000000.pcie: [iWare][Info] msi#24 address_hi 0x0 address_lo 0x700000 [ 12.637606] udrv-pcie b00000000.pcie: [iWare][Info] msi#25 address_hi 0x0 address_lo 0x700000 [ 12.646170] udrv-pcie b00000000.pcie: [iWare][Info] msi#26 address_hi 0x0 address_lo 0x700000 [ 12.654734] udrv-pcie b00000000.pcie: [iWare][Info] msi#27 address_hi 0x0 address_lo 0x700000 [ 12.663297] udrv-pcie b00000000.pcie: [iWare][Info] msi#28 address_hi 0x0 address_lo 0x700000 [ 12.671860] udrv-pcie b00000000.pcie: [iWare][Info] msi#29 address_hi 0x0 address_lo 0x700000 [ 12.680423] udrv-pcie b00000000.pcie: [iWare][Info] msi#30 address_hi 0x0 address_lo 0x700000 [ 12.688987] udrv-pcie b00000000.pcie: [iWare][Info] msi#31 address_hi 0x0 address_lo 0x700000 [ 12.698007] udrv-pcie b00000000.pcie: [iWare][Info] msi#0 address_hi 0x0 address_lo 0x700000 [ 12.732152] udrv-pcie b20000000.pcie: [iWare] no declare type support, default rp mode [ 12.755170] [iWare][Info] host_id: 0x1 [ 12.759376] [iWare][Info] host_support_type_mask: 0x2 [ 12.764450] [iWare][Info] core_version: 0x0 [ 12.768651] [iWare][Info] msi_irq: 0x46 [ 12.772941] [iWare][Info] clk_num: 0x2 [ 12.777142] [iWare][Info] rst_num: 0x1 [ 12.781345] [iWare][Info] port_id: 0x0 [ 12.785546] [iWare][Info] port_type: 0x1 [ 12.789749] [iWare][Info] lport_id: 0x1 [ 12.793951] [iWare][Info] idr: 0x1 [ 12.798153] [iWare][Info] core_id: 0x0 [ 12.802355] [iWare][Info] lane_num: 0x1 [ 12.806558] [iWare][Info] target_speed: 0x1 [ 12.810759] [iWare][Info] max_lanes: 0x1 [ 12.814962] [iWare][Info] max_speed: 0x3 [ 12.819163] [iWare][Info] is_probe: 0x0 [ 12.823366] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 12.861135] udrv-pcie b40000000.pcie: [iWare] no declare type support, default rp mode [ 12.884117] [iWare][Info] host_id: 0x2 [ 12.888323] [iWare][Info] host_support_type_mask: 0x2 [ 12.893399] [iWare][Info] core_version: 0x0 [ 12.897601] [iWare][Info] msi_irq: 0x47 [ 12.901891] [iWare][Info] clk_num: 0x2 [ 12.906092] [iWare][Info] rst_num: 0x1 [ 12.910295] [iWare][Info] port_id: 0x0 [ 12.914496] [iWare][Info] port_type: 0x1 [ 12.918699] [iWare][Info] lport_id: 0x2 [ 12.922901] [iWare][Info] idr: 0x2 [ 12.927103] [iWare][Info] core_id: 0x0 [ 12.931305] [iWare][Info] lane_num: 0x1 [ 12.935507] [iWare][Info] target_speed: 0x1 [ 12.939708] [iWare][Info] max_lanes: 0x1 [ 12.943911] [iWare][Info] max_speed: 0x3 [ 12.948114] [iWare][Info] is_probe: 0x0 [ 12.952317] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 12.990050] udrv-pcie b60000000.pcie: [iWare] no declare type support, default rp mode [ 13.013032] [iWare][Info] host_id: 0x3 [ 13.017238] [iWare][Info] host_support_type_mask: 0x2 [ 13.022313] [iWare][Info] core_version: 0x0 [ 13.026515] [iWare][Info] msi_irq: 0x48 [ 13.030804] [iWare][Info] clk_num: 0x2 [ 13.035006] [iWare][Info] rst_num: 0x1 [ 13.039209] [iWare][Info] port_id: 0x0 [ 13.043410] [iWare][Info] port_type: 0x1 [ 13.047611] [iWare][Info] lport_id: 0x3 [ 13.051813] [iWare][Info] idr: 0x3 [ 13.056015] [iWare][Info] core_id: 0x0 [ 13.060217] [iWare][Info] lane_num: 0x1 [ 13.064420] [iWare][Info] target_speed: 0x1 [ 13.068622] [iWare][Info] max_lanes: 0x1 [ 13.072825] [iWare][Info] max_speed: 0x3 [ 13.077027] [iWare][Info] is_probe: 0x0 [ 13.081230] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 13.118957] udrv-pcie b80000000.pcie: [iWare] no declare type support, default rp mode [ 13.141928] [iWare][Info] host_id: 0x4 [ 13.146133] [iWare][Info] host_support_type_mask: 0x2 [ 13.151208] [iWare][Info] core_version: 0x0 [ 13.155410] [iWare][Info] msi_irq: 0x49 [ 13.159700] [iWare][Info] clk_num: 0x2 [ 13.163903] [iWare][Info] rst_num: 0x1 [ 13.168105] [iWare][Info] port_id: 0x0 [ 13.172308] [iWare][Info] port_type: 0x1 [ 13.176511] [iWare][Info] lport_id: 0x4 [ 13.180713] [iWare][Info] idr: 0x4 [ 13.184915] [iWare][Info] core_id: 0x0 [ 13.189118] [iWare][Info] lane_num: 0x2 [ 13.193320] [iWare][Info] target_speed: 0x1 [ 13.197522] [iWare][Info] max_lanes: 0x1 [ 13.201724] [iWare][Info] max_speed: 0x3 [ 13.205927] [iWare][Info] is_probe: 0x0 [ 13.210130] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 13.247854] udrv-pcie ba0000000.pcie: [iWare] no declare type support, default rp mode [ 13.270833] [iWare][Info] host_id: 0x5 [ 13.275037] [iWare][Info] host_support_type_mask: 0x2 [ 13.280112] [iWare][Info] core_version: 0x0 [ 13.284315] [iWare][Info] msi_irq: 0x4a [ 13.288605] [iWare][Info] clk_num: 0x2 [ 13.292807] [iWare][Info] rst_num: 0x1 [ 13.297010] [iWare][Info] port_id: 0x0 [ 13.301213] [iWare][Info] port_type: 0x1 [ 13.305415] [iWare][Info] lport_id: 0x5 [ 13.309617] [iWare][Info] idr: 0x5 [ 13.313820] [iWare][Info] core_id: 0x0 [ 13.318021] [iWare][Info] lane_num: 0x2 [ 13.322224] [iWare][Info] target_speed: 0x3 [ 13.326426] [iWare][Info] max_lanes: 0x2 [ 13.330629] [iWare][Info] max_speed: 0x3 [ 13.334832] [iWare][Info] is_probe: 0x1 [ 13.339034] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 13.454261] udrv-pcie ba0000000.pcie: [iWare][Info] msi#0 address_hi 0x0 address_lo 0x700000 [ 13.462754] udrv-pcie ba0000000.pcie: [iWare][Info] msi#1 address_hi 0x0 address_lo 0x700000 [ 13.471233] udrv-pcie ba0000000.pcie: [iWare][Info] msi#2 address_hi 0x0 address_lo 0x700000 [ 13.479711] udrv-pcie ba0000000.pcie: [iWare][Info] msi#3 address_hi 0x0 address_lo 0x700000 [ 13.488189] udrv-pcie ba0000000.pcie: [iWare][Info] msi#4 address_hi 0x0 address_lo 0x700000 [ 13.496666] udrv-pcie ba0000000.pcie: [iWare][Info] msi#5 address_hi 0x0 address_lo 0x700000 [ 13.505144] udrv-pcie ba0000000.pcie: [iWare][Info] msi#6 address_hi 0x0 address_lo 0x700000 [ 13.513622] udrv-pcie ba0000000.pcie: [iWare][Info] msi#7 address_hi 0x0 address_lo 0x700000 [ 13.522099] udrv-pcie ba0000000.pcie: [iWare][Info] msi#8 address_hi 0x0 address_lo 0x700000 [ 13.530577] udrv-pcie ba0000000.pcie: [iWare][Info] msi#9 address_hi 0x0 address_lo 0x700000 [ 13.539054] udrv-pcie ba0000000.pcie: [iWare][Info] msi#10 address_hi 0x0 address_lo 0x700000 [ 13.547619] udrv-pcie ba0000000.pcie: [iWare][Info] msi#11 address_hi 0x0 address_lo 0x700000 [ 13.556183] udrv-pcie ba0000000.pcie: [iWare][Info] msi#12 address_hi 0x0 address_lo 0x700000 [ 13.564748] udrv-pcie ba0000000.pcie: [iWare][Info] msi#13 address_hi 0x0 address_lo 0x700000 [ 13.573312] udrv-pcie ba0000000.pcie: [iWare][Info] msi#14 address_hi 0x0 address_lo 0x700000 [ 13.581877] udrv-pcie ba0000000.pcie: [iWare][Info] msi#15 address_hi 0x0 address_lo 0x700000 [ 13.590446] udrv-pcie ba0000000.pcie: [iWare][Info] msi#16 address_hi 0x0 address_lo 0x700000 [ 13.599010] udrv-pcie ba0000000.pcie: [iWare][Info] msi#17 address_hi 0x0 address_lo 0x700000 [ 13.607575] udrv-pcie ba0000000.pcie: [iWare][Info] msi#18 address_hi 0x0 address_lo 0x700000 [ 13.616139] udrv-pcie ba0000000.pcie: [iWare][Info] msi#19 address_hi 0x0 address_lo 0x700000 [ 13.624703] udrv-pcie ba0000000.pcie: [iWare][Info] msi#20 address_hi 0x0 address_lo 0x700000 [ 13.633268] udrv-pcie ba0000000.pcie: [iWare][Info] msi#21 address_hi 0x0 address_lo 0x700000 [ 13.641832] udrv-pcie ba0000000.pcie: [iWare][Info] msi#22 address_hi 0x0 address_lo 0x700000 [ 13.650397] udrv-pcie ba0000000.pcie: [iWare][Info] msi#23 address_hi 0x0 address_lo 0x700000 [ 13.658961] udrv-pcie ba0000000.pcie: [iWare][Info] msi#24 address_hi 0x0 address_lo 0x700000 [ 13.667525] udrv-pcie ba0000000.pcie: [iWare][Info] msi#25 address_hi 0x0 address_lo 0x700000 [ 13.676090] udrv-pcie ba0000000.pcie: [iWare][Info] msi#26 address_hi 0x0 address_lo 0x700000 [ 13.684654] udrv-pcie ba0000000.pcie: [iWare][Info] msi#27 address_hi 0x0 address_lo 0x700000 [ 13.693219] udrv-pcie ba0000000.pcie: [iWare][Info] msi#28 address_hi 0x0 address_lo 0x700000 [ 13.701783] udrv-pcie ba0000000.pcie: [iWare][Info] msi#29 address_hi 0x0 address_lo 0x700000 [ 13.710348] udrv-pcie ba0000000.pcie: [iWare][Info] msi#30 address_hi 0x0 address_lo 0x700000 [ 13.718913] udrv-pcie ba0000000.pcie: [iWare][Info] msi#31 address_hi 0x0 address_lo 0x700000 [ 13.727925] udrv-pcie ba0000000.pcie: [iWare][Info] msi#0 address_hi 0x0 address_lo 0x700000 [ 13.762078] udrv-pcie bc0000000.pcie: [iWare] no declare type support, default rp mode [ 13.785069] [iWare][Info] host_id: 0x6 [ 13.789272] [iWare][Info] host_support_type_mask: 0x2 [ 13.794348] [iWare][Info] core_version: 0x0 [ 13.798549] [iWare][Info] msi_irq: 0x4b [ 13.802839] [iWare][Info] clk_num: 0x2 [ 13.807040] [iWare][Info] rst_num: 0x1 [ 13.811242] [iWare][Info] port_id: 0x0 [ 13.815443] [iWare][Info] port_type: 0x1 [ 13.819644] [iWare][Info] lport_id: 0x6 [ 13.823845] [iWare][Info] idr: 0x6 [ 13.828047] [iWare][Info] core_id: 0x0 [ 13.832248] [iWare][Info] lane_num: 0x1 [ 13.836450] [iWare][Info] target_speed: 0x1 [ 13.840651] [iWare][Info] max_lanes: 0x1 [ 13.844852] [iWare][Info] max_speed: 0x3 [ 13.849053] [iWare][Info] is_probe: 0x0 [ 13.853256] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 13.891008] udrv-pcie be0000000.pcie: [iWare] no declare type support, default rp mode [ 13.913979] [iWare][Info] host_id: 0x7 [ 13.918183] [iWare][Info] host_support_type_mask: 0x2 [ 13.923257] [iWare][Info] core_version: 0x0 [ 13.927458] [iWare][Info] msi_irq: 0x4c [ 13.931747] [iWare][Info] clk_num: 0x2 [ 13.935948] [iWare][Info] rst_num: 0x1 [ 13.940149] [iWare][Info] port_id: 0x0 [ 13.944350] [iWare][Info] port_type: 0x1 [ 13.948551] [iWare][Info] lport_id: 0x7 [ 13.952753] [iWare][Info] idr: 0x7 [ 13.956955] [iWare][Info] core_id: 0x0 [ 13.961156] [iWare][Info] lane_num: 0x1 [ 13.965357] [iWare][Info] target_speed: 0x1 [ 13.969558] [iWare][Info] max_lanes: 0x1 [ 13.973758] [iWare][Info] max_speed: 0x3 [ 13.977961] [iWare][Info] is_probe: 0x0 [ 13.982163] [iWare][Info] size = 0x1f800000 atu_mode = 0x0 [ 14.022852] sata_hisi d8500000.sata_dfx: [iWare][Info] get rst and clk from dts [ 14.030355] [iWare][Info]set tx_bitorder 0 , rx_bitorder 1 [ 14.038323] [iWare][Info] udrv log init ok [ 14.093780] usb_hisi usb_hisi_0: [iWare] no misc base [ 14.099241] usb_hisi usb_hisi_1: [iWare] no misc base [ 371.687427] [iWare][Error] pmbus_write timeout! raw_int_status:0x10 [ 371.694731] [iWare][Info] pmbus hang recovery done [ 2064.422683] [iWare][Error] pmbus_write timeout! raw_int_status:0x10 [ 2064.429992] [iWare][Info] pmbus hang recovery done [ 2069.219986] [iWare][Error] wait read_finish timeout!! read_len[2] fifo num[0], raw_int_status:0x10 [ 2069.229992] [iWare][Info] pmbus hang recovery done [ 2069.234807] [iWare][Error] pmbus_read_bytes_v200 slave_addr(0x70), cmd(0x8b), time out [ 2069.243769] [iWare][Info] pmbus hang recovery done [ 2085.989229] [iWare][Error] pmbus_write timeout! raw_int_status:0x10 [ 2085.996530] [iWare][Info] pmbus hang recovery done 监控总线状态显示以上log,请继续分析
最新发布
08-07
/********************************************************************* * * Software License Agreement (BSD License) * * Copyright (c) 2024, HRSTEK, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of HRSTEK, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Authors: HRSTEK *********************************************************************/ #include <iostream> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <pthread.h> #include <ctime> #include <cstdlib> #include "unistd.h" #include <cstdio> #include <iostream> #include <string> #include <map> #include <cmath> #include <signal.h> #include <ctime> extern "C" { #include "../inc/ControlCAN.h" } #include "../inc/hrstek_usbcan.h" #include "../inc/hrstek_control.h" #include "../inc/public_variable.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include "hrstek_control.h" using namespace std; bool Cmd_vel_Receiving_flag = false; bool Cmd_vel_Receiving_flag_timeout = false; bool receive_can_Signal_flag = false; bool receive_can_Signal_flag_timeout = false; bool init_motor_flag = false; Motor_Ctrl Motor_L_Ctrl, Motor_R_Ctrl; uint8_t COMPUTER_TYPE_ALL = 0; std::map<std::string, double> chassisConfig = { {"wheel_track", 0.526}, {"max_linear_velocity", 1.32946}}; // """ // 底盘配置 // :return: 底盘配置, 字典类型, 包含以下键值对: // - "wheel_radius": 轮子半径, 单位m // - "wheel_track": 轮距, 单位m // - "reduce_ratio": 减速比 // - "bevel_gear_ratio": 锥齿轮比 // - "max_linear_velocity": 最大线速度, 单位m/s // - "max_angular_velocity": 最大角速度, 单位rad/s // - "encoder_resolution": 编码器分辨率 // - ... 其他配置信息 // "" //------------------------------------------------------------------ // 控制前翻转臂和后翻转臂的动作状态 bool front_flipper_up = false; bool front_flipper_down = false; bool rear_flipper_up = false; bool rear_flipper_down = false; double maxRpm = 8000; double wheelRadius = 0.1175; double reduceRatio = 42.31; double bevelGearRatio = 16.0 / 28.0; double wheelTrack = 0.526; uint8_t LR_Max_velo = 100; // 左右电机最大速度 int MaxSpeedValue = 256; // 0xff 反向速度参数最大值 int MaxMotorV = 500; // 速度比 电机最大速度脉冲数/电机最大速度转速数 转速比例系数33.33:1 int NodeID_R = 0x602; int NodeID_L = 0x601; int NodeID_F = 0x67B; uint8_t Left_enable[3] = {0x01, 0x02}; // 左轮激活 uint8_t Right_enable[3] = {0x01, 0x01}; // 右轮激活 uint8_t Query_speed[8] = {0x40, 0x6C, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; // 速度查询命令 velocity actual value uint8_t Query_error_code[8] = {0x40, 0x3f, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; // 故障码查询命令 error code uint8_t Query_Position[8] = {0x40, 0x64, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; // 位置查询命令 position actual value uint8_t Query_current[8] = {0x40, 0x78, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; // 电流查询命令 current actual value uint8_t Bus_enable[3] = {0x00, 0x01, 0x00}; // 总线激活 uint8_t Velocity_mode[8] = {0x2f, 0x60, 0x60, 0x00, 0x03, 0x00, 0x00, 0x00}; // 设置工作模式 速度环模式 uint8_t Control_disenable[8] = {0x2b, 0x40, 0x60, 0x00, 0x06, 0x00, 0x00, 0x00}; // 控制字去使能 uint8_t Control_1ock_enable[8] = {0x2b, 0x40, 0x60, 0x00, 0x07, 0x00, 0x00, 0x00}; // 控制字锁住 uint8_t Control_enable[8] = {0x2b, 0x40, 0x60, 0x00, 0x0f, 0x00, 0x00, 0x00}; // 控制字加上使能 uint8_t Speed_increase[8] = {0x23, 0x83, 0x60, 0x00, 0xE8, 0x03, 0x00, 0x00}; // 电机加速度值 uint8_t Speed_decrease[8] = {0x23, 0x84, 0x60, 0x00, 0xE8, 0x03, 0x00, 0x00}; // 电机减速度值 uint8_t Query_voltage[8] = {0x40, 0x79, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00}; // 电压查询命令 dc link circuit voltage uint8_t mcu_state[1] = {0x05}; void hrstek_control::init(uint8_t COMPUTER_TYPE, unsigned int USB_CAN_TYPE, unsigned int USB_CAN_BAUD_RATE, unsigned int CHASSIS_TYPE) { //COMPUTER_TYPE_ALL = COMPUTER_TYPE; Select_chassis_type(CHASSIS_TYPE); //Motor_Init(); startSendThread(); std::cout << "111111111111111111111111111111111111--------------------------------------------"<< std::endl; // startReceiveThread(); // startArmFeedbackThread(); // startFaultReceiveThread(); std::cout << "ceshiceshiceshiceshiceshiceshi--------------------------------------------"<< std::endl; //hrstek_usbcan_main = new hrstek_usbcan(); //hrstek_usbcan_main->can_init(USB_CAN_TYPE, USB_CAN_BAUD_RATE); //motordrive_init(); //startSendThread(); monitor_start_Thread(); } void hrstek_control::startFaultReceiveThread() { int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("Socket creation failed"); return; } int optval = 1; if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) { perror("setsockopt SO_REUSEADDR failed"); close(sockfd); return; } if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0) { perror("setsockopt SO_REUSEPORT failed"); close(sockfd); return; } struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(4000); // 端口号 server_addr.sin_addr.s_addr = inet_addr("192.168.1.50"); // 绑定到指定IP地址 if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Bind failed"); close(sockfd); return; } std::cout << "Fault Receiver started on IP 192.168.1.50, port 4000" << std::endl; pthread_t receive_thread; if (pthread_create(&receive_thread, NULL, receiveFaultDataThread, (void *)(intptr_t)sockfd) != 0) { perror("Thread creation failed"); close(sockfd); } else { pthread_detach(receive_thread); // 确保线程分离 } } void *hrstek_control::receiveFaultDataThread(void *arg) { int sockfd = (intptr_t)arg; struct sockaddr_in client_addr; socklen_t addr_len = sizeof(client_addr); const int buffer_size = 1024; uint8_t buffer[buffer_size]; stFaultPacket fault_data; while (true) { int bytes_received = recvfrom(sockfd, buffer, buffer_size, 0, (struct sockaddr *)&client_addr, &addr_len); if (bytes_received < 0) { perror("recvfrom failed"); continue; } // 解析数据 if (buffer[0] == 0xAA) { // 假设Header为0xAA memcpy(&fault_data, buffer, sizeof(fault_data)); printFaultData(fault_data, client_addr); } } return NULL; } void hrstek_control::printFaultData(const stFaultPacket &data, const struct sockaddr_in &client_addr) { std::cout << "Received Fault Data from " << inet_ntoa(client_addr.sin_addr) << ":" << ntohs(client_addr.sin_port) << std::endl; std::cout << "Header: " << (int)data.Header << std::endl; std::cout << "Error Count: " << (int)data.ErrorCount << std::endl; std::cout << "Index: " << (int)data.Index << std::endl; std::cout << "Error Code: " << data.ErrorCode << std::endl; std::cout << "Verify: " << (int)data.Verify << std::endl; std::cout << "-------------------------------------------------------------------------------------" << std::endl; } //-------------------------------------------------------------------------------------------------- void hrstek_control::startArmFeedbackThread() { int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("Socket creation failed"); return; } struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(10001); // 数据接收端口 server_addr.sin_addr.s_addr = inet_addr("192.168.1.50"); // 绑定到指定IP地址 if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Bind failed"); close(sockfd); return; } std::cout << "Arm Feedback Receiver started on IP 192.168.1.50, port 10001" << std::endl; pthread_t receive_thread; if (pthread_create(&receive_thread, NULL, receiveArmFeedbackThread, (void *)(intptr_t)sockfd) != 0) { perror("Thread creation failed"); close(sockfd); } } void *hrstek_control::receiveArmFeedbackThread(void *arg) { int sockfd = (intptr_t)arg; struct sockaddr_in client_addr; socklen_t addr_len = sizeof(client_addr); const int buffer_size = 2048; uint8_t buffer[buffer_size]; stUDPFBPacket_Pos packet_data; while (true) { int bytes_received = recvfrom(sockfd, buffer, buffer_size, 0, (struct sockaddr *)&client_addr, &addr_len); if (bytes_received < 0) { perror("recvfrom failed"); continue; } // 解析数据 // if (buffer[0] == 0xAA) { // 假设Header为0xAA // memcpy(&packet_data, buffer, sizeof(packet_data)); // printArmFeedbackData(packet_data, client_addr, addr_len); // 传递 client_addr 和 addr_len // } // 假设Header为0xAA memcpy(&packet_data, buffer, sizeof(packet_data)); std::cout << "dddddddddddddddddddddddddddddddddddddddddddddddddddddd--------------------------------------------"<< std::endl; printArmFeedbackData(packet_data, client_addr, addr_len); // 传递 client_addr 和 addr_len } return NULL; } void hrstek_control::printArmFeedbackData(const stUDPFBPacket_Pos &data, const struct sockaddr_in &client_addr, socklen_t addr_len) { std::cout << "Received Arm Feedback Data from " << inet_ntoa(client_addr.sin_addr) << ":" << ntohs(client_addr.sin_port) << std::endl; std::cout << "Header: " << (int)data.Header << std::endl; std::cout << "Packet Length: " << (int)data.PacketLength << std::endl; std::cout << "Vehicle Voltage: " << (int)data.VehicleVoltage << std::endl; std::cout << "Joint1 Status: " << data.Joint1Status << std::endl; std::cout << "Joint2 Status: " << data.Joint2Status << std::endl; std::cout << "Joint3 Status: " << data.Joint3Status << std::endl; std::cout << "Joint4 Status: " << data.Joint4Status << std::endl; std::cout << "Joint5 Status: " << data.Joint5Status << std::endl; std::cout << "Joint6 Status: " << data.Joint6Status << std::endl; std::cout << "AuxVFW Status: " << data.AuxVFWStatus << std::endl; std::cout << "AuxVBK Status: " << data.AuxVBKStatus << std::endl; std::cout << "SP Work Complete: " << (int)data.SPWorkComplete << std::endl; std::cout << "Joint1 Pos: " << data.Joint1Pos << std::endl; std::cout << "Joint2 Pos: " << data.Joint2Pos << std::endl; std::cout << "Joint3 Pos: " << data.Joint3Pos << std::endl; std::cout << "Joint4 Pos: " << data.Joint4Pos << std::endl; std::cout << "Joint5 Pos: " << data.Joint5Pos << std::endl; std::cout << "Joint6 Pos: " << data.Joint6Pos << std::endl; std::cout << "FW AuxV Pos: " << data.FWAuxVPos << std::endl; std::cout << "BK AuxV Pos: " << data.BKAuxVPos << std::endl; std::cout << "Error Code: " << data.ErrorCode << std::endl; std::cout << "Actual Torque: " << data.ActualTorque << std::endl; std::cout << "Mile Distance: " << data.MileDistance << std::endl; std::cout << "Run Time: " << data.RunTime << std::endl; std::cout << "CRC8: " << (int)data.CRC8 << std::endl; std::cout << "-------------------------------------------------------------------------------------" << std::endl; } //----------------------------------------------------------------------------------------------------- void hrstek_control::startReceiveThread() { int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("Socket creation failed"); return; } std::cout << "ceshiceshiceshiceshiceshiceshi--------------------------------------------"<< std::endl; struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(5020); // 底盘数据端口 // server_addr.sin_addr.s_addr = INADDR_ANY; // 绑定到所有可用的网络接口 server_addr.sin_addr.s_addr = inet_addr("192.168.1.50"); // 绑定套接字 if (bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Bind failed"); close(sockfd); return; } socklen_t addr_len = sizeof(server_addr); pthread_t receive_thread; if (pthread_create(&receive_thread, NULL, receiveChassisDataThread, (void *)(intptr_t)sockfd) != 0) { perror("Thread creation failed"); close(sockfd); } } void *hrstek_control::receiveChassisDataThread(void *arg) { int sockfd = (intptr_t)arg; struct sockaddr_in server_addr; socklen_t addr_len = sizeof(server_addr); receiveChassisData(sockfd, server_addr, addr_len); return NULL; } // CRC8 校验函数 uint8_t calculateCRC8(const uint8_t *data, size_t length) { uint8_t crc = 0; for (size_t i = 0; i < length; ++i) { crc ^= data[i]; } return crc; } // // 字节序转换函数 // void swapBytesIfNeeded(ChassisData &data) { // data.ultrasonic1 = ntohs(data.ultrasonic1); // data.ultrasonic2 = ntohs(data.ultrasonic2); // data.ultrasonic3 = ntohs(data.ultrasonic3); // data.ultrasonic4 = ntohs(data.ultrasonic4); // uint32_t *floatFields[] = {reinterpret_cast<uint32_t *>(&data.gps_latitude), // reinterpret_cast<uint32_t *>(&data.gps_longitude), // reinterpret_cast<uint32_t *>(&data.gps_altitude), // reinterpret_cast<uint32_t *>(&data.imu_accel_x), // reinterpret_cast<uint32_t *>(&data.imu_accel_y), // reinterpret_cast<uint32_t *>(&data.imu_accel_z), // reinterpret_cast<uint32_t *>(&data.imu_velocity_x), // reinterpret_cast<uint32_t *>(&data.imu_velocity_y), // reinterpret_cast<uint32_t *>(&data.imu_velocity_z), // reinterpret_cast<uint32_t *>(&data.imu_angle_x), // reinterpret_cast<uint32_t *>(&data.imu_angle_y), // reinterpret_cast<uint32_t *>(&data.imu_angle_z), // reinterpret_cast<uint32_t *>(&data.left_motor_speed_abs), // reinterpret_cast<uint32_t *>(&data.right_motor_speed_abs), // reinterpret_cast<uint32_t *>(&data.cabin_temperature), // reinterpret_cast<uint32_t *>(&data.vehicle_voltage), // reinterpret_cast<uint32_t *>(&data.vehicle_battery_percentage)}; // for (auto &field : floatFields) { // *field = ntohl(*field); // } // } void swapBytesIfNeeded(ChassisData &data) { // 转换 16 位字段 data.ultrasonic1 = ntohs(data.ultrasonic1); data.ultrasonic2 = ntohs(data.ultrasonic2); data.ultrasonic3 = ntohs(data.ultrasonic3); data.ultrasonic4 = ntohs(data.ultrasonic4); // 转换 32 位字段 data.gps_latitude = ntohl(*reinterpret_cast<uint32_t *>(&data.gps_latitude)); data.gps_longitude = ntohl(*reinterpret_cast<uint32_t *>(&data.gps_longitude)); data.gps_altitude = ntohl(*reinterpret_cast<uint32_t *>(&data.gps_altitude)); data.imu_accel_x = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_accel_x)); data.imu_accel_y = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_accel_y)); data.imu_accel_z = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_accel_z)); data.imu_velocity_x = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_velocity_x)); data.imu_velocity_y = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_velocity_y)); data.imu_velocity_z = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_velocity_z)); data.imu_angle_x = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_angle_x)); data.imu_angle_y = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_angle_y)); data.imu_angle_z = ntohl(*reinterpret_cast<uint32_t *>(&data.imu_angle_z)); data.left_motor_speed_abs = ntohl(*reinterpret_cast<uint32_t *>(&data.left_motor_speed_abs)); data.right_motor_speed_abs = ntohl(*reinterpret_cast<uint32_t *>(&data.right_motor_speed_abs)); data.cabin_temperature = ntohl(*reinterpret_cast<uint32_t *>(&data.cabin_temperature)); data.vehicle_voltage = ntohl(*reinterpret_cast<uint32_t *>(&data.vehicle_voltage)); data.vehicle_battery_percentage = ntohl(*reinterpret_cast<uint32_t *>(&data.vehicle_battery_percentage)); } // 接收底盘数据的线程函数 void hrstek_control::receiveChassisData(int sockfd, struct sockaddr_in &server_addr, socklen_t &addr_len) { const int buffer_size = 1024; uint8_t buffer[buffer_size]; struct ChassisData chassis_data; while (true) { int bytes_received = recvfrom(sockfd, buffer, buffer_size, 0, (struct sockaddr *)&server_addr, &addr_len); if (bytes_received < 0) { perror("recvfrom failed"); continue; } printf("Cabin Temperature: %f\n",chassis_data.cabin_temperature); printf("-------------------------------------------------------------------------------------\n"); // 检查数据包头部 if (buffer[0] == 0xAA && buffer[1] == 0x80) { memcpy(&chassis_data, buffer, sizeof(chassis_data)); // 转换字节序 swapBytesIfNeeded(chassis_data); // // 校验数据完整性 // uint8_t receivedCRC = calculateCRC8(buffer, sizeof(ChassisData) - 1); // if (receivedCRC != chassis_data.crc8) { // std::cerr << "CRC mismatch, data may be corrupted" << std::endl; // continue; // } // 打印数据 std::cout << "Received chassis data from " << inet_ntoa(server_addr.sin_addr) << ":" << ntohs(server_addr.sin_port) << std::endl; std::cout << "Header: " << (int)chassis_data.header << std::endl; std::cout << "Flag: " << (int)chassis_data.flag << std::endl; std::cout << "Ultrasonic 1: " << chassis_data.ultrasonic1 << std::endl; std::cout << "Ultrasonic 2: " << chassis_data.ultrasonic2 << std::endl; std::cout << "Ultrasonic 3: " << chassis_data.ultrasonic3 << std::endl; std::cout << "Ultrasonic 4: " << chassis_data.ultrasonic4 << std::endl; std::cout << "GPS Latitude: " << chassis_data.gps_latitude << std::endl; std::cout << "GPS Longitude: " << chassis_data.gps_longitude << std::endl; std::cout << "GPS Altitude: " << chassis_data.gps_altitude << std::endl; std::cout << "IMU Accel X: " << chassis_data.imu_accel_x << std::endl; std::cout << "IMU Accel Y: " << chassis_data.imu_accel_y << std::endl; std::cout << "IMU Accel Z: " << chassis_data.imu_accel_z << std::endl; std::cout << "IMU Velocity X: " << chassis_data.imu_velocity_x << std::endl; std::cout << "IMU Velocity Y: " << chassis_data.imu_velocity_y << std::endl; std::cout << "IMU Velocity Z: " << chassis_data.imu_velocity_z << std::endl; std::cout << "IMU Angle X: " << chassis_data.imu_angle_x << std::endl; std::cout << "IMU Angle Y: " << chassis_data.imu_angle_y << std::endl; std::cout << "IMU Angle Z: " << chassis_data.imu_angle_z << std::endl; std::cout << "Left Motor Speed Percent: " << (int)chassis_data.left_motor_speed_percent << std::endl; std::cout << "Right Motor Speed Percent: " << (int)chassis_data.right_motor_speed_percent << std::endl; std::cout << "Left Motor Speed Abs: " << chassis_data.left_motor_speed_abs << std::endl; std::cout << "Right Motor Speed Abs: " << chassis_data.right_motor_speed_abs << std::endl; std::cout << "Left Motor Current: " << chassis_data.left_motor_current << std::endl; std::cout << "Right Motor Current: " << chassis_data.right_motor_current << std::endl; std::cout << "Left Motor Temperature: " << chassis_data.left_motor_temperature << std::endl; std::cout << "Right Motor Temperature: " << chassis_data.right_motor_temperature << std::endl; std::cout << "Left Motor Encoder Position: " << chassis_data.left_motor_encoder_position << std::endl; std::cout << "Right Motor Encoder Position: " << chassis_data.right_motor_encoder_position << std::endl; std::cout << "Cabin Temperature: " << chassis_data.cabin_temperature << std::endl; std::cout << "Vehicle Voltage: " << chassis_data.vehicle_voltage << std::endl; std::cout << "Vehicle Battery Percentage: " << chassis_data.vehicle_battery_percentage << std::endl; std::cout << "H2S Gas Concentration: " << chassis_data.h2s_gas_concentration << std::endl; std::cout << "CO Gas Concentration: " << chassis_data.co_gas_concentration << std::endl; std::cout << "O2 Gas Concentration: " << chassis_data.o2_gas_concentration << std::endl; std::cout << "LEL Gas Concentration: " << chassis_data.lel_gas_concentration << std::endl; // std::cout << "CRC8: " << (int)chassis_data.crc8 << std::endl; } } } // void hrstek_control::receiveChassisData(int sockfd, struct sockaddr_in &server_addr, socklen_t &addr_len) { // const int buffer_size = 1024; // uint8_t buffer[buffer_size]; // struct ChassisData chassis_data; // while (true) { // int bytes_received = recvfrom(sockfd, buffer, buffer_size, 0, (struct sockaddr *)&server_addr, &addr_len); // if (bytes_received < 0) { // perror("recvfrom failed"); // continue; // } // printf("Cabin Temperature: %f\n",chassis_data.cabin_temperature); // printf("-------------------------------------------------------------------------------------\n"); // // 解析数据 // if (buffer[0] == 0xAA && buffer[1] == 0x80) { // memcpy(&chassis_data, buffer, sizeof(chassis_data)); // std::cout << "Received chassis data from " << inet_ntoa(server_addr.sin_addr) << ":" << ntohs(server_addr.sin_port) << std::endl; // std::cout << "Header: " << (int)chassis_data.header << std::endl; // std::cout << "Flag: " << (int)chassis_data.flag << std::endl; // std::cout << "Ultrasonic 1: " << chassis_data.ultrasonic1 << std::endl; // std::cout << "Ultrasonic 2: " << chassis_data.ultrasonic2 << std::endl; // std::cout << "Ultrasonic 3: " << chassis_data.ultrasonic3 << std::endl; // std::cout << "Ultrasonic 4: " << chassis_data.ultrasonic4 << std::endl; // std::cout << "GPS Latitude: " << chassis_data.gps_latitude << std::endl; // std::cout << "GPS Longitude: " << chassis_data.gps_longitude << std::endl; // std::cout << "GPS Altitude: " << chassis_data.gps_altitude << std::endl; // std::cout << "IMU Accel X: " << chassis_data.imu_accel_x << std::endl; // std::cout << "IMU Accel Y: " << chassis_data.imu_accel_y << std::endl; // std::cout << "IMU Accel Z: " << chassis_data.imu_accel_z << std::endl; // std::cout << "IMU Velocity X: " << chassis_data.imu_velocity_x << std::endl; // std::cout << "IMU Velocity Y: " << chassis_data.imu_velocity_y << std::endl; // std::cout << "IMU Velocity Z: " << chassis_data.imu_velocity_z << std::endl; // std::cout << "IMU Angle X: " << chassis_data.imu_angle_x << std::endl; // std::cout << "IMU Angle Y: " << chassis_data.imu_angle_y << std::endl; // std::cout << "IMU Angle Z: " << chassis_data.imu_angle_z << std::endl; // std::cout << "Left Motor Speed Percent: " << (int)chassis_data.left_motor_speed_percent << std::endl; // std::cout << "Right Motor Speed Percent: " << (int)chassis_data.right_motor_speed_percent << std::endl; // std::cout << "Left Motor Speed Abs: " << chassis_data.left_motor_speed_abs << std::endl; // std::cout << "Right Motor Speed Abs: " << chassis_data.right_motor_speed_abs << std::endl; // std::cout << "Left Motor Current: " << chassis_data.left_motor_current << std::endl; // std::cout << "Right Motor Current: " << chassis_data.right_motor_current << std::endl; // std::cout << "Left Motor Temperature: " << chassis_data.left_motor_temperature << std::endl; // std::cout << "Right Motor Temperature: " << chassis_data.right_motor_temperature << std::endl; // std::cout << "Left Motor Encoder Position: " << chassis_data.left_motor_encoder_position << std::endl; // std::cout << "Right Motor Encoder Position: " << chassis_data.right_motor_encoder_position << std::endl; // std::cout << "Cabin Temperature: " << chassis_data.cabin_temperature << std::endl; // std::cout << "Vehicle Voltage: " << chassis_data.vehicle_voltage << std::endl; // std::cout << "Vehicle Battery Percentage: " << chassis_data.vehicle_battery_percentage << std::endl; // std::cout << "H2S Gas Concentration: " << chassis_data.h2s_gas_concentration << std::endl; // std::cout << "CO Gas Concentration: " << chassis_data.co_gas_concentration << std::endl; // std::cout << "O2 Gas Concentration: " << chassis_data.o2_gas_concentration << std::endl; // std::cout << "LEL Gas Concentration: " << chassis_data.lel_gas_concentration << std::endl; // } // } // } void hrstek_control::stop_can() { } void hrstek_control::Select_chassis_type(unsigned int CHASSIS_TYPE) { } // 根据电机的速度和方向计算控制字节 uint8_t calculateMotorControl(int speed, int direction) { if (speed == 0) { // 当速度为0时,返回 0x00 return 0; } if (direction == 1) { // Forward direction: 0x00 - 0x64 if (speed < 0) { speed = 0; } else if (speed > 100) { speed = 100; } return static_cast<uint8_t>(speed); } else { // Backward direction: 0x80 - 0xFF (from -100 to -0) int calculatedValue = 155 + (100 - speed); if (calculatedValue < 100) { calculatedValue = 100; } else if (calculatedValue > 255) { calculatedValue = 255; } return static_cast<uint8_t>(calculatedValue); } } double hrstek_control::calculate_max_linear_velocity() { // // 将RPM转换为rad/s // double omegaWheel = (maxRpm * 2 * M_PI * wheelRadius) / (60 * reduceRatio) * bevelGearRatio; // 电机的角速度,单位为rad/s // // 计算最大线速度 // double maxLinearVelocity = omegaWheel; // return maxLinearVelocity; return 1; } // 按照配置构建要发送的数据数组 uint8_t send_data[11]; // 控制反转臂 void hrstek_control::frontcontrolFlippers(bool up, bool down) { // 控制前翻转臂 if (up) { send_data[2] |= 0x40; // 设置Bit 6为1 } else { send_data[2] &= ~0x40; // 设置Bit 6为0 } if (down) { send_data[2] |= 0x80; // 设置Bit 7为1 } else { send_data[2] &= ~0x80; // 设置Bit 7为0 } } void hrstek_control::backcontrolFlippers(bool up, bool down) { // 控制后翻转臂 if (up) { send_data[7] |= 0x40; // 设置Bit 6为1 } else { send_data[7] &= ~0x40; // 设置Bit 6为0 } if (down) { send_data[7] |= 0x80; // 设置Bit 7为1 } else { send_data[7] &= ~0x80; // 设置Bit 7为0 } } bool hrstek_control::loop_control(std::map<std::string, std::map<std::string, double>> &twist) { // 需要发送的帧,结构体设置 // 获取底盘配置参数 Cmd_vel_Receiving_flag = true; double trackWidth = 0.52; double maxVelocity = 1.3; // 从Twist消息中提取线速度和角速度 double linearVelocity = twist["linear"]["x"]; // 前进速度(m/s) double angularVelocity = twist["angular"]["z"]; // 角速度(rad/s) // 计算左右轮的线速度 double vLeft = linearVelocity - (trackWidth / 2.0) * angularVelocity; double vRight = linearVelocity + (trackWidth / 2.0) * angularVelocity; // 确定左右轮速度的符号 int leftSign = vLeft >= 0 ? 1 : -1; int rightSign = vRight >= 0 ? 1 : -1; // 将速度转换为相对于最大速度的百分比并取整 int leftVelocity = static_cast<int>(std::round(std::abs(vLeft) / maxVelocity * 100)); int rightVelocity = static_cast<int>(std::round(std::abs(vRight) / maxVelocity * 100)); cout << "-------------------> \n"; cout << "linearVelocity=" << linearVelocity << " angularVelocity=" << angularVelocity << " \n"; cout << "vLeft=" << vLeft << " vRight=" << vRight << " \n"; // 使用printf输出,将各个变量以浮点数形式展示 printf("leftVelocity=%d leftSign=%d rightVelocity=%d rightSign=%d \n", leftVelocity, leftSign, rightVelocity, rightSign); cout << "<------------------- \n"; usleep(8000); send_data[4] =calculateMotorControl(leftVelocity,leftSign); send_data[5] =calculateMotorControl(rightVelocity,rightSign); if (Cmd_vel_Receiving_flag_timeout == false) { // Set_Motor_Speed(leftVelocity, rightVelocity, leftSign, rightSign); } Cmd_vel_Receiving_flag = false; return TRUE; } void hrstek_control::Set_Motor_Speed(uint8_t Left_speed, uint8_t Right_speed, int leftSign, int rightSign) { } // 计算异或校验值的函数,接收字节数组和数组长度作为参数 uint8_t calculateXORChecksum(const uint8_t* data, size_t length) { if (length == 0) { return 0; } uint8_t checksum = data[0]; for (size_t i = 1; i < length; ++i) { checksum ^= data[i]; } return checksum; } // 发送数据线程函数,每隔一段时间发送固定数据 void *hrstek_control::sendDataThread(void *arg) { hrstek_control *instance = static_cast<hrstek_control *>(arg); // 创建套接字 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { perror("Socket creation failed"); } // 设置目标地址结构体 struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(10000); server_addr.sin_addr.s_addr = inet_addr("192.168.1.110"); while (true) { // Byte 0: Header (Fixed) send_data[0] = 0xAA; // Byte 1: Mode Control (Fixed) send_data[1] = 0xF5; // Byte 2: Mode Select, Light Control, Weapon Control, Front Flipper Control // send_data[2] = 0; // Byte 3: PTZ Control, Video Channel Select send_data[3] = 0x40; // send_data[4] =calculateMotorControl(10,-1); // send_data[5] =calculateMotorControl(10,-1); // // Byte 4: Left Motor Control // send_data[4] = 0; // send_data[4] &= ~(0xFF << 0); // send_data[4] |= (50 << 0); // send_data[4] &= ~(1 << 7); // // Byte 5: Right Motor Control // send_data[5] = 0; // send_data[5] &= ~(0xFF << 0); // send_data[5] |= (60 << 0); // send_data[5] &= ~(1 << 7); // Byte 6: Joint 8, 1, 2, 3 send_data[6] = 0; // Byte 7: Joint 4, 5, PTZ Raise/Lower, Back Flipper Control // send_data[7] = 0; // Byte 8: PTZ speed (0x00-0x7F) send_data[8] = 0; // Byte 9: PTZ focus (0x00-0xFA: 0-250, 0x64:=100) send_data[9] = 0x64; // 调用函数计算异或校验值 uint8_t xor_checksum = calculateXORChecksum(send_data, 10); // std::cout << "异或校验值为: 0x" << std::hex << static_cast<int>(xor_checksum) << std::dec << std::endl; // Byte 10: CRC send_data[10] = xor_checksum; // 发送数据 if (sendto(sockfd, send_data, 11, 0, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) { perror("Sendto failed"); } // std::cout <<"------>"<< std::endl; // for (int i = 0; i < 11; ++i) { // // 使用printf以十六进制格式输出每个字节元素,%02X表示以十六进制大形式输出,宽度为2,足两位前面补0 // printf("%02X ", send_data[i]); // } // printf("\n"); // std::cout <<"<------"<< std::endl; usleep(300000); } pthread_exit(NULL); } // 启动发送数据线程函数 void hrstek_control::startSendThread() { pthread_create(&sendThread, NULL, sendDataThread, this); } void hrstek_control::CAN_trans(unsigned short stdid_can, unsigned char can_buf[], unsigned char DataLen) { } union { int a; unsigned char d[4]; } data_union; void hrstek_control::mc_Can_SdoWr(unsigned short NodeID, unsigned int ODIndex, unsigned int ODSubIndex, unsigned int ODData) { } void hrstek_control::Motor_Init(void) { } void hrstek_control::motordrive_init(void) { } void hrstek_control::monitor_start_Thread() { pthread_create(&p_monitorThread, NULL, monitorThread, this); } void *hrstek_control::monitorThread(void *arg) { hrstek_control *instance = static_cast<hrstek_control *>(arg); uint16_t Cmd_vel_Receiving_flag_cout = 0; uint16_t receive_can_Signal_flag_cout = 0; while (true) { if (Cmd_vel_Receiving_flag == false) { if ((Cmd_vel_Receiving_flag_cout < 500) && (Cmd_vel_Receiving_flag_timeout == false)) { Cmd_vel_Receiving_flag_cout++; } else if ((Cmd_vel_Receiving_flag_cout >= 500) && (Cmd_vel_Receiving_flag_timeout == false)) { cout << "-------------> \n"; // 获取当前时间 std::time_t currentTime = std::time(nullptr); // 将当前时间转换为本地时间结构体 std::tm *localTime = std::localtime(&currentTime); // 格式化输出时间,精确到毫秒 char buffer[80]; std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", localTime); std::cout << buffer << '.' << std::clock() % 1000 << std::endl; Cmd_vel_Receiving_flag_timeout = true; usleep(5000); cout << "cmd_vel超时!!!!!!!!! \n"; cout << "<------------- \n"; } } else { Cmd_vel_Receiving_flag_timeout = false; Cmd_vel_Receiving_flag_cout = 0; } usleep(1000); } pthread_exit(NULL); } int main(int argc, char **argv) { // 创建底盘控制类的实例 hrstek_control *hrstek_control_main = new hrstek_control(); // 初始化底盘控制类 // 这里需要根据实际情况提供正确的参数 uint8_t COMPUTER_TYPE = COMPUTER_TX2; // 示例参数 unsigned int USB_CAN_TYPE = LCAN_USBCAN2; // 示例参数 unsigned int USB_CAN_BAUD_RATE = USB_CAN_BAUD_RATE_250K; // 示例参数 unsigned int CHASSIS_TYPE = CHASSIS_TYPE_MINI_TANK; // 示例参数 hrstek_control_main->init(COMPUTER_TYPE, USB_CAN_TYPE, USB_CAN_BAUD_RATE, CHASSIS_TYPE); // 主循环,保持程序运行 while (true) { // 这里可以添加一些主循环中的逻辑,例如处理用户输入等 sleep(1); // 每秒检查一次 } // 清理资源 delete hrstek_control_main; return 0; } // 其他成员函数 这个文件的代码是是需要接受cmd_vel的数据?
06-25
串口OTA升级 数据格式均采用小端模式 1、选择扩展名为.hjc的升级文件 2、取文件前16字节,用来判断是否为升级文件,判断方法如下 headerList[16] 为取的文件前16字节,需要同时满足以下条件 headerList[6] == headerList[0] ^ 0x48 headerList[7] == headerList[1] ^ 0x4A headerList[8] == headerList[2] ^ 0x42 headerList[9] == headerList[3] ^ 0x4C headerList[10] == headerList[4] ^ 0x45 headerList[11] == headerList[0]^ headerList[3] 3、获取设备类型 下行 数据 {READ_OTA_TYPE} 上行 数据 {CONFIRMED-C-HJOTA} 4、切换OTA 下行 数据 {HJC + headerList数组中的最后4个字节 + } 上行 数据 {OK} 5、获取新固件存储基地址 下行 数据 010300 上行 Result Opcode Length(内容2字节) Payload 0x00 0x01 0x04 0x00 当前运行的代码在flash中存储的基地址(4字节) 为了方便下文说明,取名storage_baseaddr 6、擦除扇区,从storage_baseaddr地址开始,按照每次擦除0x1000递进擦除,直到到达够升级信息需要的长度,升级信息长度为文件长度-16,前16字节为校验字节 下行 Opcode Length(内容2字节) Base_addr 0x03 0x06 0x00 Flash中的基地址偏移(4字节,小端) 上行 Result Opcode Length(内容2字节) Payload 0x00 0x03 0x04 0x00 Flash中的基地址偏移(4字节) 7、入数据,因为hid固定521字节,所以,入的有效数据为groupSize=521-9个字节,发完前一包后,下一包,Base_addr也要加groupSize个字节 下行 Opcode Length(内容2字节) Base_addr Length(2字节) Payload 0x05 6+payload_len Flash中的基地址偏移(4字节,小端) Payload长度 要入的内容 上行 Result Opcode Length(内容2字节) Base_addr Length 0x00 0x05 0x06 0x00 入的基地址偏移(4字节) 入的长度(2字节) 8、校验并重启 下行 Opcode Length(内容) 固件大小 CRC校验 0x09 0x0a 0x00 入bin文件的大小(4字节) 入bin文件的CRC32校验(4字节) 上行 Result Opcode Length(内容 2字节) Slave端返回校验值 0x00(检验成功)/ 0x01(校验失败) 0x09 0x00 0x00 CRC32 (4个字节) 用c语言封装函数
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ChipWeaver

觉得有用的话点个赞吧 :)

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值