[关闭]
@Pigmon 2020-12-01T08:02:11.000000Z 字数 1617 阅读 673

12月1日的异常状态代码

遥控


简述

目前采用的方法是,用一个只有1位是1,其他位都是0的16位无符号整数来代表一个异常状态。车端获取到所有异常状态后将它们按位或操作后发出。
接收端可以根据整体错误代码中为1的位有哪些得知目前都有什么异常状态。

目前的错误代码定义:

bin dec hex 含义
0000 0000 0000 0010 2 0x0002 预留代表未知错误
0000 0000 0000 0100 4 0x0004 GPS 错误
0000 0000 0000 1000 8 0x0008 IMU 错误
0000 0000 0001 0000 16 0x0010 激光雷达错误
0000 0000 0010 0000 32 0x0020 预留其他错误
... ... ... ...
0100 0000 0000 0000 16384 0x4000 预留其他错误

考虑出现有符号接收的可能性,符号位保持0。

消息定义

rc_chassis.msg

  1. # Description the state of chassis
  2. Header header
  3. int8 gear # 档位,1, 2, 3..., 0表示无档位
  4. float64 speed # 秒速
  5. float64 steering # 轮偏角,弧度
  6. int16 rpm # 发动机转速
  7. uint8 bucket_pos # 斗位置 0-底,1-中间,2-顶,3-故障
  8. uint16 detect_error # 检测到故障,用于发出接管请求
  9. uint8 state
  10. uint8 Normal = 0
  11. uint8 RequiredRC = 1
  12. uint8 Emergency = 2

车端可以 source 工程 nox_comm 得到这个消息。

C++ 使用方法

错误码定义:

  1. const unsigned short ERRDET_UNKOWN_ERR = 0X0002;
  2. const unsigned short ERRDET_GPS_LOSS = 0x0004;
  3. const unsigned short ERRDET_IMU_LOSS = 0x0008;
  4. const unsigned short ERRDET_LIDAR_LOSS = 0x0010;
  5. const unsigned short ERRDET_PLACEHOLDER_0 = 0X0020;
  6. const unsigned short ERRDET_PLACEHOLDER_1 = 0X0040;
  7. const unsigned short ERRDET_PLACEHOLDER_2 = 0X0080;
  8. const unsigned short ERRDET_PLACEHOLDER_3 = 0X0100;
  9. const unsigned short ERRDET_PLACEHOLDER_4 = 0X0200;
  10. const unsigned short ERRDET_PLACEHOLDER_5 = 0X0400;
  11. const unsigned short ERRDET_PLACEHOLDER_6 = 0X0800;
  12. const unsigned short ERRDET_PLACEHOLDER_7 = 0X1000;
  13. const unsigned short ERRDET_PLACEHOLDER_8 = 0X2000;
  14. const unsigned short ERRDET_PLACEHOLDER_9 = 0X4000;

使用示例:

  1. unsigned short err_code = ERRDET_GPS_LOSS | ERRDET_LIDAR_LOSS;
  2. bool gps_err = (err_code & ERRDET_GPS_LOSS) == ERRDET_GPS_LOSS;
  3. bool imu_err = (err_code & ERRDET_IMU_LOSS) == ERRDET_IMU_LOSS;
  4. bool lidar_err = (err_code & ERRDET_LIDAR_LOSS) == ERRDET_LIDAR_LOSS;
  5. std::cout << std::boolalpha << gps_err << ", " << imu_err << ", " << lidar_err << std::endl;
  6. // prints: true, false, true
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注