can_bus.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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* frame); // 指令模式
  19. void toggleLamp(cannet_frame* frame); // 车灯开关
  20. void move_run(cannet_frame* frame); // 车辆前进
  21. void move_rot(cannet_frame* frame); // 车辆右转
  22. void car_stop(cannet_frame* frame);
  23. /*------------------小车控制参数起------------------*/
  24. bool order_flag = false; // 指令模式
  25. bool lamp_flag = false; // 车灯状态
  26. bool run_flag = false; // 车辆前进后退
  27. bool rot_flag = false; // 车辆转弯
  28. bool stop_flag = false; // 急停状态
  29. /*------------------小车控制参数止------------------*/
  30. private:
  31. void Run();
  32. void CanSendProc();
  33. void SendStatusToMSG();
  34. private:
  35. CMessageQueue* _message;
  36. SensorCanBus<CCanBusSensor> * _canbus;
  37. bool _run;
  38. std::thread _can_thread;
  39. std::mutex _last_can_lock;
  40. struct can_frame Sendframe[6];
  41. bool _front_view = true;
  42. int16_t Direction;//方向
  43. int16_t Hand_Throttle;//手油门
  44. int16_t Foot_Throttle;//脚油门
  45. int16_t Brake;//刹车
  46. int64_t count;
  47. FeedData _data;
  48. int model;//0本地,1远程
  49. /*-------------------小车控制起--------------------*/
  50. unsigned char* data2copy;
  51. unsigned char order_on[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:421 指令模式开
  52. unsigned char headlamp_on[8] = {0x01,0x01,0x50,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常开
  53. unsigned char headlamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常关
  54. unsigned char taillamp_on[8] = {0x01,0x00,0x00,0x01,0x50,0x00,0x00,0x00}; //id:121 后车灯常开
  55. unsigned char taillamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 后车灯常关
  56. unsigned char move_forward[8] = {0x00,0x96,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s前进
  57. unsigned char move_backward[8] = {0x00,0xcc,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s后退
  58. unsigned char move_rotation[8] = {0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x00}; //id:111 以0.2rad/s旋转
  59. unsigned char stop_on[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 急停
  60. /*-------------------小车控制止--------------------*/
  61. };