can_bus.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "../common/comm.h"
  3. #include "../common/notifier.h"
  4. #include "../common/iobuffer.h"
  5. #include "../common/sensor_socket.h"
  6. using namespace std;
  7. class CMessageQueue;
  8. class CCanBusSensor
  9. {
  10. public:
  11. CCanBusSensor(CMessageQueue *q);
  12. void Notify(struct can_frame *date);
  13. void SetCanBusSensor(SensorCanBus<CCanBusSensor>* can);
  14. void Start();
  15. void Stop();
  16. void OnMessage(cannet_frame* frames, int32_t count = 4);
  17. void Emergency();
  18. void order(cannet_frame* frames); // 指令模式
  19. void toggleLamp(cannet_frame* frames); // 车灯开关
  20. void move_run(cannet_frame* frames); // 车辆前进
  21. void move_rot(cannet_frame* frames); // 车辆右转
  22. void car_stop(cannet_frame* frames);
  23. private:
  24. void Run();
  25. void CanSendProc();
  26. void SendStatusToMSG();
  27. private:
  28. CMessageQueue* _message;
  29. SensorCanBus<CCanBusSensor> * _canbus;
  30. bool _run;
  31. std::thread _can_thread;
  32. std::mutex _last_can_lock;
  33. struct can_frame Sendframe[4];
  34. bool _front_view = true;
  35. int16_t Direction;//方向
  36. int16_t Hand_Throttle;//手油门
  37. int16_t Foot_Throttle;//脚油门
  38. int16_t Brake;//刹车
  39. int64_t count;
  40. FeedData _data;
  41. int model;//0本地,1远程
  42. /*-------------------小车控制起--------------------*/
  43. bool order_flag = false; // 指令模式
  44. bool lamp_flag = false; // 车灯状态
  45. bool run_flag = false; // 车辆前进后退
  46. bool rot_flag = false; // 车辆转弯
  47. bool stop_flag = false; // 急停状态
  48. unsigned char order_on[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:421 指令模式开
  49. unsigned char headlamp_on[8] = {0x01,0x01,0x50,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常开
  50. unsigned char headlamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常关
  51. unsigned char taillamp_on[8] = {0x01,0x00,0x00,0x01,0x50,0x00,0x00,0x00}; //id:121 后车灯常开
  52. unsigned char taillamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 后车灯常关
  53. unsigned char move_forward[8] = {0x00,0x96,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s前进
  54. unsigned char move_backward[8] = {0x00,0xcc,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s后退
  55. unsigned char move_rotation[8] = {0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x00}; //id:111 以0.2rad/s旋转
  56. unsigned char stop[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 急停
  57. /*-------------------小车控制止--------------------*/
  58. };