Virtualenv创建虚拟环境

安装:

pip install virtualenv

移动到指定文件夹目录,执行:

virtualenv {虚拟环境名}

在linux下激活虚拟环境,执行:

source {文件目录}/{虚拟环境名}/bin/activate

在windows的powershell里激活虚拟环境,执行:

.\{文件目录}\{虚拟环境名}\Scripts\activate

激活后提示符会发生变化

在linux和windows中都可以使用此命令退出虚拟环境

deactivate

fh5汽车调教笔记

胎压:

低胎压,增加抓地力(接触地面面积),太低容易过热;高胎压,减小抓地力(接触地面面积),转向零密度增高,太高容易失去抓地力。

胎压前低后高,偏转向过度(推尾);胎压前高后低,偏转向不足(推头)。

依据车重设置胎压,

<1000kg(2200lbs),设置1.5/1.5bar(21.75/21.75psi)

<1400kg(3100lbs),,设置1.8/1.8bar(26.1/26.1psi)

>1400kg(3100lbs),,设置2.0/2.0bar(29/29psi)

拉力、越野在此基础上 -0.3bar(-4.35psi),

直线加速,漂移:前胎最高后台最低,如3.8/1.0bar(55.11/14.5psi)。漂移车按习惯调整后胎胎压。

齿轮比:

看性能曲线图,看峰值扭矩和峰值马力的转速区间,这个区间是功率带power band,理想转速比如 5000rpm – 9300rpm。调整齿轮比,从第二档开始,每一档的转速起始和结束都在理想转速区间内。调整最终传动比,让车辆在马力峰值时达到最大极速。理论极速没有考虑空气下压力和只用了理想最终传动比计算得出的。起步地板油打滑,把第一档拉到偏向车速,齿轮比图上拉长。

万能齿轮比:

六速:2.89/1.99/1.49/1.18/0.97/0.81

七速:3.75/2.38/1.7/1.34/1.11/0.96/0.85

八速:3.88/2.68/2.01/1.6/1.33/1.14/1.00/0.89

轮胎定位:

外倾角:为了在弯道中外侧轮胎与地面接触面积最大化,提升抓地力

束角:外束角轻微改善转向不足,太大会让车变得不稳定,内束角让车保持直线。对于四驱和前驱这类天生转向不足的车,前轮可以加不超过0.5的外束角,后轮加不超过0.2的外束角。大马力后驱后轮加一点内束角,增加后轮稳定性。

前后倾角:初始直接最高,如果转向太灵活,再来调小。前后倾角越小,前轮就需要更多负外倾。

公路–外倾角:前-0.5,后-0.5;束角:前0.3,后0.1,前后倾角7.0

拉力/越野–外倾角:前0.0,后0.5;束角:前0.0,后0.0,前后倾角7.0

漂移–外倾角:前-5.0,后-2.0;束角:前5.0,后1.0,前后倾角7.0

直线加速–外倾角:前0.0,后0.0;束角:前0.0,后0.0,前后倾角7.0

试车反馈:

过弯时观察外侧轮胎的外倾角,理论0度是最理想,因为路面不平,过弯时有-2的外倾角都是合理的。注意不要出现正外倾。

轮胎温度,比赛中轮胎内侧温度依次高于中间和外侧温度。如果内测与外侧温差太大,超过10摄氏度,说明负外倾角过大,需要调小。

防倾杆:

前防倾杆软,后防倾杆硬,改善转向不足。弯中推尾(转向过度)调硬前防倾杆。

前驱或四驱:前1后65,提升弯中稳定性可以前10后55。后驱 前10后56

拉力/越野:前10后25, 直线加速:前65后1

弹簧:

与防倾杆相似,弹簧越软,重心转移越快。越硬,操控响应越好。太硬会失去抓地力。

前弹簧,软-转向过度,硬-转向不足

后弹簧,软-转向不足,硬-转向过度

前驱/四驱:前弹簧最软,后弹簧在2/3的位置,甚至有四驱调教是前面最软后面最硬。

后驱:前后不超过1/3,初始前弹簧可以设为80,后弹簧可以设为100,根据实际情况调整。

大马力后驱可以前后弹簧一样,设置一样最软。拉力和越野需要偏软,通常前弹簧不超过1/6,后弹簧不超过1/4,拉力常使用前软后硬提高转向,越野前后软硬通常一样。直线加速前弹簧最硬,后弹簧最软。

车身高度公路一般默认配平即可。拉力和越野前后车高都设为最高。直线加速前轮最高,后轮最低。漂移统一最低车高。

试车反馈:

悬挂系统:弹簧在静止时压缩程度在50%,如果不是很颠簸的路况下,弹簧压缩已经满了,那说明车子托底,这种情况可以调硬弹簧,调高压缩硬度,或者调高车身高度解决。一般弹簧压缩程度在5%~85%。平整路面弹簧压缩波动很大,需要把弹簧调硬,波动小,则需要调软。

阻尼:

回弹硬度:弹簧压缩之后复原的速度。压缩硬度:弹簧压缩的速度。

回弹硬度永远大于压缩硬度。理论上:压缩=回弹*(0.5 ~ 0.75)

fh5喜好较软的压缩,所以这个比值太硬了。回弹硬度在8~14之间,拉力和越野比值一般在0.25,公路一般在0.4 。 初始使用默认回弹硬度。

回弹硬度前软后硬的设置可以改善转向不足,前硬后软的设置可以改善转向过度。

前驱或四驱:一般前软后硬;直线加速:前最高后最低。

空气动力:

前下压力直接最高,后下压力越大,后轮抓地力越强,但是太大会造成转向不足。

后驱车甚至要把后下压力拉满。前驱和四驱一般前下压力最大,后下压力不超过一半。

直线加速不需要空气动力套件。

刹车:

刹车重心靠前,增加刹车时的转向过度,刹车重心靠后,增加刹车时的转向不足。通常刹车重心偏靠前。如果车本来转向就灵活,那刹车需要更多稳定性,那刹车重心就得偏后。

制动力看开不开ABS,不开ABS最好开小点或者不变,防止轮胎抱死。

差速器:

四驱有前差后差中央差速器三个板块。前驱只有前插,后去只有后叉。

0%代表差速器完全放开,两边轮子各转各的;100%代表差速器完全锁死,两个轮子转速时钟相同。前后差速器加速设置踩油门时差速器锁死的快慢,反之减速是松油门时锁死的快慢。中央差速器控制扭矩的前后分配,让车辆偏前驱或者偏后驱。

现实弯道中,我们需要内侧轮子转速小于外侧轮子,这样转向更灵活。

公路调教,前差加速20%~90%,马力大的来说偏高的前差加速会让弯中和出完更稳定。

拉力调教,前差加速30%~90%

越野调教,前差加速80%~100%

前差减速一般为0%,如果后差减速已经调高的情况下,依旧推尾(转向过度),那就要适当把前差减速调高

中央差速器:公路一般75%,拉力一般60%

前驱一般前差加速50%,减速0%,后驱一般后差加速80%,减速0%,如果是大马力后驱,适当调低后差加速,调高后差减速以增加稳定性。

后驱漂移,后差加速锁死速度100%,减速90%,锁的越死,车容易飘,把差速器焊死是一个原理。

C++中对string进行分割,寻找,长度等处理

在写C++的过程中,有的时候必须要对用户的输入进行一些处理,用户所输入的string, 可能包含了数字,单词。然而电脑只认为输入的是一串字符而已。

所以,在实战过程中,处理用户输入是很重要的。

我们既然要对string做处理,当然是要先包含了这个强大的string模块:#include <string>

using std::string; //告诉电脑我要用string

假设用户输入一个命令+空格后+第一个数字+空格+第二个数字,我们需要两个String形式的变量,一个是源输入,一个是处理后的命令string. 之后我们需要几个double或者float变量给用户所输入的数字。这边还多了一个strnum,是为了处理尚未转换成double的只包含数字的字符串用的。如果内存紧张可以直接不用。

string command, str,strnum;
double argument1, argument2, answer;
getline(cin, str);

如果要处理源输入str,必须使用getline(), 使用cin在后续就不好操作了。

int index = 0;//整数型index,用来找第一个空格
int index2 = 0;//整数型index2,用来找第二个空格

接下来就要用到string库中的find功能了。index是找到的空格的排序数字位置。比如说这句话:“hello world”,空格就在第六个,那么str.find会返回6。如果没有空格,就返回-1.
index = str.find(” “,0);
现在又要提到我们的substr功能,这是一个很好的分割字符串的工具。其实在一个字符串里截取字符方法有很多种,substr就是其中的一种而已。它的用法就是截取从第n个字母到第m种字母的字符。在以下代码中, n就是0,代表第一个字母,m就是我们上面获得的index代表空格在第几位, command = str.substr(0, index);

下面其实是一样的操作,指定从第一个空格到字符结尾都是我们要的数字。确定字符所有字母数是用length函数,非常简明的,调用它就会回归字符的长度。再就是说这个strnum可能会有两个数字,所以我们再在这个字符串里找一下有没有空格。这个方法只适用于小数量的数字上。
strnum = str.substr(index + 1, str.length());
index2 = strnum.find(” “, 0);

后面的话,我们都需要在strnum这个字符串里处理了,简单来说就是从数字的先后位置来指定数字顺序。空格前为第一个数字,空格后是第二个。这里我用了个套娃,先运行分割,再使用stod把字符转换为数字。stod应该来自“string to double”, 我记得还有stoi:”string to int”,之后还有很多,这些转换的功能,还是挺方便的。

argument1 = stod(strnum.substr(0, index2));
argument2=stod(strnum.substr(index2+1,strnum.length())

暂时就写这么多,要是有意思以后再补充。

纯粹瞎玩

将pip源更换到国内镜像

用pip管理工具安装库文件时,默认使用国外的源文件,因此在国内的下载速度会比较慢,可能只有50KB/s。幸好,国内的一些顶级科研机构已经给我们准备好了各种镜像,下载速度可达2MB/s。

其中,比较常用的国内镜像包括:

(1)阿里云http://mirrors.aliyun.com/pypi/simple/

(2)豆瓣http://pypi.douban.com/simple/

(3)清华大学https://pypi.tuna.tsinghua.edu.cn/simple/

(4)中国科学技术大学http://pypi.mirrors.ustc.edu.cn/simple/

设置方法:(以清华镜像为例,其它镜像同理)

(1)临时使用:

可以在使用pip的时候,加上参数-i和镜像地址(如

https://pypi.tuna.tsinghua.edu.cn/simple/

例如:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simpleopencv-contrib-python

这样就会从清华镜像安装opencv-contrib-python库。

(2)永久修改,一劳永逸:

windows下,直接在user\xxx目录中创建一个pip目录,如:C:\Users\xx\pip,然后新建文件pip.in

在pip.ini文件中输入以下内容

[global]

index-url = https://pypi.tuna.tsinghua.edu.cn/simple/

[index]

在linux下,

一般要修改配置文件:~/.config/pip/pip.conf (Linux), (没有就创建一个), 将 index-url改成至tuna,例如
在.config文件夹中创建pip/pip.conf

在pip.conf文件中添加清华大学的pypi镜像,要是想用其他的镜像,替换成相应的地址即可。

[global]


index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Ubuntu换国内的软件源

ubuntu系统现在一般都会自带中国的软件仓库,但是如果你的ubuntu系统再国内下载很慢,考虑以下操作。

首先备份源列表文件sources.list:

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup

再打开现有sources.list

sudo gedit /etc/apt/sources.list

编辑/etc/apt/sources.list文件, 在文件最前面添加阿里云镜像源:

#阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

还有一些其他的国内源:

#中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#163源
deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

#清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

加完以后刷新列表:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential

如果还是速度慢,去应用软件里找:软件和更新,仔细在检查一下这些源有没有被确认了。

Easy Opencv deployment on raspberry pi

What we need in this deployment is a raspberry pi, a pi camera, if you have a screen for raspberry pi it will be better. We also need an internet connection for modules!

Set up our raspbian in raspberry pi. It is very easy to write an image in your sd card, by using “raspberry pi imager“. This is much more convenient than downloading the image by yourself and write using other software.

if you don’t have a screen or ethernet connection for our raspberry pi, it is necessary to set up a wifi connection before we start up the system. Go to the boot direction in this raspbian SD card, create a file named as “wpa_supplicant.conf“, copy the code below into this .conf file:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid=”WiFi SSID”
psk=”WiFi PASSWORD”
}

Replace Wifi SSID and Wifi password in the code, then you are good to go.

Boot up the raspberry pi and connect the pi camera to it, find the IP address of raspberry pi on your computer. Using ssh to connect Raspberry pi. For the first time startup on pi, the username should be pi, and the password should be raspberry.

SSH on windows has the various options, shell and putty are both great software and easy to setup. On Linux is easier, the command will just be:

ssh 192.168.xx.xx@pi

Now we are ready to move on installing OpenCV! Don’t forget to run these two commands every time!

sudo apt-get update

sudo apt-get upgrade

remove the software we don’t need, but it’s optional:

$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove

Then we can setup our camera and expand file system on this command: sudo raspi-config Camera option is in 5Interfacing options, expand file system is in 7Advance options.

We can take a reboot right now by :sudo reboot. After rebooting, we can use the command: df -h to check the system size.

Usually, in the raspbian system, the python2 and python3 is preinstalled. But we need the module pip in our system. Command: wget https://bootstrap.pypa.io/get-pip.py

Then open this py file: sudo python3 get-pip.py

We want to use python3 instead of python2. After this command, pip3 should be a command in the shell.

Finally, it is time to install our OpenCV module! There are two ways to install, we will take an easy way by using pip. We can also use source code to build, but it will take over 2 hours to finish. Using pip will be much faster. Commands are below:

pip install opencv-python

pip install opencv-contrib-python

Haha, if there is no error message show, Opencv is now installed in our raspberry pi! But don’t get excited too soon my brother, let’s using python3 to check again.

Type python3 in console, then type “import cv2“, hit enter. If still no error message, type “cv2.__version__“. When you see your OpenCV version, congratulations! You finally installed your OpenCV successfully!

Follow these steps, we can also install OpenCV on our Linux and Windows computers, they are basically the same.

Now enjoy and have some random fun!

Ubuntu下搭建STC单片机开发环境

首先安装sdcc,全称Small Device C Compiler,是一个转为8位MCU设计的C编译器。sdcc如同gcc,可以把C源码编译、链接成单片机的可执行文件。安装方法是:

sudo apt install sdcc
当然,也可以从源码编译安装,具体可以查看sdcc官网。

使用如下命令编译和链接:sdcc main.c


sdcc也可以像gcc那样使用-c参数指定只编译、不链接等等。

命令执行后,会看到目录下产生了一堆main.*文件,其中有一个main.ihx就是我们要的文件。

在安装sdcc时自动安装了packihx这个工具,能把ihx文件转为hex文件:packihx main.ihx > main.hex

接下来就是下载了,需要zhuang一个模组:stcgal

sudo pip3 install stcgal
如果之前没有安装过pip3的话,需要先安装pip3:

sudo apt install python3-pip
可以正式开始烧录了。把USB-TTL插入电脑,应该会出现/dev/ttyUSB0(如果有多个,那么找到对应那个)。然后执行命令:

sudo stcgal main.hex
此时会出现“Waiting for MCU, please cycle power:”,然后需要重新插拔一下单片机电源,然后就会开始下载:

stcgal可以额外配置很多的参数。比如STC12C2052这款单片机,可以选择使用内部RC震荡器还是外部时钟源。那么在烧录时可以带上这些配置,比如:

sudo stcgal -o clock_source=internal main.hex
具体参数可以查看。

另外我发现,stcgal是可以直接下载ihx格式的文件的。

Win和linux系统中环境变量

最近在用pyinstaller编译python时,无论怎么召唤pyinstaller,命令行都不识别。结果发现是Python的第三方模组没有加进系统的环境变量。这个问题在windows和ubuntu上都发现了。

windows中修改环境变量超容易,控制面板里修改环境变量就行,linux里也只要修改./bashrc文件,在最后一行加上你的要的路径,像是:export PATH=$PATH:/xxx/xxx  ///xxx/xxx (等号两边没空格),退出来后source .bashrc生效然后echo $PATH查看一下以防外一。

但是这个python第三方模组的路径我找了好久,现在终于想到有一个简单方法:在python里import numpy,在输入numpy.__file__就会自动输出Numpy所在的路径了,linux和win通用。当然如果没有装numpy就看看其他有没有可以import的模组,原理是一样的。

在安装ros2时也发现命令行写ros2没反应。同样也是./bashrc改一下。遇到这个问题的时候我一下子就反应过来了。

我以前用的是zsh,据说也有zshrc,但是太烦了,zsh感觉没啥用,删了。