Optimaze with new mbed os for study

Dependencies:   TS_DISCO_F746NG BSP_DISCO_F746NG Graphics

Committer:
ngtkien
Date:
Fri Aug 23 16:59:22 2019 +0000
Revision:
5:64cafb3c6e7b
Parent:
0:d8b9955d2b36
KienNgo optimaze

Who changed what in which revision?

UserRevisionLine numberNew contents of line
karpent 0:d8b9955d2b36 1 //
karpent 0:d8b9955d2b36 2 // Target.cpp - Simple simulation of radar target
karpent 0:d8b9955d2b36 3 //
karpent 0:d8b9955d2b36 4
karpent 0:d8b9955d2b36 5 #include "Target.h"
karpent 0:d8b9955d2b36 6 #include "math.h"
karpent 0:d8b9955d2b36 7
karpent 0:d8b9955d2b36 8 Target::Target(int id, float speed, float direction)
karpent 0:d8b9955d2b36 9 {
karpent 0:d8b9955d2b36 10 Id = id;
karpent 0:d8b9955d2b36 11
karpent 0:d8b9955d2b36 12 _speed = speed;
karpent 0:d8b9955d2b36 13 _direction = direction;
karpent 0:d8b9955d2b36 14
karpent 0:d8b9955d2b36 15 _type = 0;
karpent 0:d8b9955d2b36 16 _lastUpdateTime = 0;
karpent 0:d8b9955d2b36 17 }
karpent 0:d8b9955d2b36 18
karpent 0:d8b9955d2b36 19
karpent 0:d8b9955d2b36 20 Target::Target(int id, float x, float y, float h, float speed, float direction)
karpent 0:d8b9955d2b36 21 {
karpent 0:d8b9955d2b36 22 _location.SetLocation(x, y, h);
karpent 0:d8b9955d2b36 23 _speed = speed;
karpent 0:d8b9955d2b36 24 _direction = direction;
karpent 0:d8b9955d2b36 25
karpent 0:d8b9955d2b36 26 _type = 0;
karpent 0:d8b9955d2b36 27 _lastUpdateTime = 0;
karpent 0:d8b9955d2b36 28 Id = id;
karpent 0:d8b9955d2b36 29 }
karpent 0:d8b9955d2b36 30
karpent 0:d8b9955d2b36 31 Location Target::GetLocation()
karpent 0:d8b9955d2b36 32 {
karpent 0:d8b9955d2b36 33 return _location;
karpent 0:d8b9955d2b36 34 }
karpent 0:d8b9955d2b36 35
karpent 0:d8b9955d2b36 36 void Target::SetLocation(float x, float y)
karpent 0:d8b9955d2b36 37 {
karpent 0:d8b9955d2b36 38 _location.SetLocation(x, y, _location.GetHeight());
karpent 0:d8b9955d2b36 39 }
karpent 0:d8b9955d2b36 40
karpent 0:d8b9955d2b36 41 float Target::GetX()
karpent 0:d8b9955d2b36 42 {
karpent 0:d8b9955d2b36 43 return _location.GetX();
karpent 0:d8b9955d2b36 44 }
karpent 0:d8b9955d2b36 45
karpent 0:d8b9955d2b36 46 float Target::GetY()
karpent 0:d8b9955d2b36 47 {
karpent 0:d8b9955d2b36 48 return _location.GetY();
karpent 0:d8b9955d2b36 49 }
karpent 0:d8b9955d2b36 50
karpent 0:d8b9955d2b36 51 float Target::GetAzimuth()
karpent 0:d8b9955d2b36 52 {
karpent 0:d8b9955d2b36 53 return _location.GetAzimuth();
karpent 0:d8b9955d2b36 54 }
karpent 0:d8b9955d2b36 55
karpent 0:d8b9955d2b36 56 float Target::GetDistance()
karpent 0:d8b9955d2b36 57 {
karpent 0:d8b9955d2b36 58 return _location.GetDistance();
karpent 0:d8b9955d2b36 59 }
karpent 0:d8b9955d2b36 60
karpent 0:d8b9955d2b36 61 float Target::GetDirection()
karpent 0:d8b9955d2b36 62 {
karpent 0:d8b9955d2b36 63 return _direction;
karpent 0:d8b9955d2b36 64 }
karpent 0:d8b9955d2b36 65
karpent 0:d8b9955d2b36 66 float Target::GetSpeed()
karpent 0:d8b9955d2b36 67 {
karpent 0:d8b9955d2b36 68 return _speed;
karpent 0:d8b9955d2b36 69 }
karpent 0:d8b9955d2b36 70
karpent 0:d8b9955d2b36 71 int Target::GetType()
karpent 0:d8b9955d2b36 72 {
karpent 0:d8b9955d2b36 73 return _type;
karpent 0:d8b9955d2b36 74 }
karpent 0:d8b9955d2b36 75
karpent 0:d8b9955d2b36 76 void Target::UpdateLocationForTime(uint32_t currentTime)
karpent 0:d8b9955d2b36 77 {
karpent 0:d8b9955d2b36 78 // Calculate time period from last update
karpent 0:d8b9955d2b36 79 uint32_t timePeriod = currentTime - _lastUpdateTime;
karpent 0:d8b9955d2b36 80 _lastUpdateTime = currentTime;
karpent 0:d8b9955d2b36 81
karpent 0:d8b9955d2b36 82 float distance = _speed * timePeriod / 3600000;
karpent 0:d8b9955d2b36 83 float dx = distance * sinf(GetDirection());
karpent 0:d8b9955d2b36 84 float dy = distance * cosf(GetDirection());
karpent 0:d8b9955d2b36 85 SetLocation(GetX() + dx, GetY() + dy);
karpent 0:d8b9955d2b36 86 }
karpent 0:d8b9955d2b36 87
karpent 0:d8b9955d2b36 88 void Target::SetLocationAngular(float distance, float azimuth)
karpent 0:d8b9955d2b36 89 {
karpent 0:d8b9955d2b36 90 _location.SetLocationAngular(distance, azimuth, _location.GetElevation());
karpent 0:d8b9955d2b36 91 }