Skip to content

Commit a401343

Browse files
committed
Localization with flipped RGBD
1 parent 7dc4d4c commit a401343

3 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/rbiyani_project_5/adventure_simulator/adventure_description/finn/finn.urdf.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- Sensors... FIXME -->
99

1010
<xacro:include filename="$(find adventure_description)/urdf/sensors/asus_xtion_pro.urdf.xacro"/>
11-
<xacro:sensor_asus_xtion_pro parent="base_link" xyz="0.14 0.02 0.1" rpy="0 0 0"/>
11+
<xacro:sensor_asus_xtion_pro parent="base_link" xyz="0.14 -0.02 0.1" rpy="3.14 0 0"/>
1212
<!-- origin xyz="${0} 0 0" rpy="0.0 0.0 0.0"/-->
1313
<!-- /xacro:sensor_asus_xtion_pro -->
1414

src/rbiyani_project_5/adventure_slam/src/Localizer.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "adventure_slam/Localizer.h"
22
#include "adventure_slam/Line.h"
33
#include <cmath>
4+
#include "ros/ros.h"
45

56
#define PI 3.14159265
67

@@ -26,7 +27,7 @@ void Localizer::estimate()
2627
if (sz != 0)
2728
del_yaw = del_yaw / sz;
2829

29-
if (std::abs(del_yaw) > 0.01)
30+
if (std::abs(del_yaw) > 0.1)
3031
delta_yaw += del_yaw;
3132

3233
if (delta_yaw >= 360)
@@ -42,13 +43,15 @@ void Localizer::estimate()
4243
double curr_shift_x = 0, curr_shift_y = 0;
4344
int i, j, count = 0;
4445
double first_distance, first_angle, second_distance, sec_angle;
45-
46+
ROS_INFO("Angle: %d", sz);
4647
for (i = 0; i < sz ; i++)
4748
{
49+
//Simple Averaging approach
4850
LineMatcher::Pair curr_pair = matched_pairs[i];
4951
first_distance = curr_pair.L1.distance - curr_pair.L2.distance;
5052
first_angle = (curr_pair.L1.angle + curr_pair.L2.angle) / 2;
51-
if ((abs(first_angle) > 0 && abs(first_angle) < 10) || (abs(first_angle) > 80 && abs(first_angle) < 100) || (abs(first_angle) > 170 && abs(first_angle) < 190))
53+
ROS_INFO("Angle: %f", first_angle);
54+
if ((abs(first_angle) > 0 && abs(first_angle) < 40) || (abs(first_angle) > 80 && abs(first_angle) < 120) || (abs(first_angle) > 160 && abs(first_angle) < 200))
5255
{
5356
first_angle = first_angle * PI / 180;
5457

@@ -58,8 +61,8 @@ void Localizer::estimate()
5861
}
5962
}
6063

61-
/* Following logic used Line Intersection Logic
62-
if (sz == 1)
64+
// Following logic used Line Intersection Logic
65+
/*if (sz == 1)
6366
{
6467
curr_shift_x += first_distance * std::cos(first_angle);
6568
curr_shift_y += first_distance * std::sin(first_angle);
@@ -85,9 +88,9 @@ void Localizer::estimate()
8588
curr_shift_y = curr_shift_y / count;
8689
}
8790

88-
//if(std::abs(curr_shift_x) > 0.01)
91+
if(std::abs(curr_shift_x) > 0.001)
8992
shift_x += curr_shift_x;
90-
//if(std::abs(curr_shift_y) > 0.01)
93+
if(std::abs(curr_shift_y) > 0.001)
9194
shift_y += curr_shift_y;
9295

9396
}

src/rbiyani_project_5/adventure_slam/src/adventure_slam.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ LaserScanProcessor::LaserScanProcessor(ros::NodeHandle n_)
4545
this->vo_pub = n.advertise<nav_msgs::Odometry>("/vo",1);
4646

4747
//Initialize the odom_visual to odom Broadcaster
48-
tf::Transform transform;
49-
transform.setOrigin( tf::Vector3(0.0, 0.0, 0.0) );
50-
transform.setRotation( tf::Quaternion(0, 0, 0, 1) );
51-
br_vo_o.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "odom_visual", "odom"));
48+
//tf::Transform transform;
49+
//transform.setOrigin( tf::Vector3(0.0, 0.0, 0.0) );
50+
//transform.setRotation( tf::Quaternion(0, 0, 0, 1) );
51+
//br_vo_o.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "odom_visual", "odom"));
5252
}
5353

5454
void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
@@ -66,6 +66,10 @@ void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
6666
float angle = scan.angle_min;
6767
std::vector<pcl::PointXYZ> points;
6868
std::vector<float> ranges = scan.ranges;
69+
70+
// FIX: Make the ranges go reverse to support reverse camera placement
71+
std::reverse(ranges.begin(),ranges.end());
72+
6973
float theta, r;
7074
tf::Vector3 v, v_glob, v_glob_vo;
7175

@@ -81,7 +85,7 @@ void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
8185
continue;
8286
if (isnan(r))
8387
continue;
84-
point.x = (r * std::sin(theta)); //camera_depth_optical_frame has actually Z direction pointing forwards.
88+
point.x = (-r * std::sin(theta)); //camera_depth_optical_frame has actually Z direction pointing forwards.
8589
point.z = (r * std::cos(theta)); //Initially, We rather took y direction pointing forwards. i.e. swap z and y and get all
8690
point.y = 0; //co-ordinates in first two-components of the PCLXYZ object and work with
8791
//all are equations in X-Y Plane(rather than X-Z). It is better to work in X-Z so that
@@ -150,8 +154,6 @@ void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
150154
//v_glob.setY(loc.shift_x);
151155
//v_glob.setZ(0);
152156

153-
//TODO: Need to transform v_glob to base_footprint - static transform-will be only translation
154-
// For now robot's pose point is taken to be as the point on the optical depth sensor
155157
v_glob_vo = (this->vo_fixed_to_base) * v_glob;
156158

157159
//Correct for the difference in origin
@@ -177,7 +179,7 @@ void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
177179
result_pose.pose.pose.position.z = 0;
178180

179181
//tf::Quaternion res = vo_fixed_to_base.getRotation() * tf::createQuaternionFromRPY(0,loc.delta_yaw,0);
180-
tf::Quaternion res = tf::createQuaternionFromRPY(0, 0, -loc.delta_yaw * M_PI / 180);
182+
tf::Quaternion res = tf::createQuaternionFromRPY(0, 0, loc.delta_yaw * M_PI / 180);
181183

182184
//Publishing the other way round
183185
//tf::Quaternion res = tf::createQuaternionFromRPY(0, 0, -loc.delta_yaw);
@@ -230,11 +232,11 @@ void LaserScanProcessor::laser_callback(const sensor_msgs::LaserScan& scan)
230232

231233
tf::Transform odom_to_ov;
232234
odom_to_ov = base_to_ov * base_to_odom.inverse();
233-
br_vo_o.sendTransform(tf::StampedTransform(odom_to_ov, ros::Time::now(), "/odom_visual", "/odom"));
234-
br_vo_bf.sendTransform(tf::StampedTransform(base_to_ov, ros::Time::now(), "/odom_visual", "/base_footprint"));
235+
//br_vo_o.sendTransform(tf::StampedTransform(odom_to_ov, ros::Time::now(), "/odom_visual", "/odom"));
236+
//br_vo_bf.sendTransform(tf::StampedTransform(base_to_ov, ros::Time::now(), "/odom_visual", "/base_footprint"));
235237

236238
//Attach base_footprint to odom_visual directly
237-
//br_vo_bf.sendTransform(tf::StampedTransform(base_to_ov.inverse(), ros::Time::now(), "/base_footprint", "/odom_visual"));
239+
br_vo_bf.sendTransform(tf::StampedTransform(base_to_ov.inverse(), ros::Time::now(), "/base_footprint", "/odom_visual"));
238240

239241
}
240242

0 commit comments

Comments
 (0)