Browse Source

人在候车上速度显示

lixioayao 5 years ago
parent
commit
b8d9e8a0e7
4 changed files with 13 additions and 12 deletions
  1. 4 6
      card_person.cpp
  2. 1 1
      monkey_car/monkeycar_bus.h
  3. 5 2
      monkey_car/monkeycar_person.cpp
  4. 3 3
      monkey_car/monkeycar_person.h

+ 4 - 6
card_person.cpp

@@ -226,13 +226,11 @@ point person::getSmoothPoint(uint64_t& t)
 	pt.x = lp.x;
 	pt.y = -lp.y;
 	t=lp.m_time;
-	if(auto  p = m_monkeyPerson.lock() )
-	{
-		if(p->is_on_bus())
-		{
+	if(auto  p = m_monkeyPerson.lock() ){
+		if(p->is_on_bus()){
 			m_stat = 7;
-			pt = p->getPoint(t);	
-			log_info("getpoint_oncar:%d,%lld",m_id,t);
+			pt = p->getPoint(t,m_speed);	
+			log_info("getpoint_oncar:%d,%lld,speed:%.2f",m_id,t,m_speed);
 		}
 	}
 	return pt;

+ 1 - 1
monkey_car/monkeycar_bus.h

@@ -55,9 +55,9 @@ struct monkey_bus
 	{
 		return m_speed * time_val;
 	}
+	double m_speed;
 private:
 	std::vector<std::shared_ptr<monkey_person>> person_list_;
-	double m_speed;
 	int    m_direct;
 	std::unique_ptr<std::thread> m_thread;
 	std::mutex m_mtx;

+ 5 - 2
monkey_car/monkeycar_person.cpp

@@ -97,7 +97,7 @@ std::shared_ptr<monkey_bus> monkey_person::getBus()
 {
 	return m_bus.lock();
 }
-point_2 monkey_person::get_position()
+point_2 monkey_person::get_position(double &speedx)
 {
 	uint64_t timeval = tool_time::now_to_ms();
 	if (m_bus.expired() || m_cur_distance == 0x12345678)
@@ -122,11 +122,13 @@ point_2 monkey_person::get_position()
 	//get time val
 	double val = 1.*(timeval - m_timeval)/1000;
 	//get Distance
-	double ds = tbus->getNextStep_Distance(val)/m_area.lock()->getScale();
+    double scale=m_area.lock()->getScale();
+	double ds = tbus->getNextStep_Distance(val)/scale;
 	m_cur_distance += ds;
 	//compensation speed...
 	m_cur_distance += m_compensation_speed * val;
 	double total_length = m_area.lock()->get_total_length();
+    speedx=(tbus->m_speed+m_compensation_speed*scale)*3.6;
 	if (m_cur_distance < ZERO_)
 	{
 		m_cur_distance = 0;
@@ -134,6 +136,7 @@ point_2 monkey_person::get_position()
 	else if (m_cur_distance >=total_length)
 	{
 		m_cur_distance = total_length;
+        speedx=0;
 	}
 	//get point
 	point_2 tmp = m_area.lock()->map(m_cur_distance);

+ 3 - 3
monkey_car/monkeycar_person.h

@@ -40,10 +40,10 @@ struct monkey_person
 	bool fit_speed(double*ret_speed);
 	bool get_num_point(int * p);
 	bool init_another_list(size_t index);
-	point getPoint(uint64_t t)
+	point getPoint(uint64_t t,double &speed)
 	{
 		point p;
-		const auto pt = get_position();
+		const auto pt = get_position(speed);
 		t=m_timeval;
 		if(point_2::is_valid(pt))
 		{
@@ -63,7 +63,7 @@ struct monkey_person
 	void Set_AverageSpeed();
 	void handle_monkeycar_fit(double);
 private:
-	point_2 get_position();
+	point_2 get_position(double &speed);
 public:
 	int				m_getOffIndex;
 	double			m_cur_distance;   //curTime distance