Multiple Publishers and Subscribers in ROS
Regularly, it is necessary to subscribe different topic messages and publish one or more messages in one ROS node. Therefore,
we need to design a node which owns several publishers and/or subscribers. Sometimes we will even use multi-thread methods in C++.
Python
The following codes shows how to subscribe a topic message and publish another topic message in one node. This method utilizes reponsion mechanism, it will publish a message after it receive a topic message and finish dealing with it.
1 ...
Ackermann Geometrics and Pure Pursuit Algorithm
Ackermann Geometrics
如下图,车辆以固定的方向盘转角转弯时,实质为绕圆心在后轴延长线上,半径为 rrr 的圆弧做圆周运动。
根据图内关系,可以推算出车辆前轴偏转角与圆心半径 rrr 的关系, LLL为车辆轴距。
δ=arctan(Lr)\delta = arctan(\frac{L}{r})
δ=arctan(rL)
Pure Pursuit Algorithm
Pure Pursuit Algorithm 是一种车辆跟踪的简单算法,具体方法为根据车辆当前点与一系列的waypoints,与当前车辆距离合适的一个目标点,计算车辆从当前位置驾驶到目标点位置的期望轮胎转角。
由上图,以车辆后轴为圆心建立车辆坐标系,经过几何运算可以得到车辆圆周运动的圆弧曲率 κ\kappaκ 与目标点位置的关系。
d=r−x(r−x)2+y2=r2r2−2rx+x2+y2=r22rx=l2r=l22xκ=2xl2d = r-x \\
(r-x)^2 + y^2 = r^2 \\
r^2 - 2rx + x^2 + y^2 = r^2 \\
2rx = l^2 \\
r = \frac ...
Use Customed Python Environment in ROS
Install Denpendent Packages
In ROS, if we use our special python environment under conda or virtualenv instead of the basic python environment,
there will be something wrong when we use ROS package. This is because ROS packages cannot be found in our special environment.
In order to resolve this problem, we need to install ROS packages in our python enviornment. Open a terminal and enter the following codes to install ROS dependencies.
123$ conda activate yourEnv$ pip install catkin-tools$ pip i ...
data-visualization-through-matplotlib-1
Line Chart
In order to show data dyanmically, it’s necessary to use interactive mode of matplotlib. The following codes show a sine line dynamically.
1234567891011121314151617181920212223import matplotlib.pyplot as pltimport numpy as npimport timefrom math import *count = 0time_list = []data_list = []def main(): plt.ion() # Use interactive mode plt.figure(1) for:i range(2000): plt.clf() # clear the canvas time_list.append(0.1 * i) data_list.append(sin(0.1 * i)) ...
Compute Distance and Angle between Two GPS Points
背景知识
经纬线的产生与定义
地球是一个椭球体,其赤道半径要比极半径更大。赤道半径 a=6378.1730kma = 6378.1730 kma=6378.1730km , 极半径 b=6356.7523kmb = 6356.7523 kmb=6356.7523km ,平均半径 R=2a+b3=6371.0088kmR = \frac{2a+b}{3} = 6371.0088kmR=32a+b=6371.0088km 。
经纬线则是人们为了清晰表达地球上任意一点而定义出来的辅助线。
纬线定义为地球表面某点随地球自转而形成的轨迹,因此纬线与赤道平行,其周长等于赤道的周长乘以纬线的维度的余弦。
经线定义为地球表面连接南北两极点的半圆弧,任意两经线长度相等,L=20003.93kmL = 20003.93kmL=20003.93km。
经纬度的定义
经度:已知经线是连接两极点的圆弧,那么地球上任意一点的经度坐标等于:该点所在经线与地球圆心组成的平面与本初子五线平面的夹角的度数。
纬度:已知纬线是与赤道平行的圆弧,因此地球上任意一点的维度坐标等于:该点与球心连接的线段和投影在赤道平面组成的 ...
Internal Netwrok Penetration
Dependencies
A computer in internal network environment
A server in public network environment(Own a public IP address)
A personal computer
Principle
Personal computer --> Public Server --> Interal computer
Procedure
Open the 8086 port in of Public server. In Security Group, add a Custom TCP Rule(Protocol: TCP, Port: 8086)
Open a terminal in Public server, and import the following commands.12345sudo vim /etc/ssh/ssh_config# Add the following line in itGatewayPorts yes# Import the follow ...
Ros Qt Install and Configuration on Ubuntu
Download and Install
Dependencies:
Qt depends on C/C++. Meanwhile, Qt’s 3D interface depends on OpenGL lib. Therefore, gcc/g++ complier and OpenGL lib are required. Open a terminal and enter the following commands so that these dependencies will be installed.
12$ sudo apt-get install mesa-common-dev$ sudo apt-get install ligblul-mesa-dev -y
Download:
Download the .run file in your required version.
Official download link
Mirror download link
Install:
Go into the download folder, open a t ...
Two Classes Call each other (C++)
两个对象互相访问成员函数及成员变量
头文件
父类的头文件应当 include 子类的头文件,同时声明指向子类的指针。
Parent.h
12345678910111213#include "Son.h"class Parent{public: Parent(); ~Parent(); Son* sonPtr; // 声明指向子对象的指针public: int a;}
在C++中,如果两个头文件互相调用,将会发生循环检测引用的编译错误。为了避免编译错误,在子类的头文件中,不应该 include 父类的头文件,而是直接声明父类。
Son.h
1234567891011121314class Parent;class Son{public: Son(Parent* ptr); ~Son(); Parent* parentPtr; // 声明指向父类的指针public: int getParentA(); // 声明获取父类成员变量的函数}
源文件
父类的源文件应当包含其自 ...