Improved object perception
This commit is contained in:
		
							parent
							
								
									47556d1d5d
								
							
						
					
					
						commit
						a502af99d4
					
				| @ -156,23 +156,35 @@ void PerceivedObject::Refresh(Polar position, float radius) { | |||||||
|   this->confidence = maxConfidence; |   this->confidence = maxConfidence; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void Perception::AddPerceivedObject(Polar position) { | ||||||
|  |   // int objCount = PerceivedObjectCount();
 | ||||||
|  |   // printf("perc obj count %d\n");
 | ||||||
|  | 
 | ||||||
|  |   PerceivedObject *obj = new PerceivedObject(position); | ||||||
|  |   // objCount = PerceivedObjectCount();
 | ||||||
|  |   // printf("perc obj count %d\n");
 | ||||||
|  |   AddPerceivedObject(obj); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void Perception::AddPerceivedObject(PerceivedObject *obj) { | void Perception::AddPerceivedObject(PerceivedObject *obj) { | ||||||
|   unsigned char farthestObjIx = 0; |   unsigned char farthestObjIx = 0; | ||||||
|   unsigned char availableSlotIx = 0; |   unsigned char availableSlotIx = 0; | ||||||
|   for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { |   for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { | ||||||
|  |     // printf("[%d] %d\n", objIx, this->perceivedObjects[objIx]);
 | ||||||
|     // Is this slot available?
 |     // Is this slot available?
 | ||||||
|     if (perceivedObjects[objIx] == nullptr) { |     if (this->perceivedObjects[objIx] == nullptr) { | ||||||
|       availableSlotIx = objIx; |       availableSlotIx = objIx; | ||||||
|     } |     } | ||||||
|     // Do we see the same object?
 |     // Do we see the same object?
 | ||||||
|     else if (obj->IsTheSameAs(perceivedObjects[objIx])) { |     else if (obj->IsTheSameAs(this->perceivedObjects[objIx])) { | ||||||
|       perceivedObjects[objIx]->Refresh(obj->position, obj->radius); |       printf("[%d] Updating...\n", objIx); | ||||||
|  |       this->perceivedObjects[objIx]->Refresh(obj->position, obj->radius); | ||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|     // Is this the fartest object we see?
 |     // Is this the fartest object we see?
 | ||||||
|     else if (perceivedObjects[farthestObjIx] == nullptr || |     else if (this->perceivedObjects[farthestObjIx] == nullptr || | ||||||
|              (perceivedObjects[objIx]->position.distance > |              (this->perceivedObjects[objIx]->position.distance > | ||||||
|               perceivedObjects[farthestObjIx]->position.distance)) { |               this->perceivedObjects[farthestObjIx]->position.distance)) { | ||||||
|       farthestObjIx = objIx; |       farthestObjIx = objIx; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -181,12 +193,13 @@ void Perception::AddPerceivedObject(PerceivedObject *obj) { | |||||||
|   // max number of objects)
 |   // max number of objects)
 | ||||||
|   if (availableSlotIx < maxObjectCount) { |   if (availableSlotIx < maxObjectCount) { | ||||||
|     // a slot is available
 |     // a slot is available
 | ||||||
|     perceivedObjects[availableSlotIx] = obj; |     printf("[%d] new object \n", availableSlotIx); | ||||||
|  |     this->perceivedObjects[availableSlotIx] = obj; | ||||||
|   } |   } | ||||||
|   // If this object is closer than the farthest object, then replace it
 |   // If this object is closer than the farthest object, then replace it
 | ||||||
|   else if (obj->position.distance < |   else if (obj->position.distance < | ||||||
|            perceivedObjects[farthestObjIx]->position.distance) { |            this->perceivedObjects[farthestObjIx]->position.distance) { | ||||||
|     perceivedObjects[farthestObjIx] = obj; |     this->perceivedObjects[farthestObjIx] = obj; | ||||||
|     // we may want to destroy the fartest object, but if it is created
 |     // we may want to destroy the fartest object, but if it is created
 | ||||||
|     // externally, other links may still exist...
 |     // externally, other links may still exist...
 | ||||||
|   } |   } | ||||||
| @ -195,13 +208,15 @@ void Perception::AddPerceivedObject(PerceivedObject *obj) { | |||||||
| unsigned char Perception::PerceivedObjectCount() { | unsigned char Perception::PerceivedObjectCount() { | ||||||
|   unsigned char objectCount = 0; |   unsigned char objectCount = 0; | ||||||
|   for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { |   for (unsigned char objIx = 0; objIx < maxObjectCount; objIx++) { | ||||||
|     if (perceivedObjects[objIx] != nullptr) |     if (this->perceivedObjects[objIx] != nullptr) | ||||||
|       objectCount++; |       objectCount++; | ||||||
|   } |   } | ||||||
|   return objectCount; |   return objectCount; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| PerceivedObject **Perception::GetPerceivedObjects() { return perceivedObjects; } | PerceivedObject **Perception::GetPerceivedObjects() { | ||||||
|  |   return this->perceivedObjects; | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void Perception::Update(float currentTimeMs) { | void Perception::Update(float currentTimeMs) { | ||||||
|   float deltaTime = currentTimeMs - lastUpdateTimeMs; |   float deltaTime = currentTimeMs - lastUpdateTimeMs; | ||||||
| @ -217,12 +232,13 @@ void Perception::Update(float currentTimeMs) { | |||||||
| 
 | 
 | ||||||
|     if (obj->DegradeConfidence(deltaTime) == false) { |     if (obj->DegradeConfidence(deltaTime) == false) { | ||||||
|       // delete obj
 |       // delete obj
 | ||||||
|       perceivedObjects[objIx] = nullptr; |       printf("[%d] delete object\n", objIx); | ||||||
|  |       this->perceivedObjects[objIx] = nullptr; | ||||||
|     } else { |     } else { | ||||||
|       // Serial.printf("[%d] confidence: %d\n", objIx,
 |       Serial.printf("[%d] confidence: %d\n", objIx, | ||||||
|       //               perceivedObjects[objIx]->confidence);
 |                     this->perceivedObjects[objIx]->confidence); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   if (perceivedObjects[0] != nullptr) { |   if (this->perceivedObjects[0] != nullptr) { | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -10,7 +10,7 @@ namespace RoboidControl { | |||||||
| class PerceivedObject { | class PerceivedObject { | ||||||
| public: | public: | ||||||
|   PerceivedObject(); |   PerceivedObject(); | ||||||
|   PerceivedObject(Polar position, float radius); |   PerceivedObject(Polar position, float radius = 0.1F); | ||||||
| 
 | 
 | ||||||
|   static constexpr float equalityDistance = 0.3F; |   static constexpr float equalityDistance = 0.3F; | ||||||
|   static constexpr float equalityAngle = 5.0F; |   static constexpr float equalityAngle = 5.0F; | ||||||
| @ -94,6 +94,7 @@ public: | |||||||
| 
 | 
 | ||||||
|   // Object Perception
 |   // Object Perception
 | ||||||
| 
 | 
 | ||||||
|  |   void AddPerceivedObject(Polar position); | ||||||
|   void AddPerceivedObject(PerceivedObject *obj); |   void AddPerceivedObject(PerceivedObject *obj); | ||||||
|   unsigned char PerceivedObjectCount(); |   unsigned char PerceivedObjectCount(); | ||||||
|   PerceivedObject **GetPerceivedObjects(); |   PerceivedObject **GetPerceivedObjects(); | ||||||
|  | |||||||
| @ -7,40 +7,37 @@ Propulsion::Propulsion() { | |||||||
|   this->motorCount = 0; |   this->motorCount = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| unsigned int Propulsion::GetMotorCount() { | unsigned int Propulsion::GetMotorCount() { return this->motorCount; } | ||||||
|   return this->motorCount; |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| Motor* Propulsion::GetMotor(unsigned int motorId) { | Motor *Propulsion::GetMotor(unsigned int motorId) { | ||||||
|   if (motorId >= this->motorCount) |   if (motorId >= this->motorCount) | ||||||
|     return nullptr; |     return nullptr; | ||||||
| 
 | 
 | ||||||
|   Thing* thing = this->placement[motorId].thing; |   Thing *thing = this->placement[motorId].thing; | ||||||
|   if (thing->IsMotor()) |   if (thing->IsMotor()) | ||||||
|     return (Motor*)thing; |     return (Motor *)thing; | ||||||
| 
 | 
 | ||||||
|   return nullptr; |   return nullptr; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Placement* Propulsion::GetMotorPlacement(unsigned int motorId) { | Placement *Propulsion::GetMotorPlacement(unsigned int motorId) { | ||||||
|   if (motorId >= this->motorCount) |   if (motorId >= this->motorCount) | ||||||
|     return nullptr; |     return nullptr; | ||||||
| 
 | 
 | ||||||
|   Placement* placement = &this->placement[motorId]; |   Placement *placement = &this->placement[motorId]; | ||||||
|   if (placement->thing->IsMotor()) |   if (placement->thing->IsMotor()) | ||||||
|     return placement; |     return placement; | ||||||
| 
 | 
 | ||||||
|   return nullptr; |   return nullptr; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| void Propulsion::Update(float currentTimeMs) {} | void Propulsion::Update(float currentTimeMs) {} | ||||||
| 
 | 
 | ||||||
| void Propulsion::SetTwistSpeed(float forward, float yaw) {} | void Propulsion::SetTwistSpeed(float forward, float yaw) {} | ||||||
| 
 | 
 | ||||||
| void Propulsion::SetTwistSpeed(Vector2 linear, float yaw) {} | void Propulsion::SetTwistSpeed(Vector2 linear, float yaw) {} | ||||||
| 
 | 
 | ||||||
| void Propulsion::SetTwistSpeed(Vector3 linear, | void Propulsion::SetTwistSpeed(Vector3 linear, float yaw, float pitch, | ||||||
|                                float yaw, |  | ||||||
|                                float pitch, |  | ||||||
|                                float roll) {} |                                float roll) {} | ||||||
|  | 
 | ||||||
|  | Polar Propulsion::GetVelocity() { return Polar(0, 0); } | ||||||
							
								
								
									
										19
									
								
								Propulsion.h
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								Propulsion.h
									
									
									
									
									
								
							| @ -2,6 +2,7 @@ | |||||||
| 
 | 
 | ||||||
| #include "Motor.h" | #include "Motor.h" | ||||||
| #include "Placement.h" | #include "Placement.h" | ||||||
|  | #include "Polar.h" | ||||||
| #include "Vector2.h" | #include "Vector2.h" | ||||||
| 
 | 
 | ||||||
| namespace Passer { | namespace Passer { | ||||||
| @ -14,7 +15,7 @@ namespace RoboidControl { | |||||||
| /// robot. This base class does not implement the functions to move the Roboid
 | /// robot. This base class does not implement the functions to move the Roboid
 | ||||||
| /// around.
 | /// around.
 | ||||||
| class Propulsion { | class Propulsion { | ||||||
|  public: | public: | ||||||
|   /// @brief Default Constructor for Propulsion
 |   /// @brief Default Constructor for Propulsion
 | ||||||
|   Propulsion(); |   Propulsion(); | ||||||
| 
 | 
 | ||||||
| @ -29,12 +30,12 @@ class Propulsion { | |||||||
|   /// @param motorIx The index of the motor
 |   /// @param motorIx The index of the motor
 | ||||||
|   /// @return Returns the motor or a nullptr when no motor with the given index
 |   /// @return Returns the motor or a nullptr when no motor with the given index
 | ||||||
|   /// could be found
 |   /// could be found
 | ||||||
|   Motor* GetMotor(unsigned int motorIx); |   Motor *GetMotor(unsigned int motorIx); | ||||||
|   /// @brief Get the Placement of a specific Motor
 |   /// @brief Get the Placement of a specific Motor
 | ||||||
|   /// @param motorIx The index of the Motor
 |   /// @param motorIx The index of the Motor
 | ||||||
|   /// @return Returns the Placement or a nullptr when no Placement with the give
 |   /// @return Returns the Placement or a nullptr when no Placement with the give
 | ||||||
|   /// index could be found
 |   /// index could be found
 | ||||||
|   Placement* GetMotorPlacement(unsigned int motorIx); |   Placement *GetMotorPlacement(unsigned int motorIx); | ||||||
| 
 | 
 | ||||||
|   // Velocity control
 |   // Velocity control
 | ||||||
| 
 | 
 | ||||||
| @ -56,16 +57,16 @@ class Propulsion { | |||||||
|   /// @param yaw The target rotation speed around the vertical axis
 |   /// @param yaw The target rotation speed around the vertical axis
 | ||||||
|   /// @param pitch The target rotation speed around the sideward axis
 |   /// @param pitch The target rotation speed around the sideward axis
 | ||||||
|   /// @param roll The target rotation speed around hte forward axis
 |   /// @param roll The target rotation speed around hte forward axis
 | ||||||
|   virtual void SetTwistSpeed(Vector3 linear, |   virtual void SetTwistSpeed(Vector3 linear, float yaw = 0.0F, | ||||||
|                              float yaw = 0.0F, |                              float pitch = 0.0F, float roll = 0.0F); | ||||||
|                              float pitch = 0.0F, |  | ||||||
|                              float roll = 0.0F); |  | ||||||
| 
 | 
 | ||||||
|  protected: |   virtual Polar GetVelocity(); | ||||||
|  | 
 | ||||||
|  | protected: | ||||||
|   /// @brief The number of motors used for Propulsion
 |   /// @brief The number of motors used for Propulsion
 | ||||||
|   unsigned int motorCount = 0; |   unsigned int motorCount = 0; | ||||||
|   /// @brief The Placement of the motors used for Propulsion
 |   /// @brief The Placement of the motors used for Propulsion
 | ||||||
|   Placement* placement = nullptr; |   Placement *placement = nullptr; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| } // namespace RoboidControl
 | } // namespace RoboidControl
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pascal Serrarens
						Pascal Serrarens