37 return fmod(fmod(angle, 2.0*M_PI) + 2.0*M_PI, 2.0*M_PI);
58 LshapeTracker::LshapeTracker(
const double& x_corner,
const double& y_corner,
const double& L1,
const double& L2,
const double& theta,
const double& dt){
75 A << 1, 0,dt, 0, ddt, 0,
82 C << 1, 0, 0, 0, 0, 0,
85 Q << 1, 0, 0, 0, 0, 0,
94 P.setIdentity() * 0.1;
99 VectorXd x0_dynamic(n);
100 x0_dynamic << x_corner, y_corner, 0, 0, 0, 0;
123 0, 0, dt,
pow(dt,2)/2,
127 KalmanFilter shape_kalman_filter(dt, As, Cs, Qs, Rs, Ps);
128 this->
shape_kf = shape_kalman_filter;
130 VectorXd x0_shape(n);
133 if(L1>L1init){L1init = L1;}
134 if(L2>L2init){L2init = L2;}
135 x0_shape << L1init, L2init, theta, 0;
147 void LshapeTracker::update(
const double& thetaL1,
const double& x_corner,
const double& y_corner,
const double& L1,
const double& L2,
const double& dt,
const int cluster_size) {
158 y << x_corner, y_corner;
162 Vector3d shape_measurements;
169 shape_measurements << L1max, L2max, theta;
186 double x_new = x_corner;
187 double y_new = y_corner;
188 double theta_new = to;
189 double theta_corner = from;
195 double x_corner_L1= x_c + L1_box*
cos(theta_corner);
196 double y_corner_L1= y_c + L1_box*
sin(theta_corner);
199 double x_corner_L2 = x_c + L2_box*sin(theta_corner);
200 double y_corner_L2 = y_c - L2_box*cos(theta_corner);
204 Eigen::Matrix<double, 5, 5> C;
216 Eigen::Matrix<double, 5, 1> means;
217 means(0) = x_c - x_new;
218 means(1) = y_c - y_new;
219 means(2) = L1-L1_box;
220 means(3) = L2-L2_box;
221 means(4) =
findTurn(theta_new,theta_corner);
222 std::vector<double> mdistances;
223 mdistances.push_back(means.transpose()*C.inverse()*means);
225 means(0) = x_corner_L1 - x_new;
226 means(1) = y_corner_L1 - y_new;
227 means(2) = L1-L2_box;
228 means(3) = L2-L1_box;
229 means(4) =
findTurn(theta_new,theta_corner_L1);
230 mdistances.push_back(means.transpose()*C.inverse()*means);
232 means(0) = x_corner_L2 - x_new;
233 means(1) = y_corner_L2 - y_new;
234 means(2) = L1-L2_box;
235 means(3) = L2-L1_box;
236 means(4) =
findTurn(theta_new,theta_corner_L2);
237 mdistances.push_back(means.transpose()*C.inverse()*means);
239 int minElementIndex = std::min_element(mdistances.begin(),mdistances.end()) - mdistances.begin();
241 if(minElementIndex == 2 &&
abs(mdistances[0]-mdistances[2])>0.1 &&
current_size>1){
244 else if(minElementIndex == 1 &&
abs(mdistances[0]-mdistances[1])>0.1 &&
current_size>1){
249 std::vector<double> distances;
251 euclidean =
sqrt(
pow(x_c-x_new,2) +
pow(y_c-y_new,2) +
pow(
findTurn(theta_new,theta_corner),2) +
pow(L1-L1_box,2) +
pow(L2-L2_box,2));
252 distances.push_back(euclidean);
253 euclidean =
sqrt(
pow(x_corner_L1-x_new,2) +
pow(y_corner_L1-y_new,2) +
pow(
findTurn(theta_new,theta_corner_L1),2)+
pow(L1-L2_box,2) +
pow(L2-L1_box,2));
254 distances.push_back(euclidean);
255 euclidean =
sqrt(
pow(x_corner_L2-x_new,2) +
pow(y_corner_L2-y_new,2) +
pow(
findTurn(theta_new,theta_corner_L2),2)+
pow(L1-L2_box,2) +
pow(L2-L1_box,2));
256 distances.push_back(euclidean);
260 void LshapeTracker::BoxModel(
double& x,
double& y,
double& vx,
double& vy,
double& theta,
double& psi,
double& omega,
double& L1,
double& L2,
double& length,
double& width){
265 double ex = (L1 *
cos(theta) + L2 *
sin(theta)) /2;
266 double ey = (L1 *
sin(theta) - L2 *
cos(theta)) /2;
283 double theta_pro = new_angle - old_angle;
285 if(-M_PI<=theta_pro && theta_pro <= M_PI){
287 else if(theta_pro > M_PI){
288 turn = theta_pro - 2*M_PI;}
289 else if(theta_pro < -M_PI){
290 turn = theta_pro + 2*M_PI;}
308 std::vector<double>
angles;
310 angles.push_back(angle_norm);
311 angles.push_back(angle_norm +
pi);
312 angles.push_back(angle_norm +
pi/2);
313 angles.push_back(angle_norm + 3*
pi/2);
320 for (
unsigned int i = 0; i < 4; ++i) {
328 if(pos ==0 || pos==1){
366 new_shape_states(0) = L2;
368 new_shape_states(1) = L1;
400 new_shape_states(0) = L2;
402 new_shape_states(1) = L1;
void detectCornerPointSwitch(const double &from, const double &to, const double dt)
static double shortest_angular_distance(double from, double to)
void ClockwisePointSwitch()
static double normalize_angle(double angle)
double min(double a, double b)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
#define ROS_DEBUG_STREAM(args)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
void CounterClockwisePointSwitch()
double findTurn(const double &new_angle, const double &old_angle)
void BoxModel(double &x, double &y, double &vx, double &vy, double &theta, double &psi, double &omega, double &L1, double &L2, double &length, double &width)
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
static double normalize_angle_positive(double angle)
void update(const double &thetaL1, const double &x_corner, const double &y_corner, const double &L1, const double &L2, const double &dt, const int cluster_size)
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
void changeStates(const Eigen::VectorXd &new_states)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
void update(const Eigen::VectorXd &y)
void detectCornerPointSwitchMahalanobis(const double &from, const double &to, const double dt)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
void findOrientation(double &psi, double &length, double &width)
Finds orientations of tracked object.
Eigen::Matrix< double, 6, 1 > Vector6d