Day: November 5, 2020
Predcition
Implement Practical Filter
Particle Filter Algorithm Steps and Inputs
The flowchart below represents the steps of the particle filter algorithm as well as its inputs.

Particle Filter Algorithm Flowchart
Psuedo Code
This is an outline of steps you will need to take with your code in order to implement a particle filter for localizing an autonomous vehicle. The pseudo code steps correspond to the steps in the algorithm flow chart, initialization, prediction, particle weight updates, and resampling. Python implementation of these steps was covered in the previous lesson.

Initialization
At the initialization step we estimate our position from GPS input. The subsequent steps in the process will refine this estimate to localize our vehicle.

Prediction
During the prediction step we add the control input (yaw rate & velocity) for all particles

Update
During the update step, we update our particle weights using map landmark positions and feature measurements.

Resampling
During resampling we will resample M times (M is range of 0 to length_of_particleArray) drawing a particle i (i is the particle index) proportional to its weight . Sebastian covered one implementation of this in his discussion and implementation of a resampling wheel.

Return New Particle Set
The new set of particles represents the Bayes filter posterior probability. We now have a refined estimate of the vehicles position based on input evidence.
Practical Filter
Motion Model
What is Localization?
Docker Container
Docker là gì ? Kiến thức cơ bản về Docker
Docker là gì ? Kiến thức cơ bản về Docker

I. Tại sao phải dùng Docker ?
Việc setup và deploy application lên một hoặc nhiều server rất vất vả từ việc phải cài đặt các công cụ, môi trường cần cho application đến việc chạy được ứng dụng chưa kể việc không đồng nhất giữa các môi trường trên nhiều server khác nhau. Chính vì lý do đó Docker được ra đời để giải quyết vấn đề này.
II. Docker là gì ?
Docker là một nền tảng cho developers và sysadmin để develop, deploy và run application với container. Nó cho phép tạo các môi trường độc lập và tách biệt để khởi chạy và phát triển ứng dụng và môi trường này được gọi là container. Khi cần deploy lên bất kỳ server nào chỉ cần run container của Docker thì application của bạn sẽ được khởi chạy ngay lập tức.
III. Lợi ích của Docker
- Không như máy ảo Docker start và stop chỉ trong vài giây.
- Bạn có thể khởi chạy container trên mỗi hệ thống mà bạn muốn.
- Container có thể build và loại bỏ nhanh hơn máy ảo.
- Dễ dàng thiết lập môi trường làm việc. Chỉ cần config 1 lần duy nhất và không bao giờ phải cài đặt lại các dependencies. Nếu bạn thay đổi máy hoặc có người mới tham gia vào project thì bạn chỉ cần lấy config đó và đưa cho họ.
- Nó giữ cho word-space của bạn sạch sẽ hơn khi bạn xóa môi trường mà ảnh hưởng đến các phần khác.
IV. Cài đặt
Link download: tại đây
Chọn bản cài đặt tương ứng với hệ điều hành của bạn và tiến hành cài đặt theo hướng dẫn đối với Linux còn Windows và MacOS thì bạn chỉ cần tải bản cài về và cài đặt như mọi application khác.
Sau khi cài đặt xong để kiểm tra xem cài đặt thành công hay không ?
- Mở command line:
$ docker version$ docker info$ docker run hello-world
V. Một số khái niệm

- Docker Client: là cách mà bạn tương tác với docker thông qua command trong terminal. Docker Client sẽ sử dụng API gửi lệnh tới Docker Daemon.
- Docker Daemon: là server Docker cho yêu cầu từ Docker API. Nó quản lý images, containers, networks và volume.
- Docker Volumes: là cách tốt nhất để lưu trữ dữ liệu liên tục cho việc sử dụng và tạo apps.
- Docker Registry: là nơi lưu trữ riêng của Docker Images. Images được push vào registry và client sẽ pull images từ registry. Có thể sử dụng registry của riêng bạn hoặc registry của nhà cung cấp như : AWS, Google Cloud, Microsoft Azure.
- Docker Hub: là Registry lớn nhất của Docker Images ( mặc định). Có thể tìm thấy images và lưu trữ images của riêng bạn trên Docker Hub ( miễn phí).
- Docker Repository: là tập hợp các Docker Images cùng tên nhưng khác tags. VD: golang:1.11-alpine.
- Docker Networking: cho phép kết nối các container lại với nhau. Kết nối này có thể trên 1 host hoặc nhiều host.
- Docker Compose: là công cụ cho phép run app với nhiều Docker containers 1 cách dễ dàng hơn. Docker Compose cho phép bạn config các command trong file docker-compose.yml để sử dụng lại. Có sẵn khi cài Docker.
- Docker Swarm: để phối hợp triển khai container.
- Docker Services: là các containers trong production. 1 service chỉ run 1 image nhưng nó mã hoá cách thức để run image — sử dụng port nào, bao nhiêu bản sao container run để service có hiệu năng cần thiết và ngay lập tức.
VI. Dockerfile
– Dockerfile là file config cho Docker để build ra image. Nó dùng một image cơ bản để xây dựng lớp image ban đầu. Một số image cơ bản: python, unbutu and alpine. Sau đó nếu có các lớp bổ sung thì nó được xếp chồng lên lớp cơ bản. Cuối cùng một lớp mỏng có thể được xếp chồng lên nhau trên các lớp khác trước đó.
– Các config :
- FROM — chỉ định image gốc: python, unbutu, alpine…
- LABEL — cung cấp metadata cho image. Có thể sử dụng để add thông tin maintainer. Để xem các label của images, dùng lệnh
docker inspect
. - ENV — thiết lập một biến môi trường.
- RUN — Có thể tạo một lệnh khi build image. Được sử dụng để cài đặt các package vào container.
- COPY — Sao chép các file và thư mục vào container.
- ADD — Sao chép các file và thư mục vào container.
- CMD — Cung cấp một lệnh và đối số cho container thực thi. Các tham số có thể được ghi đè và chỉ có một CMD.
- WORKDIR — Thiết lập thư mục đang làm việc cho các chỉ thị khác như: RUN, CMD, ENTRYPOINT, COPY, ADD,…
- ARG — Định nghĩa giá trị biến được dùng trong lúc build image.
- ENTRYPOINT — cung cấp lệnh và đối số cho một container thực thi.
- EXPOSE — khai báo port lắng nghe của image.
- VOLUME — tạo một điểm gắn thư mục để truy cập và lưu trữ data.
VII. Tạo Demo
Tạo file Dockerfile
FROM golang:1.11 AS builderWORKDIR /go/src/docker-demo/COPY . .RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o docker-demo .FROM alpine:latestWORKDIR /root/COPY — from=builder /go/src/docker-demo .CMD [“./docker-demo”]
Tạo file main.go
package mainimport ( “fmt”)func main() { fmt.Println(“Learning Docker”)}
Tiến hành build file Dockerfile
$ docker build .

$ docker run 4cc010d9d657

Kết quả in ra dòng chữ Learning Docker đã được code trong file main.go
VII. Các lênh cơ bản trong docker
- List image/container:
$ docker image/container ls
- Delete image/container:
$ docker image/container rm <tên image/container >
- Delete all image hiện có:
$ docker image rm $(docker images –a –q)
- List all container hiện có:
$ docker ps –a
- Stop a container cụ thể:
$ docker stop <tên container>
- Run container từ image và thay đổi tên container:
$ docker run –name <tên container> <tên image>
- Stop all container:
$ docker stop $(docker ps –a –q)
- Delete all container hiện có:
$ docker rm $(docker ps –a –q)
- Show log a container:
$ docker logs <tên container>
- Build một image từ container:
$ docker build -t <tên container> .
- Tạo một container chạy ngầm:
$ docker run -d <tên image>
- Tải một image trên docker hub:
$ docker pull <tên image>
- Start một container:
$ docker start <tên container>
Bash Script
Đặt vấn đề
Có bao giờ bạn cảm thấy mất thời gian và công sức khi cứ phải lặp lại thao tác gõ những lệnh dài dòng và khó nhớ trên Terminal . Và bạn muốn viết những câu lệnh đó ở một chỗ nào đó và sau chỉ cần lấy ra chạy
Giải pháp cho bạn là hãy viết một file script ( file .sh trên mồi trường linux và .bat trên môi trường window ) chỉ cần viết 1 lần và có thể chạy bất kỳ khi nào
1) Cấu trúc file bash
Dòng đâu tiên và bắt buộc với một file bash với đuôi mở rộng là .sh ( trên Linux ) hoặc .bat trên Window ) là câu lệnh này
#!/bin/bash#
// tiếp theo là những câu lệnh thực thi
VD : myscript.sh
#!/bin/bash
echo Hello
// in ra màn hình terminal chứ Hello
Để run file này đơn giản trên màn hình terminal chỉ cần chạy ./myscript.sh
2) Các biến trong file bash
Có 2 kiểu biến trong file bash
- Setting a value for a variable.
- Reading the value for a variable.
Đơn giản khi chúng ta cần tham chiều và để đọc giá trị của biên đó thì ta dùng Reading the value với cú pháp thêm dấu $ trước tên biến Khi chúng ta muốn gán giá trị cho biến thì ta dùng Setting a value chỉ cần bỏ dấu $ đằng trước đi là được
Một số biến của hệ thống như :
$0- Tên của file Bash script.
$1 - $9 - lần lượt là các đối số truyền vào cho file Bash script.
$# - Số lượng các arguments chúng ta truyền vào cho file the Bash script.
$@ - Tất cả các đối số cung cấp cho file Bash script.
$? - Trạng thái của câu lệnh thực hiện gần nhất ( 0 -> true , 1 -> false )
$$ - ID của script hiện tại .
VD :
#!/bin/bash
arg=$1
echo arguments1 = $arg
Run file : ./myscript.sh 123 với 123 là giá trị argument truyền vào
màn hình sẽ in ra kết quả như sau :
nambd@nambd-HP:~/Desktop$ bash ./myscipt.sh 123
arguments1 = 123
3) Input trong file bash
Như ví dụ bên trên mình đang truyển giá trị theo kiểu Command line arguments
Một cách khác là mình sẽ dùng cách Ask the User for Input
Cú pháp :
read value
VD :
nambd@nambd-HP:~/Desktop$ bash ./myscipt.sh
Enter your name :
Hihi
Your name is Hihi
Một số option
-p : thêm dấu nhắc nhập lệnh -s : ẩn đi giá trị bạn nhập
#!/bin/bash
read -p 'Username: ' uservar
read -sp 'Password: ' passvar
echo Username : $uservar Password : $passvar
Khi bạn muốn nhập nhiều gía trị :
read var1 var2 var3
4) If , If else Statements
Cậu lệnh điều kiện
Cú pháp
if [ <some test> ]
then
<commands>
else
<other commands>
fi
VD :
#!/bin/bash
if [ $# -eq 1 ] // kiêm tra số lượng các argument
then
nl $1
else
//some action
fi
Hoặc câu lệnh elif
if [ <some test> ]
then
<commands>
elif [ <some test> ]
then
<different commands>
else
<other commands>
fi
VD :
#!/bin/bash
if [ $1 -ge 18 ]
then
echo You may go to the party.
elif [ $2 == 'yes' ]
then
echo You may go to the party but be back before midnight.
else
echo You may not go to the party.
fi
Boolean Operations gồm có
- and – &&
- or – ||
VD
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi
5) Case Statements
Cú pháp :
case <variable> in
<pattern 1>)
<commands>
;;
<pattern 2>)
<other commands>
;;
esac
VD :
#!/bin/bash
case $1 in
start)
echo starting
;;
stop)
echo stoping
;;
restart)
echo restarting
;;
*)
echo don\'t know
;;
esac
Tổng kết
Ok .Chăc chỉ cần như này là các bạn đã có thể áp dụng để chạy nhiều câu lệnh trên terminal dung bash script rồi Phần này mình xin dừng lại ở đây , phần tiếp theo mình sẽ giới thiệu về vòng lắp và function trong Bash Script
Python
C++
C++ is a general-purpose programming language that was developed as an enhancement of the C language to include object-oriented paradigm. It is an imperative and a compiled language.

C++ is a middle-level language rendering it the advantage of programming low-level (drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.). The basic syntax and code structure of both C and C++ are the same.
Some of the features & key-points to note about the programming language are as follows:
- Simple: It is a simple language in the sense that programs can be broken down into logical units and parts, has a rich libray support and a variety of data-types.
- Machine Independent but Platform Dependent: A C++ executable is not platform-independent (compiled programs on Linux won’t run on Windows), however they are machine independent.
- Mid-level language: It is a mid-level language as we can do both systems-programming (drivers, kernels, networking etc.) and build large-scale user applications (Media Players, Photoshop, Game Engines etc.)
- Rich library support: Has a rich library support (Both standard ~ built-in data structures, algorithms etc.) as well 3rd party libraries (e.g. Boost libraries) for fast and rapid development.
- Speed of execution: C++ programs excel in execution speed. Since, it is a compiled language, and also hugely procedural. Newer languages have extra in-built default features such as grabage-collection, dynamic typing etc. which slow the execution of the program overall. Since there is no additional processing overhead like this in C++, it is blazing fast.
- Pointer and direct Memory-Access: C++ provides pointer support which aids users to directly manipulate storage address. This helps in doing low-level programming (where one might need to have explicit control on the storage of variables).
- Object-Oriented: One of the strongest points of the language which sets it apart from C. Object-Oriented support helps C++ to make maintainable and extensible programs. i.e. Large-scale applications can be built. Procedural code becomes difficult to maintain as code-size grows.
- Compiled Language: C++ is a compiled language, contributing to its speed.
Applications of C++:
C++ finds varied usage in applications such as:
- Operating Systems & Systems Programming. e.g. Linux-based OS (Ubuntu etc.)
- Browsers (Chrome & Firefox)
- Graphics & Game engines (Photoshop, Blender, Unreal-Engine)
- Database Engines (MySQL, MongoDB, Redis etc.)
- Cloud/Distributed Systems
Some interesting facts about C++:
Here are some awesome facts about C++ that may interest you:
- The name of C++ signifies the evolutionary nature of the changes from C. “++” is the C increment operator.
- C++ is one of the predominant languages for the development of all kind of technical and commercial software.
- C++ introduces Object-Oriented Programming, not present in C. Like other things, C++ supports the four primary features of OOP: encapsulation, polymorphism, abstraction, and inheritance.
- C++ got the OOP features from Simula67 Programming language.
- A function is a minimum requirement for a C++ program to run.(at least main() function)
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.