can_bus.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /*------------------小车控制参数和函数起------------------*/
  19. void order(cannet_frame* frame); // 指令模式
  20. void toggleLamp(cannet_frame* frame); // 车灯开关
  21. void move_run(cannet_frame* frame); // 车辆前进
  22. void move_neutral(cannet_frame* frame); //空挡
  23. void move_back(cannet_frame* frame); // 车辆后退
  24. void move_rot(cannet_frame* frame); // 车辆右转
  25. bool car_stop(cannet_frame* frame);
  26. int gearselection(cannet_frame* frame); // 1:前进档 2:空挡 3:后退档
  27. void speedlevel(cannet_frame* frame); //升档降档
  28. void runSpeed(unsigned char input, unsigned char &byte0, unsigned char &byte1); //座舱速度与小车速度线性对应
  29. void backSpeed(unsigned char input, unsigned char &byte0, unsigned char &byte1);
  30. void leftSpeed(unsigned char input, unsigned char &byte0, unsigned char &byte1);
  31. void rightSpeed(unsigned char input, unsigned char &byte0, unsigned char &byte1);
  32. bool order_flag ; // 指令模式
  33. bool lamp_flag ; // 车灯状态
  34. bool run_flag ; // 车辆前进后退
  35. bool rot_flag ; // 车辆转弯
  36. bool stop_flag ; // 急停状态
  37. int gear; //前进后退空档位
  38. int speed_flag = 11; //升档降档档位
  39. // unsigned int mapped_value;
  40. unsigned char id_init[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  41. unsigned char id_111[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  42. /*------------------小车控制参数和函数止------------------*/
  43. private:
  44. void Run();
  45. void CanSendProc();
  46. void SendStatusToMSG();
  47. private:
  48. CMessageQueue* _message;
  49. SensorCanBus<CCanBusSensor> * _canbus;
  50. bool _run;
  51. std::thread _can_thread;
  52. std::mutex _last_can_lock;
  53. struct can_frame Sendframe[7];
  54. bool _front_view = true;
  55. int16_t Direction;//方向
  56. int16_t Hand_Throttle;//手油门
  57. int16_t Foot_Throttle;//脚油门
  58. int16_t Brake;//刹车
  59. int64_t count;
  60. FeedData _data;
  61. int model;//0本地,1远程
  62. /*-------------------小车控制起--------------------*/
  63. unsigned char order_on[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:421 指令模式开
  64. unsigned char headlamp_on[8] = {0x01,0x01,0x50,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常开
  65. unsigned char headlamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 前车灯常关
  66. unsigned char taillamp_on[8] = {0x01,0x00,0x00,0x01,0x50,0x00,0x00,0x00}; //id:121 后车灯常开
  67. unsigned char taillamp_off[8] = {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:121 后车灯常关
  68. unsigned char move_forward[8] = {0x00,0x96,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s前进
  69. unsigned char move_backward[8] = {0xFF,0x6A,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 以0.15m/s后退
  70. unsigned char turn_left[8] = {0x00,0x00,0x00,0xc8,0x00,0x00,0x00,0x00}; //id:111 以0.2rad/s左转
  71. unsigned char turn_right[8] = {0x00,0x00,0xFF,0x38,0x00,0x00,0x00,0x00}; //id:111 以0.2rad/s右转
  72. unsigned char stop_on[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //id:111 急停
  73. /*-------------------小车控制止--------------------*/
  74. };