1. 重烧镜像
参照上一个贴子操作
镜像地址:
链接: https://pan.baidu.com/s/1roXNRNPnhH5S7uVqFkEwng?pwd=8k6t
提取码: 8k6t
Ubuntu-20.04.4-LTS-5.18
2. 更改两个配置
1、resize2fs根文件系统
$ sudo resize2fs /dev/system
2、串口终端输入,需修改console为ttyAML0,完整命令如下(Ctrl+C进入uboot后修改环境变量)
$ setenv initargs 'rootfstype=ext4 rw root=/dev/mmcblk0p16 init=/sbin/init console=ttyAML0,115200 no_console_suspend earlycon=meson,0xff803000 ramoops.pstore_en=1 ramoops.record_size=0x8000 ramoops.console_size=0x4000 skip_initramfs'
$ save
3. 硬件连接
4. 部分软件代码
uint8_t FormaldehydeUart::check_sum(uint8_t *data, uint8_t len)
{
uint8_t tmp = 0;
for(int j = 1; j < len - 1; j++)
{
tmp += data[j];
}
return (~tmp + 1);
}
bool FormaldehydeUart::is_check_sum(uint8_t *data, uint8_t len)
{
if(check_sum(data, len) == data[len - 1])
{
return true;
}
return false;
}
void FormaldehydeUart::update(void)
{
ros::Rate r(5);
while (ros::ok())
{
if (serial_->isOpen())
{
uint8_t read_buffer[read_buffer_size];
size_t n = serial_->available();
if ( n != 0)
{
serial_->read(read_buffer, read_buffer_size);
if(!is_check_sum(read_buffer, read_buffer_size))
{
continue;
}
uint16_t formaldehyde;
formaldehyde = ((uint16_t)read_buffer[4] << 8)| read_buffer[5];
std_msgs::Float64 msg;
msg.data = (double)formaldehyde/1000.0;
formaldehyde_pub_.publish(msg);
}
}
else
{
int max_count = output_hz_ * 5;
open_count_++;
if (open_count_ >= max_count)
{
open_count_ = 0;
try
{
serial_->open();
}
catch (std::exception &e)
{
ROS_WARN("open serial port failed");
}
}
}
updateDiagnostics();
r.sleep();
}
}
5. 启动ROS
$ roscore
$ rosrun
6. 获取甲醛值
d09519e801699d5fc3d66aab9fd948ba
|