env.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. /*
  2. * @file env.h
  3. *
  4. * @brief description
  5. * @details description
  6. *
  7. * @copyright (c) 2006-2021, Huali Development Team
  8. *
  9. * (c) Copyright 2021, Shandong Huali electromechanical Co., Ltd..
  10. * This is protected by international copyright laws. Knowledge of the
  11. * source code may not be used to write a similar product. This file may
  12. * only be used in accordance with a license and should not be redistributed
  13. * in any way. We appreciate your understanding and fairness.
  14. *
  15. * Change Logs:
  16. * @date @author @note
  17. * 2021-10-16 Simon the first version
  18. */
  19. #ifndef ENV_H_
  20. #define ENV_H_
  21. #include <stdint.h>
  22. #include <stdbool.h>
  23. #include "hardware.h"
  24. #include "board.h"
  25. #include "status.h"
  26. #define _VERSION "001"
  27. /* bool */
  28. #define False 0
  29. #define True 1
  30. #define MIN_S16 -32768
  31. typedef struct {
  32. volatile uint16_t AgvId;
  33. /* 状态信息 */
  34. uint16_t Status; //小车状态
  35. uint16_t BatteryVolt;
  36. /* 实时速度 */
  37. uint16_t Speed;
  38. uint16_t TaskStatus; //任务状态
  39. // uint16_t TaskCnt;
  40. uint32_t Station; //站点
  41. uint32_t TgtStation; //目标站点
  42. uint32_t Point; //地标
  43. uint16_t CargoStatus; //货物状态
  44. uint16_t NavStatus; //导航状态
  45. uint16_t FR; //
  46. uint16_t CrossType; //十字架的类型
  47. /* 目标速度 */
  48. uint16_t TgtSpeed;
  49. uint16_t LiftStatus;
  50. uint16_t QYPreStatus; //没用
  51. /* 实时操作 */
  52. uint16_t PreStatus;
  53. uint16_t PrePoint;
  54. /* 目标操作 */
  55. uint16_t TgtAction; //前后
  56. uint16_t DRAction; //
  57. uint16_t Action; //
  58. uint16_t Direction; //方向
  59. uint16_t Branch; //分支,没用到
  60. uint16_t StopAtCross; //
  61. // 板载LED灯
  62. uint16_t Light1Red;
  63. uint16_t Light1Yellow;
  64. uint16_t Light1Green;
  65. uint16_t OBSArea;
  66. /* rfid */
  67. uint16_t RfidNeedHandle;
  68. uint16_t RfidType;
  69. uint8_t RfidData2;
  70. uint8_t RfidData1;
  71. uint8_t RfidData4;
  72. uint8_t RfidData3;
  73. uint8_t RfidData6;
  74. uint8_t RfidData5;
  75. uint8_t RfidData8;
  76. uint8_t RfidData7;
  77. uint16_t Led0Status;
  78. uint16_t Light2Red;
  79. uint16_t Light2Yellow;
  80. uint16_t Light2Green;
  81. uint16_t ObsStatus; //光电开关状态
  82. uint16_t BlkNum; //用不到
  83. uint16_t BlkStat;
  84. /* 获取次数 */
  85. uint16_t BlkReqCnt;
  86. /* 速度类型 */
  87. uint16_t IdleSecond;
  88. /* 电池信息 */
  89. uint16_t Driver1Volt;
  90. uint16_t Driver2Volt;
  91. uint16_t BatteryStatus; //电池状态
  92. /* 驱动信息 */
  93. uint16_t DRStatus; //驱动器状态
  94. uint8_t FFLmtSw; //
  95. uint8_t FRLmtSw; //
  96. uint8_t BFLmtSw; //
  97. uint8_t BRLmtSw; //
  98. int FAngle;
  99. int BAngle;
  100. int FPos;
  101. int BPos;
  102. short FWlkRpm; //行走电机的转速
  103. short BWlkRpm;
  104. uint16_t FWlkZj;
  105. uint16_t BWlkZj;
  106. uint8_t FMgsOnline;
  107. uint8_t BMgsOnline;
  108. uint8_t LMgsOnline;
  109. uint8_t RMgsOnline;
  110. short FMgsOffset; //
  111. short BMgsOffset;
  112. short LMgsOffset;
  113. short RMgsOffset;
  114. uint16_t FWlkError;
  115. uint16_t BWlkError;
  116. uint16_t FStrError;
  117. uint16_t BStrError;
  118. uint16_t LogSwMain :1;
  119. uint16_t LogSwMsg :1;
  120. uint16_t LogSwCan :1;
  121. uint16_t LogSwDriver :1;
  122. uint16_t LogSwGuide :1;
  123. uint16_t LogSwRfid :1;
  124. uint16_t LogSwMns :1;
  125. uint16_t LogSwBtn :1;
  126. uint16_t LogSwRoad :1;
  127. char * TaskId;
  128. uint16_t TaskSrc;
  129. int LiftPosL;
  130. int LiftPosR;
  131. uint16_t DemoTaskStatus;
  132. uint16_t TimerChargeStatus;
  133. uint16_t HH; //时
  134. uint16_t MM; //分
  135. uint16_t SS;
  136. uint8_t DmS;
  137. short xValue; //x的实际值
  138. short yValue;
  139. uint16_t cValue;
  140. short xOffset; //x的偏移量
  141. short yOffset;
  142. uint16_t Angle;
  143. uint32_t TagNum;
  144. uint8_t AtStation;
  145. uint8_t DirStatus;
  146. uint8_t DirLiftStatus;
  147. uint8_t RoadNum_xxxxx;
  148. uint16_t TgtStationXvalue;
  149. uint16_t TgtStationYvalue;
  150. uint16_t TgtStationCvalue; //
  151. uint16_t DirPauseStatus; //
  152. uint16_t DecPressStatus; //
  153. uint16_t InTsjStatus; //
  154. uint16_t StartCvalue; //
  155. uint16_t TgtCvalue;
  156. uint16_t TsjStatus;
  157. uint16_t TsjId;
  158. uint16_t TsjFloorStatus;
  159. uint16_t TsjStationXvalue;
  160. uint16_t TsjStationYvalue;
  161. uint16_t near_time_out;
  162. uint8_t estop_flag;
  163. uint8_t reset_flag;
  164. uint16_t motor_err;
  165. } Status_t;
  166. extern Status_t S;
  167. #define TO_DIGIT(a) ((a) - '0')
  168. #define TO_ASCII(a) ((a) + '0')
  169. #define NEAR(c, t, d) (((c) < ((t) + (d))) && ((c) > ((t) - (d))))
  170. #define FAngleReach NEAR(S.FAngle, Set.FAngle, Cfg.MtsAglAcy)
  171. #define BAngleReach NEAR(S.BAngle, Set.BAngle, Cfg.MtsAglAcy)
  172. /*********************************************************************************************************
  173. * GLOBAL CFG
  174. *********************************************************************************************************/
  175. #define CFG_REMOTE_CTRL_NUM 8
  176. #define CFG_RFID_TYPE_HS 0
  177. #define CFG_RFID_TYPE_EMR 1
  178. #define CFG_IS_RfidType(a) (((a) == CFG_RFID_TYPE_HS) || ((a) == CFG_RFID_TYPE_EMR))
  179. #define CFG_BATTERY_TYPE_24V 24
  180. #define CFG_BATTERY_TYPE_48V 48
  181. #define CFG_IS_BtyType(a) (((a) == CFG_BATTERY_TYPE_24V) || ((a) == CFG_BATTERY_TYPE_48V))
  182. #define CFG_CARGO_TYPE_NULL 0
  183. #define CFG_CARGO_TYPE_LIFT 1
  184. #define CFG_CARGO_TYPE_QIANYI 2
  185. #define CFG_CARGO_TYPE_CHUANSONG 3
  186. #define CFG_CARGO_TYPE_LIFT_SCREW 4
  187. #define CFG_IS_CargoType(a) (((a) == CFG_CARGO_TYPE_CHUANSONG) || ((a) == CFG_CARGO_TYPE_LIFT) || ((a) == CFG_CARGO_TYPE_QIANYI) || ((a) == CFG_CARGO_TYPE_NULL))
  188. #define CFG_OBS_TYPE_KL 0
  189. #define CFG_OBS_TYPE_PX24 1
  190. #define CFG_IS_ObsType(a) (((a) == CFG_OBS_TYPE_KL) || ((a) == CFG_OBS_TYPE_PX24))
  191. //#define CFG_STEER_TYPE_SPEED 0
  192. //#define CFG_STEER_TYPE_POSITION 1
  193. //#define CFG_IS_SteerType(a) (((a) == CFG_STEER_TYPE_SPEED) || ((a) == CFG_STEER_TYPE_POSITION))
  194. #define CFG_WlkMcType_Hs 0
  195. #define CFG_WlkMcType_SenChuang 1
  196. #define CFG_WlkMcType_Motec 2
  197. #define CFG_WlkMcType_Leisai 3
  198. #define CFG_WlkMcType_Curtis 4
  199. //#define CFG_WlkMcType_RoboteQ 5
  200. #define CFG_StrMcType_Hs 0
  201. #define CFG_StrMcType_SenChuang 1
  202. #define CFG_StrMcType_Motec 2
  203. //#define CFG_StrMcType_Leisai 3
  204. //#define CFG_StrMcType_Curtis 4
  205. #define CFG_StrMcType_RoboteQ 5
  206. typedef struct {
  207. uint16_t Saved;
  208. uint16_t AgvId;
  209. // 类型
  210. uint16_t Type;
  211. uint16_t Version;
  212. // 最大转速
  213. uint16_t MaxRpm;
  214. /* 速度因子, 一米转数 = 减速比/轮子直周长 */
  215. uint16_t SpdFctr;
  216. uint16_t Speed;
  217. uint16_t SpdMxDft;
  218. uint16_t SpdHigh;
  219. uint16_t SpdMid;
  220. uint16_t SpdLow;
  221. //接近速度
  222. uint16_t SpdNear;
  223. //手动速度
  224. uint16_t SpdMan;
  225. //旋转速度
  226. uint16_t SpdRota;
  227. //电池电压
  228. uint16_t BtyType;
  229. //电池满电电压
  230. uint16_t VoltFull;
  231. //电池高电压
  232. uint16_t VoltHigh;
  233. //电池中电压
  234. uint16_t VoltMid;
  235. //电池低电压
  236. uint16_t VoltLow;
  237. //电池报警电压
  238. uint16_t VoltWarn;
  239. //电池停止电压
  240. uint16_t VoltStop;
  241. uint16_t RfidType; //depreciated
  242. uint16_t CargoType; //depreciated
  243. uint16_t ObsType; //depreciated
  244. uint16_t CscType; //depreciated
  245. uint16_t WlkMcType;
  246. uint16_t StrMcType; //depreciated
  247. /* 每度脉冲数 大齿轮*编码器线数*编码器倍数 /编码器齿轮数/360 */
  248. uint16_t FStrPlsDeg;
  249. uint16_t BStrPlsDeg;
  250. uint16_t NavSP;
  251. uint16_t NavSI;
  252. uint16_t NavSD;
  253. uint16_t NavWP;
  254. uint16_t DftWP;
  255. uint16_t MtsAglAcy;
  256. // uint16_t SteerType;
  257. /* 角度为arctan(舵轮-横向中心线/舵轮-纵向中心线) */
  258. short RoteAngle;
  259. // todo need Test to short
  260. int FZeroAng;
  261. int BZeroAng;
  262. uint16_t FWlkAcc;
  263. uint16_t FWlkDcc;
  264. uint16_t BWlkAcc;
  265. uint16_t BWlkDcc;
  266. uint16_t StartAct;
  267. uint16_t ZeroSt;
  268. uint32_t ipaddr;
  269. uint32_t netmask;
  270. uint32_t gateway;
  271. uint16_t dhcp;
  272. uint16_t stop_dist; /* 停止距离 */
  273. uint16_t reduce_dist; /* 减速距离 */
  274. } Cfg_t;
  275. extern Cfg_t Cfg;
  276. /**
  277. * @brief 初始化配置
  278. * @param
  279. * @return
  280. */
  281. void Cfg_Init(void);
  282. /*
  283. *********************************************************************************************************
  284. * GOLBAL STATUS
  285. *********************************************************************************************************
  286. */
  287. /* 未设置状态 */
  288. #define STATUS_INIT 0
  289. /* 就绪状态 */
  290. #define STATUS_READY 1
  291. /* 运行状态 */
  292. #define STATUS_RUN 2
  293. /* 停止状态 */
  294. //#define STATUS_STOP 3
  295. /* 急停按钮急停状态 */
  296. #define STATUS_ESTOP 4
  297. /* 刹车停止 */
  298. //#define STATUS_BREAK 5
  299. /* 驱动器错误 */
  300. #define STATUS_DRIVER_ERROR 6
  301. /* 导航错误 */
  302. #define STATUS_TARGET_ST_ERROR 7
  303. /* 任务错误 */
  304. #define STATUS_TASK_ERROR 8
  305. /* 手动控制状态 */
  306. #define STATUS_REMOTE_MANUAL 9
  307. /* 1 开头为停止 */
  308. /* 遇到障碍物停止 或者 冲突区域 */
  309. #define STATUS_STOP_OBS 11
  310. /* 防撞条紧急停止 */
  311. #define STATUS_STOP_BUMPER 12
  312. /* 冲突区域 */
  313. //#define STATUS_STOP_BLOCK 13
  314. /* 电压低 */
  315. #define STATUS_STOP_LOW_POWER 15
  316. /* 2开头为 警告 一般情况下只是警告,车辆正常运行 */
  317. /* 车辆低电压运行:电压低但是还未到必须停止,亮黄灯提示充电 */
  318. #define STATUS_RUN_LOW_POWER 21
  319. /* 车辆遇到障碍物靠近:遇到障碍物比较远,低速运行 */
  320. #define STATUS_RUN_OBS_LOW_SPEED 22
  321. /* 正方向磁导航脱线 */
  322. #define STATUS_ERROR_FMGS_OFFLINE 31
  323. /* 反方向磁导航脱线 */
  324. #define STATUS_ERROR_BMGS_OFFLINE 32
  325. /* 正方向磁导航脱线 */
  326. #define STATUS_ERROR_LMGS_OFFLINE 33
  327. /* 反方向磁导航脱线 */
  328. #define STATUS_ERROR_RMGS_OFFLINE 34
  329. #define STATUS_ERROR_ROTE_OFFLINE 35
  330. /* 取货物时举升不为空 */
  331. #define STATUS_ERROR_CARGO_START_FULL 71//取货失败1/
  332. #define STATUS_ERROR_CARGO_PICKUP_FAIL 72//取货失败2/
  333. #define STATUS_ERROR_CARGO_RELEASE_FAIL 73//放货失败/
  334. //
  335. //#define ERROR_STATUS_FORWARD_LIMIT 0x32//前驱动器限位保护
  336. //#define ERROR_STATUS_FORWARD_CONNECT_FAILS 0x33//前驱动器上位机连接失败
  337. //#define ERROR_STATUS_FORWARD_LOW_VOLT 0x34//前驱动器欠压
  338. //#define ERROR_STATUS_FORWARD_OFFLINE 0x35//前磁导航脱线
  339. //
  340. //#define ERROR_STATUS_BACK_LIMIT 0x3C//后驱动器限位保护
  341. //#define ERROR_STATUS_BACK_CONNECT_FAILS 0x3D//后驱动器上位机连接失败
  342. //#define ERROR_STATUS_BACK_OFFLINE 0x3E//后磁导航脱线
  343. //#define ERROR_STATUS_BACK_LOW_VOLT 0x3F//后驱动器欠压
  344. /* 初始化状态 */
  345. #define NAV_STATUS_INIT 0
  346. /* 在路上 */
  347. #define NAV_STATUS_NAV 1
  348. /* 已经进入站点 */
  349. #define NAV_STATUS_STATION_IN 2
  350. /* 在站点分支 */
  351. #define NAV_STATUS_STATION_BRANCH 3
  352. /* 到达站点 */
  353. #define NAV_STATUS_STATION_ON 4
  354. #define WARN_NULL 0
  355. #define WARN_OBS_NEAR 100
  356. #define WARN_OBS_STOP 50
  357. #define WARN_LOW_POWER 200
  358. /**
  359. * @brief 顶升状态定义
  360. */
  361. // 初始化状态,未检测状态时为此状态
  362. #define LIFT_STATUS_INIT 0
  363. #define LIFT_STATUS_TOP 1
  364. #define LIFT_STATUS_BOTTOM 2
  365. #define LIFT_STATUS_UP 3
  366. #define LIFT_STATUS_DOWN 4
  367. #define LIFT_STATUS_MANUAL_UP 5
  368. #define LIFT_STATUS_MANUAL_DOWN 6
  369. #define LIFT_STATUS_CENTER 7
  370. #define LIFT_STATUS_MANUAL_STOP 8
  371. /**
  372. * @brief 顶升货物状态
  373. */
  374. #define DIR_STATUS_INIT 0
  375. #define DIR_STATUS_FB 1
  376. #define DIR_STATUS_LR 2
  377. #define DIR_STATUS_UP 3
  378. #define DIR_STATUS_DOWN 4
  379. #define DIR_STATUS_MANUAL_UP 5
  380. #define DIR_STATUS_MANUAL_DOWN 6
  381. #define DIR_STOP_STATUS 2
  382. #define DIR_RUN_STATUS 1
  383. //换向延时时间10=10*100ms=1s
  384. #define DIR_LIFT_TIMER 10
  385. // 初始化状态
  386. #define CARGO_STATUS_INIT 'I'
  387. // 无货物
  388. #define CARGO_STATUS_NULL 'N'
  389. // 货物在中间
  390. #define CARGO_STATUS_CENTER 'C'
  391. // 货物偏置
  392. #define CARGO_STATUS_SIDE 'S'
  393. //#define TASK_STATUS_INIT 'I'
  394. //#define TASK_STATUS_NULL 'N'
  395. //#define TASK_STATUS_IDLE 'D'
  396. //#define TASK_STATUS_TO_ST 'T'
  397. //#define TASK_STATUS_ST_ACTION 'A'
  398. //#define TASK_STATUS_MANUAL 'M'
  399. #define BATTERY_STATUS_NULL 0
  400. #define BATTERY_STATUS_STOP 00
  401. #define BATTERY_STATUS_WARN 20
  402. #define BATTERY_STATUS_LOW 40
  403. #define BATTERY_STATUS_MID 60
  404. #define BATTERY_STATUS_HIGH 80
  405. #define BATTERY_STATUS_FULL 100
  406. /* 灯光状态FF表示常亮,0表示不亮 其他的数值表示间隔多少个0.1秒切换一次 */
  407. #define LIGHT_STATUS_OFF 0x0
  408. #define LIGHT_STATUS_ON 0xFF
  409. #define LIGHT_STATUS_TOGGLE_05 05
  410. #define LIGHT_STATUS_TOGGLE_1S 10
  411. #define LIGHT_STATUS_TOGGLE_2S 20
  412. #define IDLE_TIMEOUT 1800
  413. #define ACT_NULL 0x0
  414. #define ACT_RESET 0x7
  415. #define ACT_BRAKE 0x6
  416. #define ACT_STOP 0x5
  417. #define ACT_FORWARD 0x1
  418. #define ACT_FORWARD_LEFT 0x13
  419. #define ACT_FORWARD_RIGHT 0x14
  420. #define ACT_FORWARD_STOP_CROSS 0x15
  421. #define ACT_BACKWARD 0x2
  422. #define ACT_BACKWARD_LEFT 0x23
  423. #define ACT_BACKWARD_RIGHT 0x24
  424. #define ACT_BACKWARD_STOP_CROSS 0x25
  425. #define ACT_LEFT 0x3
  426. #define ACT_LEFT_FORWARD 0x31
  427. #define ACT_LEFT_BACKWARD 0x32
  428. #define ACT_LEFT_STOP_CROSS 0x35
  429. #define ACT_RIGHT 0x4
  430. #define ACT_RIGHT_FORWARD 0x41
  431. #define ACT_RIGHT_BACKWARD 0x42
  432. #define ACT_RIGHT_STOP_CROSS 0x45
  433. #define ACT_MANUAL_FORWARD 0x91
  434. #define ACT_MANUAL_BACKWARD 0x92
  435. #define ACT_MANUAL_DRIFT_LEFT 0x93
  436. #define ACT_MANUAL_DRIFT_RIGHT 0x94
  437. #define ACT_MANUAL_STOP 0x95
  438. #define ACT_MANUAL_ROTATE_LEFT 0x97
  439. #define ACT_MANUAL_ROTATE_RIGHT 0x98
  440. #define ACT_SPEED_NORMAL 0x80
  441. #define ACT_SPEED_LOW 0x81
  442. //#define ACT_SPEED_MID 0x82
  443. //#define ACT_SPEED_HIGH 0x83
  444. #define ACT_BRANCH_LEFT 0xA
  445. #define ACT_BRANCH_RIGHT 0xB
  446. #define ACT_ROTATE_LEFT 0xC
  447. #define ACT_ROTATE_RIGHT 0xD
  448. #define ACT_ROUND_LEFT 0xE
  449. #define ACT_ROUND_RIGHT 0xF
  450. #define ActIsManual(act) (((act) >> 4) == 9)
  451. #define ActIsNav(act) (((act)==ACT_FORWARD) || \
  452. ((act)==ACT_FORWARD_LEFT) || \
  453. ((act)==ACT_FORWARD_RIGHT) || \
  454. ((act)==ACT_FORWARD_STOP_CROSS) || \
  455. ((act)==ACT_BACKWARD) || \
  456. ((act)==ACT_BACKWARD_LEFT) || \
  457. ((act)==ACT_BACKWARD_RIGHT) || \
  458. ((act)==ACT_BACKWARD_STOP_CROSS) || \
  459. ((act)==ACT_LEFT) || \
  460. ((act)==ACT_LEFT_FORWARD) || \
  461. ((act)==ACT_LEFT_BACKWARD) || \
  462. ((act)==ACT_LEFT_STOP_CROSS) || \
  463. ((act)==ACT_RIGHT) || \
  464. ((act)==ACT_RIGHT_FORWARD) || \
  465. ((act)==ACT_RIGHT_BACKWARD) || \
  466. ((act)==ACT_RIGHT_STOP_CROSS) || \
  467. ((act)==ACT_STOP))
  468. #define NULL_POINT 0xFFFF
  469. #define NULL_STATION NULL_POINT
  470. #define RFID_TYPE_POINT 0
  471. #define RFID_TYPE_STATION 1
  472. #define RFID_TYPE_CMD 2
  473. #define RFID_TYPE_ACT 3
  474. #define RFID_TYPE_BLOCK 4
  475. #define RFID_TYPE_BLOCK_OUT 5
  476. #define RFID_TYPE_OBS_AREA 6
  477. #define DIRECTION_NULL 0x0
  478. #define DIRECTION_FORWARD 0x1
  479. #define DIRECTION_BACKWARD 0x2
  480. #define DIRECTION_LEFT 0x3
  481. #define DIRECTION_RIGHT 0x4
  482. #define DIRECTION_ROTATE 0x5
  483. #define OBS_STATUS_NULL 0
  484. #define OBS_STATUS_FAR 1 //
  485. #define OBS_STATUS_NEAR 2
  486. /**
  487. * @brief RDM Relative Direction Model 相对方向模式
  488. */
  489. #define RDM_PASS 0x0 /*直接通过*/
  490. #define RDM_BRANCH_LEFT 0x1
  491. #define RDM_BRANCH_RIGHT 0x2
  492. #define RDM_DRIFT_LEFT 0x3
  493. #define RDM_DRIFT_RIGHT 0x4
  494. #define RDM_TRUN_LEFT 0x5
  495. #define RDM_TRUN_RIGHT 0x6
  496. #define RDM_STOP 0x7
  497. #define RDM_STOP_CROSS 0x8
  498. #define RDM_BACK 0xF
  499. #define RDM_LIFT_UP 0x11
  500. #define RDM_LIFT_DOWN 0x12
  501. #define FR_NULL 0
  502. #define FR_FORWARD 1
  503. #define FR_BACKWARD 2
  504. #define BRANCH_CENTER 0
  505. #define BRANCH_LEFT 1
  506. #define BRANCH_RIGHT 2
  507. #define CROSS_OFF 0
  508. #define CROSS_FB 1
  509. #define CROSS_LR 2
  510. #define CROSS_XY 3
  511. /* 因队列判满需要最后一个不存任务,因此任务总数为16个 */
  512. #define MAX_TASK_Q 64
  513. /* 接收命令的返回值 */
  514. #define TASK_LIST 0
  515. #define TASK_ASCCEPT 1
  516. #define TASK_FINISH 2
  517. #define TASK_LIST_FULL 9
  518. #define TASK_ERROR_LEN 61
  519. #define TASK_ERROR_SRC_NOT_NUM 62
  520. #define TASK_ERROR_DST_NOT_NUM 63
  521. #define TASK_ERROR_SRC_NOT_DEFINE 64
  522. #define TASK_ERROR_DST_NOT_DEFINE 65
  523. #define TASK_ERROR_PICKUP 73 // 取货失败
  524. #define TASK_ERROR_RELEASE 74 // 放货失败
  525. #define TRANS_STATUS_NULL 0
  526. #define TRANS_STATUS_INIT 1
  527. #define TRANS_STATUS_TO_SRC 2
  528. #define TRANS_STATUS_PICKUP 3
  529. #define TRANS_STATUS_TO_DST 4
  530. #define TRANS_STATUS_RELEASE 5
  531. #define TRANS_STATUS_ACTION 6
  532. #define TRANS_STATUS_TO_STN 10
  533. #define RUNTYPE_INIT 0
  534. #define RUNTYPE_FR 1
  535. #define RUNTYPE_STATION 2
  536. #define RUNTYPE_TRANS 3
  537. #define TIMER_STATUS_TO_CHARGE 1
  538. #define TIMER_STATUS_TO_TASK 2
  539. /* 任务从SRC站点取货到DST站点放货 */
  540. typedef struct {
  541. char Id[65];
  542. int Src;
  543. int Dst;
  544. int DstFloor;
  545. uint8_t Act;
  546. } TASK_Transport_t;
  547. typedef struct {
  548. uint8_t Status;
  549. TASK_Transport_t Elems[MAX_TASK_Q];
  550. uint8_t Current;
  551. uint8_t Last;
  552. } TransportQueue_t;
  553. typedef struct {
  554. /* 按钮 */
  555. uint8_t BtnRun :1;
  556. uint8_t BtnRev :1;
  557. uint8_t BtnEStop :1;
  558. uint8_t BtnCStop :1;
  559. uint8_t BtnLiftUp :1;
  560. uint8_t BtnLiftDown :1;
  561. uint8_t :2;
  562. // 遥控器
  563. uint8_t RmcStart :1;
  564. uint8_t RmcStop :1;
  565. uint8_t RmcEStop :1;
  566. uint8_t RmcLiftUp :1;
  567. uint8_t RmcLiftDown :1;
  568. uint8_t :3;
  569. uint8_t RmcForward :1;
  570. uint8_t RmcBackward :1;
  571. uint8_t RmcDriftLeft :1;
  572. uint8_t RmcDriftRight :1;
  573. uint8_t RmcRoteLeft :1;
  574. uint8_t RmcRoteRight :1;
  575. uint8_t :2;
  576. // 避障
  577. // OBS1
  578. uint8_t OBS1In1 :1;
  579. uint8_t OBS1In2 :1;
  580. uint8_t OBS1In3 :1;
  581. uint8_t OBS1In4 :1;
  582. uint8_t :4;
  583. // OBS2
  584. uint8_t OBS2In1 :1;
  585. uint8_t OBS2In2 :1;
  586. uint8_t OBS2In3 :1;
  587. uint8_t OBS2In4 :1;
  588. uint8_t :4;
  589. // OBS3
  590. uint8_t OBS3In1 :1;
  591. uint8_t OBS3In2 :1;
  592. uint8_t OBS3In3 :1;
  593. uint8_t OBS3In4 :1;
  594. uint8_t :6;
  595. /* OBS4 */
  596. uint8_t OBS4In1 :1;
  597. uint8_t OBS4In2 :1;
  598. uint8_t OBS4In3 :1;
  599. uint8_t OBS4In4 :1;
  600. uint8_t :6;
  601. /* NPN */
  602. uint8_t Npn1 :1;
  603. uint8_t Npn2 :1;
  604. uint8_t Npn3 :1;
  605. uint8_t Npn4 :1;
  606. uint8_t Npn5 :1;
  607. uint8_t Npn6 :1;
  608. uint8_t Npn7 :1;
  609. uint8_t Npn8 :1;
  610. uint8_t Npn9 :1;
  611. uint8_t Npn10 :1;
  612. /* Lift */
  613. uint8_t Lft1InTop :1;
  614. uint8_t Lft1InBottom :1;
  615. uint8_t :6;
  616. uint8_t Lft2InTop :1;
  617. uint8_t Lft2InBottom :1;
  618. uint8_t :6;
  619. uint8_t Motor1DET :1;
  620. uint8_t Motor2DET :1;
  621. } IN_t;
  622. extern IN_t I;
  623. typedef struct {
  624. /* 信号灯1 */
  625. uint8_t Light1Red :1;
  626. uint8_t Light1Yellow :1;
  627. uint8_t Light1Green :1;
  628. uint8_t :5;
  629. // 信号灯2
  630. uint8_t Light2Red :1;
  631. uint8_t Light2Yellow :1;
  632. uint8_t Light2Green :1;
  633. uint8_t :5;
  634. uint8_t OBS1Out1 :1;
  635. uint8_t OBS1Out2 :1;
  636. uint8_t OBS1Out3 :1;
  637. uint8_t OBS1Out4 :1;
  638. uint8_t :4;
  639. uint8_t OBS2Out1 :1;
  640. uint8_t OBS2Out2 :1;
  641. uint8_t OBS2Out3 :1;
  642. uint8_t OBS2Out4 :1;
  643. uint8_t :4;
  644. uint8_t OBS3Out1 :1;
  645. uint8_t OBS3Out2 :1;
  646. uint8_t :6;
  647. uint8_t OBS4Out1 :1;
  648. uint8_t OBS4Out2 :1;
  649. uint8_t :6;
  650. /* Lift */
  651. uint8_t Lft1Up24 :1;
  652. uint8_t Lft1Down24 :1;
  653. uint8_t Lft1Out1 :1;
  654. uint8_t Lft1Out2 :1;
  655. uint8_t :4;
  656. uint8_t Lft2Up24 :1;
  657. uint8_t Lft2Down24 :1;
  658. uint8_t Lft2up1 :1;
  659. uint8_t Lft2Down2 :1;
  660. uint8_t :4;
  661. /* KDS */
  662. uint8_t KDS1Out241 :1;
  663. uint8_t KDS1Out242 :1;
  664. uint8_t KDS1Out243 :1;
  665. uint8_t KDS1Out244 :1;
  666. uint8_t :4;
  667. uint8_t KDS2Out241 :1;
  668. uint8_t KDS2Out242 :1;
  669. uint8_t KDS2Out243 :1;
  670. uint8_t KDS2Out244 :1;
  671. uint8_t :4;
  672. /* Motor */
  673. uint8_t Motor1FR :1;
  674. uint8_t Motor1EN :1;
  675. uint8_t Motor1BR :1;
  676. uint8_t :5;
  677. uint8_t Motor2FR :1;
  678. uint8_t Motor2EN :1;
  679. uint8_t Motor2BR :1;
  680. uint8_t :5;
  681. } OUT_t;
  682. extern OUT_t O;
  683. #ifndef MgsNA
  684. #define MgsNA MIN_S16
  685. #endif
  686. #ifndef AngleNA
  687. #define AngleNA MIN_S16
  688. #endif
  689. #ifndef PosNA
  690. #define PosNA MIN_S16
  691. #endif
  692. #define DR_STATUS_INIT 0
  693. #define DR_STATUS_RUN 1
  694. /* 无冲突 */
  695. #define BLOCK_NULL 0
  696. /* 冲突获取 */
  697. #define BLOCK_ACK 1
  698. /* 冲突申请 */
  699. #define BLOCK_REQ 2
  700. /* 冲突释放 */
  701. #define BLOCK_RLS 3
  702. #define OBS_AREA_OFF 0
  703. #define OBS_AREA_ON 0xFF
  704. #define DEMO_TASK_TIME 50
  705. #define AGV_ON_FB (S.CrossType == CROSS_FB)
  706. #define AGV_ON_LR (S.CrossType == CROSS_LR)
  707. #define AGV_ON_CROSS (S.CrossType == CROSS_XY)
  708. #define AGV_OFF_LINE (S.CrossType == CROSS_OFF)
  709. #define DM_READ_CODE (S.DmS == 0)
  710. /**
  711. * @brief 初始化配置
  712. * @param
  713. * @return
  714. */
  715. void Stat_Init(void);
  716. typedef struct {
  717. uint16_t RpmNav;
  718. uint16_t RpmDft;
  719. uint16_t RpmNear;
  720. uint16_t RpmManual;
  721. uint16_t RpmRotate;
  722. uint16_t Branch;
  723. uint16_t SpeedAct;
  724. uint16_t Speed;
  725. uint16_t SpeedDrift;
  726. uint16_t RotateAct;
  727. uint16_t RotateCnt;
  728. uint16_t DRAction;
  729. uint16_t DRRpmNav;
  730. uint16_t DRRpmDft;
  731. short FStrRpm;
  732. short BStrRpm;
  733. short FWlkRpm;
  734. short BWlkRpm;
  735. short FAngle;
  736. short BAngle;
  737. short LiftRpmUp;
  738. short LiftRpmDown;
  739. int LiftUpPos;
  740. int LiftDownPos;
  741. int LiftPos;
  742. uint16_t FWlkAAcc;
  743. uint16_t FWlkMAcc;
  744. uint16_t FWlkADcc;
  745. uint16_t FWlkMDcc;
  746. uint32_t ChargeStation;
  747. short LiftRpm;
  748. uint16_t StationDcc;
  749. uint32_t TsjStation;
  750. //专为唐山修改,2排11列与3排11列不起作用
  751. uint32_t TsjPoint; //地标
  752. } Set_t;
  753. extern Set_t Set;
  754. void Set_Init(void);
  755. void SetSpeed(uint16_t speed);
  756. #define JSON_O_SetCfg "SetCfg"
  757. #define JSON_O_GetCfg "GetCfg"
  758. #define JSON_O_SaveCfg "SaveCfg"
  759. #define JSON_O_Status "Status"
  760. #define JSON_O_SetLog "SetLog"
  761. #define JSON_O_ClearTask "ClearTask"
  762. #define JSON_O_SetAct "SetAct"
  763. #define JSON_O_ToStation "ToStn"
  764. #define JSON_O_AddTask "AddTsk"
  765. #define JSON_O_BlkReq "BlkReq"
  766. #define JSON_O_BlkRls "BlkRls"
  767. #define JSON_O_Time "Time"
  768. #define OP_SET_ACTION 0x2
  769. #define OP_SET_SPEED 0x4
  770. #define OP_SET_STATION 0x5
  771. #define OP_RUN 'R'
  772. #define OP_ADDTASK '1'
  773. #define OP_CLEAR_TASK '2'
  774. #define OP_STOP 'S'
  775. #define OP_TO_STATION 'T'
  776. #define OP_LOG ':'
  777. #define OP_GET_TASK 0xA4
  778. #define OP_SET_TASK 0xA5
  779. //#define OP_SAVE_TASK 0xA6
  780. #define OP_GET_ROADINFO 0xB1
  781. #define OP_SET_ROADINFO 0xB2
  782. #define OP_SAVE_ROADINFO 0xB3
  783. #define OPT_STOP 0x01
  784. #define OPT_STOP_LIFT_UP 0x02
  785. #define OPT_STOP_LIFT_DOWN 0x03
  786. #define OPT_TURN_LEFT 0x04
  787. #define OPT_TURN_RIGHT 0x05
  788. #define OPT_SET_SPEED 0x06
  789. #define OPT_SWITCH_LINE 0x07
  790. #define OPT_SET_OBS 0x08
  791. #define OPT_LEFT 0x09
  792. #define OPT_RIGHT 0x0A
  793. typedef struct {
  794. uint16_t Station;
  795. uint8_t Opertaion;
  796. uint8_t param;
  797. } Trans_t;
  798. #define GD_MAX_STATION 128
  799. #define GD_MAX_POINT 128
  800. extern TransportQueue_t Trans;
  801. uint8_t FLASH_Write(uint32_t startAddr, const uint8_t *pBuffer, uint32_t size);
  802. uint16_t FLASH_ReadHalfWord(uint32_t addr) ;
  803. #endif /* ENV_H_ */