monkeycar_bus.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef __MONKEYCAR_BUS__
  2. #define __MONKEYCAR_BUS__
  3. #include <numeric>
  4. #include "base_data.h"
  5. #include <thread>
  6. #include <mutex>
  7. #define K_MEANS_X1 0.5
  8. #define K_MEANS_X2 1.8
  9. #define K_MEANS_x3 3.0
  10. #define ON_BUS_SPEED_LIMIT 0.95
  11. #define ON_BUS_SPEED_MAX_LIMIT 2
  12. #define OFF_BUS_SPEED_LIMIT 0.67
  13. #define ADJUST_DISTANCE_TIMEVAL (5 * 60 * 1000)
  14. #define PERSON_SEND_TIME_INTERVAL (2 * 1000) // 2s intervel
  15. #define GROUPING_PERSON_DISTANCE 20 // 60/map_scale now is 60m
  16. #define GROUPING_PERSON_NUMBER 5
  17. #define FIT_COUNT_LIMIT (ADJUST_DISTANCE_TIMEVAL/PERSON_SEND_TIME_INTERVAL)*6.0/10
  18. #define LONG_TIME_NO_DATA (1*60*1000) //1 min no data recv.
  19. enum DIRECTION{
  20. NO_DIRECTION = 0,
  21. POSTIVE_DIRECTION,
  22. NEGTIVE_DIRECTION
  23. };
  24. struct monkey_person;
  25. struct monkey_bus
  26. {
  27. monkey_bus(double speed, int direct);
  28. ~monkey_bus()
  29. {
  30. m_stop = true;
  31. m_thread->join();
  32. }
  33. bool test_get_on(double speed);
  34. /********************************/
  35. /*Decide whether to get off or not*/
  36. /******************************/
  37. bool test_get_off(std::shared_ptr<monkey_person> mp,double speed);
  38. //get the average speed
  39. void Set_AverageSpeed(double speed);
  40. //get off the bus
  41. void getOffTheBus(std::shared_ptr<monkey_person> mp);
  42. //get on the bus
  43. void getOnTheBus(std::shared_ptr<monkey_person> mp,std::shared_ptr<monkey_bus> bus);
  44. //get step length
  45. inline double getNextStep_Distance(double time_val)
  46. {
  47. return m_speed * time_val;
  48. }
  49. double m_speed;
  50. private:
  51. std::vector<std::shared_ptr<monkey_person>> person_list_;
  52. int m_direct;
  53. std::unique_ptr<std::thread> m_thread;
  54. std::mutex m_mtx;
  55. void adjust_monkeyperson_distance();
  56. bool m_stop;
  57. };
  58. #endif