Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
jzhang1900 committed Jan 2, 2021
1 parent 06cb154 commit e46d373
Show file tree
Hide file tree
Showing 562 changed files with 72,631 additions and 0 deletions.
58 changes: 58 additions & 0 deletions P1_SFND_Lidar_Obstacle_Detection/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"files.associations": {
"complex": "cpp",
"cmath": "cpp",
"cctype": "c",
"clocale": "c",
"csignal": "c",
"cstdarg": "c",
"cstddef": "c",
"cstdio": "c",
"cstdlib": "c",
"cstring": "c",
"ctime": "c",
"cwchar": "c",
"cwctype": "c",
"array": "c",
"atomic": "c",
"strstream": "c",
"*.tcc": "c",
"bitset": "c",
"chrono": "c",
"cstdint": "c",
"deque": "c",
"list": "c",
"unordered_map": "c",
"unordered_set": "c",
"vector": "c",
"exception": "c",
"fstream": "c",
"functional": "c",
"initializer_list": "c",
"iomanip": "c",
"iosfwd": "c",
"iostream": "c",
"istream": "c",
"limits": "c",
"mutex": "c",
"new": "c",
"ostream": "c",
"numeric": "c",
"ratio": "c",
"sstream": "c",
"stdexcept": "c",
"streambuf": "c",
"system_error": "c",
"thread": "c",
"cfenv": "c",
"cinttypes": "c",
"tuple": "c",
"type_traits": "c",
"utility": "c",
"typeindex": "c",
"typeinfo": "c",
"algorithm": "c",
"memory": "c",
"string": "cpp"
}
}
23 changes: 23 additions & 0 deletions P1_SFND_Lidar_Obstacle_Detection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

add_definitions(-std=c++11)

set(CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")

project(playback)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")


add_executable (environment src/environment.cpp src/render/render.cpp src/processPointClouds.cpp)
target_link_libraries (environment ${PCL_LIBRARIES})




64 changes: 64 additions & 0 deletions P1_SFND_Lidar_Obstacle_Detection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Sensor Fusion Self-Driving Car Course

<img src="media/ObstacleDetectionFPS.gif" width="700" height="400" />

### Welcome to the Sensor Fusion course for self-driving cars.

In this course we will be talking about sensor fusion, whch is the process of taking data from multiple sensors and combining it to give us a better understanding of the world around us. we will mostly be focusing on two sensors, lidar, and radar. By the end we will be fusing the data from these two sensors to track multiple cars on the road, estimating their positions and speed.

**Lidar** sensing gives us high resolution data by sending out thousands of laser signals. These lasers bounce off objects, returning to the sensor where we can then determine how far away objects are by timing how long it takes for the signal to return. Also we can tell a little bit about the object that was hit by measuring the intesity of the returned signal. Each laser ray is in the infrared spectrum, and is sent out at many different angles, usually in a 360 degree range. While lidar sensors gives us very high accurate models for the world around us in 3D, they are currently very expensive, upwards of $60,000 for a standard unit.

**Radar** data is typically very sparse and in a limited range, however it can directly tell us how fast an object is moving in a certain direction. This ability makes radars a very pratical sensor for doing things like cruise control where its important to know how fast the car infront of you is traveling. Radar sensors are also very affordable and common now of days in newer cars.

**Sensor Fusion** by combing lidar's high resoultion imaging with radar's ability to measure velocity of objects we can get a better understanding of the sorrounding environment than we could using one of the sensors alone.


## Installation

### Ubuntu

```bash
$> sudo apt install libpcl-dev
$> cd ~
$> git clone https://github.com/udacity/SFND_Lidar_Obstacle_Detection.git
$> cd SFND_Lidar_Obstacle_Detection
$> mkdir build && cd build
$> cmake ..
$> make
$> ./environment
```

### Windows

http://www.pointclouds.org/downloads/windows.html

### MAC

#### Install via Homebrew
1. install [homebrew](https://brew.sh/)
2. update homebrew
```bash
$> brew update
```
3. add homebrew science [tap](https://docs.brew.sh/Taps)
```bash
$> brew tap brewsci/science
```
4. view pcl install options
```bash
$> brew options pcl
```
5. install PCL
```bash
$> brew install pcl
```

#### Prebuilt Binaries via Universal Installer
http://www.pointclouds.org/downloads/macosx.html
NOTE: very old version

#### Build from Source

[PCL Source Github](https://github.com/PointCloudLibrary/pcl)

[PCL Mac Compilation Docs](http://www.pointclouds.org/documentation/tutorials/compiling_pcl_macosx.php)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 171 additions & 0 deletions P1_SFND_Lidar_Obstacle_Detection/src/environment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/* \author Aaron Brown */
// Create simple 3d highway enviroment using PCL
// for exploring self-driving car sensors

#include "sensors/lidar.h"
#include "render/render.h"
#include "processPointClouds.h"
// using templates for processPointClouds so also include .cpp to help linker
#include "processPointClouds.cpp"

ProcessPointClouds<pcl::PointXYZ> *pc_processor = new ProcessPointClouds<pcl::PointXYZ>();

std::vector<Car> initHighway(bool renderScene, pcl::visualization::PCLVisualizer::Ptr& viewer)
{

Car egoCar( Vect3(0,0,0), Vect3(4,2,2), Color(0,1,0), "egoCar");
Car car1( Vect3(15,0,0), Vect3(4,2,2), Color(0,0,1), "car1");
Car car2( Vect3(8,-4,0), Vect3(4,2,2), Color(0,0,1), "car2");
Car car3( Vect3(-12,4,0), Vect3(4,2,2), Color(0,0,1), "car3");

std::vector<Car> cars;
cars.push_back(egoCar);
cars.push_back(car1);
cars.push_back(car2);
cars.push_back(car3);

if(renderScene)
{
renderHighway(viewer);
egoCar.render(viewer);
car1.render(viewer);
car2.render(viewer);
car3.render(viewer);
}

return cars;
}

void cityBlock(pcl::visualization::PCLVisualizer::Ptr& viewer,
ProcessPointClouds<pcl::PointXYZI>* pc_processorI, const pcl::PointCloud<pcl::PointXYZI>::Ptr& inputCloud)
{
bool render_box = true;

typename pcl::PointCloud<pcl::PointXYZI>::Ptr inputCloud2 = pc_processorI->FilterCloud(inputCloud, 0.1f ,
Eigen::Vector4f (-10, -5, -2, 1),
Eigen::Vector4f ( 30, 8, 1, 1));

std::pair<pcl::PointCloud<pcl::PointXYZI>::Ptr, pcl::PointCloud<pcl::PointXYZI>::Ptr> segmentCloud =
pc_processorI->SegmentPlaneCustomRansac(inputCloud2, 100, 0.2);

std::vector<pcl::PointCloud<pcl::PointXYZI>::Ptr> cloudClusters =
pc_processorI->ClusteringCustom(segmentCloud.first, 0.75, 10, 500);

int clusterId = 0;
std::vector<Color> colors = {Color(1,0,0), Color(0,1,0), Color(0,0,1)};

for(pcl::PointCloud<pcl::PointXYZI>::Ptr cluster : cloudClusters)
{
// std::cout << "cluster size ";
// pc_processorI->numPoints(cluster);
renderPointCloud(viewer,cluster,"obstCloud"+std::to_string(clusterId),colors[clusterId]);

if(render_box)
{
Box box = pc_processorI->BoundingBox(cluster);
renderBox(viewer, box, clusterId);
}
++clusterId;
}

renderPointCloud(viewer,segmentCloud.second,"planeCloud",Color(0,1,0));
}

void simpleHighway(pcl::visualization::PCLVisualizer::Ptr& viewer)
{
// ----------------------------------------------------
// -----Open 3D viewer and display simple highway -----
// ----------------------------------------------------

// RENDER OPTIONS
bool renderScene = false;
bool render_box = true;
std::vector<Car> cars = initHighway(renderScene, viewer);
Lidar *lidar = new Lidar(cars, 0);
pcl::PointCloud<pcl::PointXYZ>::Ptr inputCloud = lidar->scan();
// renderRays(viewer, lidar->position, inputCloud);
// renderPointCloud(viewer, inputCloud, "inputCloud");
std::pair<pcl::PointCloud<pcl::PointXYZ>::Ptr, pcl::PointCloud<pcl::PointXYZ>::Ptr> segmentCloud =
pc_processor->SegmentPlane(inputCloud, 100, 0.2);

// renderPointCloud(viewer,segmentCloud.first,"obstCloud",Color(1,0,0));
// renderPointCloud(viewer,segmentCloud.second,"planeCloud",Color(0,1,0));

std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> cloudClusters =
pc_processor->Clustering(segmentCloud.first, 1.0, 3, 30);

int clusterId = 0;
std::vector<Color> colors = {Color(1,0,0), Color(0,1,0), Color(0,0,1)};

for(pcl::PointCloud<pcl::PointXYZ>::Ptr cluster : cloudClusters)
{
std::cout << "cluster size ";
pc_processor->numPoints(cluster);
renderPointCloud(viewer,cluster,"obstCloud"+std::to_string(clusterId),colors[clusterId]);

if(render_box)
{
Box box = pc_processor->BoundingBox(cluster);
renderBox(viewer, box, clusterId);
}
++clusterId;
}
}


//setAngle: SWITCH CAMERA ANGLE {XY, TopDown, Side, FPS}
void initCamera(CameraAngle setAngle, pcl::visualization::PCLVisualizer::Ptr& viewer)
{

viewer->setBackgroundColor (0, 0, 0);

// set camera position and angle
viewer->initCameraParameters();
// distance away in meters
int distance = 16;

switch(setAngle)
{
case XY : viewer->setCameraPosition(-distance, -distance, distance, 1, 1, 0); break;
case TopDown : viewer->setCameraPosition(0, 0, distance, 1, 0, 1); break;
case Side : viewer->setCameraPosition(0, -distance, 0, 0, 0, 1); break;
case FPS : viewer->setCameraPosition(-10, 0, 0, 0, 0, 1);
}

if(setAngle!=FPS)
viewer->addCoordinateSystem (1.0);
}


int main (int argc, char** argv)
{
std::cout << "starting enviroment" << std::endl;

pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
CameraAngle setAngle = XY;
initCamera(setAngle, viewer);
// simpleHighway(viewer);
ProcessPointClouds<pcl::PointXYZI>* pointProcessorI = new ProcessPointClouds<pcl::PointXYZI>();

std::vector<boost::filesystem::path> stream = pointProcessorI->streamPcd("../src/sensors/data/pcd/data_1");
auto streamIterator = stream.begin();
pcl::PointCloud<pcl::PointXYZI>::Ptr inputCloudI;


while (!viewer->wasStopped ())
{
// Clear viewer
viewer->removeAllPointClouds();
viewer->removeAllShapes();

// Load pcd and run obstacle detection process
inputCloudI = pointProcessorI->loadPcd((*streamIterator).string());
cityBlock(viewer, pointProcessorI, inputCloudI);

streamIterator++;
if(streamIterator == stream.end())
streamIterator = stream.begin();

viewer->spinOnce ();
}
}
Loading

0 comments on commit e46d373

Please sign in to comment.