monkeycar_bus.h 2.0 KB

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