安装流程
安装环境:ubuntu20.04,python=3.7
参考https://www.bilibili.com/video/BV1kq4y1n7Ju/?spm_id_from=333.1007.top_right_bar_window_default_collection.content.click&vd_source=3b1dadea8ca9691e050b12f5305b8a3b
报错1
lcm
make报错:
lcm/lcm-python/module.c:1:10: fatal error: Python.h: 没有那个文件或目录
1 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
make[2]: *** [lcm-python/CMakeFiles/lcm-python.dir/build.make:63:lcm-python/CMakeFiles/lcm-python.dir/module.c.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:862:lcm-python/CMakeFiles/lcm-python.dir/all] 错误 2
make: *** [Makefile:163:all] 错误 2
原因:
lcm-python/CMakeLists.txt 中的代码
find_package(Python3 COMPONENTS Interpreter Development.Module)
target_include_directories(lcm-python PRIVATE
${Python3_INCLUDE_DIRS}
)
无法找到python头文件路径
解决方法:
运行:
python3 -c “from sysconfig import get_paths; print(get_paths()[‘include’])”
可以找到python头文件路径,将lcm-python/CMakeLists.txt 中的以上代码更改为:
find_package(Python3 COMPONENTS Interpreter Development.Module)
if (NOT Python3_INCLUDE_DIRS)
set(Python3_INCLUDE_DIRS “/usr/include/python3.8(替换为自己的python头文件路径)”)
endif()
target_include_directories(lcm-python PRIVATE ${Python3_INCLUDE_DIRS})
报错2
Cheetah-Software
make -j4报错:
Built target test-common
make: *** [Makefile:130:all] 错误 2
其并没有详细显示所有错误,改用make -j1 VERBOSE=1命令,报错:
Cheetah-Software/robot/src/SimulationBridge.cpp:7:
In function ‘char* strncpy(char*, const char*, size_t)’,
inlined from ‘void SimulationBridge::run()’ at /home/j/Cheetah-Software/robot/src/SimulationBridge.cpp:73:12:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ specified bound 2056 equals destination size [-Werror=stringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
解决方法:
将Cheetah-Software/robot/src/SimulationBridge.cpp中以下代码:
catch (std::exception& e) {
strncpy(_sharedMemory().robotToSim.errorMessage, e.what(), sizeof(_sharedMemory().robotToSim.errorMessage));
_sharedMemory().robotToSim.errorMessage[sizeof(_sharedMemory().robotToSim.errorMessage) - 1] = ‘\0’;
throw e;
}
更改为:
catch (std::exception& e) {
std::string errorMessage = e.what();
size_t copySize = std::min(errorMessage.size(), sizeof(_sharedMemory().robotToSim.errorMessage) - 1);
strncpy(_sharedMemory().robotToSim.errorMessage, errorMessage.c_str(), copySize);
_sharedMemory().robotToSim.errorMessage[copySize] = ‘\0’;
throw e;
}
报错3
Cheetah-Software
继续运行make -j1 VERBOSE=1报错:
Cheetah-Software/robot/src/rt/rt_serial.cpp:24:10: fatal error: stropts.h: 没有那个文件或目录
24 | #include <stropts.h>
| ^~~~~~~~~~~
compilation terminated.
表明在编译过程中,<stropts.h> 头文件没有找到
创建stropts.h文件,写入如下代码:
#if HAVE_STROPTS_H
#include <stropts.h>
#endif
把stropts.h文件移动到/usr/include中(或者anaconda/envs/xxx/include中?不确定可以都复制一份)
报错4
Cheetah-Software
继续运行make -j1 VERBOSE=1报错:
Cheetah-Software/robot/src/rt/rt_serial.cpp: In function ‘void init_serial_for_sbus(int, int)’:
/home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:34:3: error: ‘ioctl’ was not declared in this scope
34 | ioctl(fd, TCGETS2, &tty);
| ^~~~~
/home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp: In function ‘int set_interface_attribs_custom_baud(int, int, int, int)’:
/home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:89:3: error: ‘ioctl’ was not declared in this scope
89 | ioctl(fd, TCGETS2, &tty);
| ^~~~~
在Cheetah-Software/robot/src/rt/rt_serial.cpp文件中添加了以下依赖项:
#include <sys/ioctl.h>
继续报错:
In file included from /usr/include/x86_64-linux-gnu/asm/termios.h:1,
from /home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:18:
/usr/include/asm-generic/termios.h:15:8: error: redefinition of ‘struct winsize’
15 | struct winsize {
| ^~~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/ioctl.h:29,
from /home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:9:
/usr/include/x86_64-linux-gnu/bits/ioctl-types.h:27:8: note: previous definition of ‘struct winsize’
27 | struct winsize
| ^~~~~~~
In file included from /usr/include/x86_64-linux-gnu/asm/termios.h:1,
from /home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:18:
/usr/include/asm-generic/termios.h:23:8: error: redefinition of ‘struct termio’
23 | struct termio {
| ^~~~~~
In file included from /usr/include/x86_64-linux-gnu/sys/ioctl.h:29,
from /home/j/Cheetah-Software/robot/src/rt/rt_serial.cpp:9:
/usr/include/x86_64-linux-gnu/bits/ioctl-types.h:36:8: note: previous definition of ‘struct termio’
36 | struct termio
| ^~~~~~
将整个文件的依赖改成如下格式:
#ifdef linux
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define termios asmtermios
#undef termios
#include <termios.h>
#include <math.h>
#include <pthread.h>
#include <stropts.h>
#include <endian.h>
#include <stdint.h>
#include “rt/rt_serial.h”
继续报错,并报了很多次错,崩溃中。。。
最终将整个Cheetah-Software/robot/src/rt/rt_serial.cpp文件修改为如下内容:
#define BOTHER 0010000
#ifdef linux
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <math.h>
#include <pthread.h>
#include <stropts.h>
#include <endian.h>
#include <stdint.h>
#include “rt/rt_serial.h”
void init_serial_for_sbus(int fd, int baud) {
printf(“\t[RT SERIAL] Configuring serial device…\n”);
struct termios tty;
ioctl(fd, TCGETS, &tty);
tty.c_cflag &= ~CBAUD;
tty.c_cflag |= BOTHER;
tty.c_ispeed = baud;
tty.c_ospeed = baud;
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
tty.c_oflag &= ~OPOST;
tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
tty.c_cflag &= ~(CSIZE | PARENB);
tty.c_cflag |= PARENB;
tty.c_cflag &= ~PARODD;
tty.c_cflag |=
tty.c_cflag |= CS8;
// tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
// tty.c_iflag &= ~IGNBRK; // disable break processing
// tty.c_lflag = 0; // no signaling chars, no echo,
// // no canonical processing
// tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 1; // read doesn’t block
tty.c_cc[VTIME] = 1; // 0.5 seconds read timeout
// tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
// tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,
// // enable reading
// // tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
// tty.c_cflag |= PARENB;
// tty.c_cflag &= ~CSTOPB;
// tty.c_cflag &= ~CRTSCTS;
// cfmakeraw(&tty);
ioctl(fd, TCSETS, &tty);
}
int set_interface_attribs_custom_baud(int fd, int speed, int parity, int port) {
(void)parity;
(void)port;
printf(“\t[RT SERIAL] Configuring serial device…\n”);
struct termios tty;
ioctl(fd, TCGETS, &tty);
tty.c_cflag &= ~CBAUD;
tty.c_cflag |= BOTHER;
tty.c_ispeed = speed;
tty.c_ospeed = speed;
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~IGNBRK; // disable break processing
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn’t block
tty.c_cc[VTIME] = 1; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls,
// enable reading
// tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= PARENB;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
// cfmakeraw(&tty);
ioctl(fd, TCSETS, &tty);
return 0;
}
#endif
再运行make -j1 VERBOSE=1一次通过。
测试
在Cheetah-Software/build/下输入
./sim/sim
在界面中选择
Mini Cheetah
Simulator
点击 start
另开一个终端在Cheetah-Software/build/下输入
./user/MIT_Controller/mit_ctrl m s
即可实现四足仿真