Skip to content

Instantly share code, notes, and snippets.

@GitBubble
Last active May 2, 2019 16:30
Show Gist options
  • Save GitBubble/744c2d7ab152c57ac1244f65d6a6af72 to your computer and use it in GitHub Desktop.
Save GitBubble/744c2d7ab152c57ac1244f65d6a6af72 to your computer and use it in GitHub Desktop.
问自己的问题。

我想做什么?要解决什么问题?

为什么需要Real Time?

探月火星车,火箭和工业制造以及自动驾驶技术。他们都是和安全(safty)相关,要求在设计的时间内完成某项计算/传输任务。 这三类系统,是要求硬实时的。

硬实时: 在严格设定的时间内完成任务。超过该时间认为是系统错误。 (人命关天)
软实时: 在设定的时间内完成任务。超过该时间认为,系统服务质量出现问题。 (音视频的传输)
确定实时: 在设定的时间完成任务。超过时间认为结果是非法和不可信的。 (工业制造)

总结起来实时强调两点:

1, 时间能确定,意思是处理时间有上界。
2, 处理时间超过上界, 我们如何判定处理结果。 这点决定实时系统的分类。

从概念上判断,对于自动驾驶的某些场景(以某种速度刹车的端到端时间,传感器数据处理时间等)是需要做到 #硬实时的# 。

需要注意的是,“real time” 并不是要求系统是ultra low latency, 而要求 time 必定是 deterministic 的。 这点容易成为追求实时的误区。

ROS 1.0 不具有实时性

1, STL线程无超时参数(不能被强占),无优先级机制。

2, 运行时的内存分配/释放,导致内存的碎片化。

3, 使用有阻塞能力的系统调用: malloc,free,fopen,fread,fwrite,….

4, 使用了加锁的队列来实现多发布多订阅。

什么是Real Time Programming?

首先参考ROS2的这篇设计文档:https://index.ros.org/doc/ros2/Real-Time-Programming/

这篇介绍了real-time system: http://design.ros2.org/articles/realtime_background.html

https://answers.ros.org/question/288783/difference-in-the-delay-time-between-ros-and-ros2-for-rt-applications/

Linux下的Real-Time: http://linuxrealtime.org/index.php/Main_Page

怎么做到Real Time的系统?

做出一个real time的产品,除了需要os的调度补丁,还需要软件有一些编程策略,什么策略? 这其中有什么规范可以遵循。 如何满足性能的思考:

一个多发布多订阅的代码:
https://github.com/natsys/blog/blob/master/lockfree_rb_q.cc?from=singlemessage&isappinstalled=0
http://natsys-lab.blogspot.com/2013/05/lock-free-multi-producer-multi-consumer.html

用C++11实现的多发布多订阅代码: https://juanchopanzacpp.wordpress.com/2013/02/26/concurrent-queue-c11/

share memory with real-time:
https://www.vision.uji.es/~pla/ii75/docs/rtdocs/SharedMemory.ps

怎么实现满足ISO26262的Safty要求的软件?

我们假设现在ECU里的软件就是我们想要达到的目标。R52就是我们的一个小目标。泰山里的软件是我们的一个大目标。怎么实现这个小目标。

一个程序员应该如何看待内存,保护内存安全
https://akkadia.org/drepper/cpumemory.pdf

一个程序员如何看内核的try/catch
https://www.reddit.com/r/linux/comments/a3nwgd/trycatch_in_linux_kernel/?st=JQ0O03IF&sh=e0b56aea

QNX(ASIL-D认证,业界车载OS) RTOS上的ROS2移植消息
http://blackberry.qnx.com/en/articles/what-adas-market-needs-now

A Quick Guide to ISO26262:
https://www.feabhas.com/sites/default/files/2016-06/A%20quick%20guide%20to%20ISO%2026262%5B1%5D_0_0.pdf

业界的车载软件review :
https://dev.to/bosepchuk/is-it-ethical-to-work-on-the-tesla-autopilot-software-4lhh

怎么实现软件模块的平滑过渡?

当前使用ROS1来做通信,大量依赖rostopic,rosnode, rosparam,rosservice,rosbag,rviz,tf2_monitor,rqt 这种组件来调试。 从中间件看车载软件设计:https://info.rti.com/hubfs/whitepapers/DDS_in_Autonomous_Car_Design.pdf

如何做软件的FEMA?

翻译了Kraig Strong的一篇文章:《Using FMEA to Improve Software Reliability 》
https://gist.github.com/GitBubble/ed0f11ec1329fa7521928a1570e89a79

ECU里有多少真正在work的代码?

https://spectrum.ieee.org/transportation/systems/this-car-runs-on-code

https://ieeexplore.ieee.org/document/4142919?isnumber=4142917&arnumber=4142919&count=20&index=7&tag=1

https://insideevs.com/infographic-chevy-volt-has-10-million-lines-of-code-f-22-raptor-only-has-1-7-million/

https://dev.to/bosepchuk/is-it-ethical-to-work-on-the-tesla-autopilot-software-4lhh

https://www.visualcapitalist.com/millions-lines-of-code/

实现一个支持Real-Time系统的自动驾驶车载软件栈

1, OS 支持线程强占和优先级调度策略。(Real Time OS)

2, 使用静态内存(static memory)。

3, 有一个支持类似ROS2的通信中间件。(Real Time DDS implementation)

4, 应用程序同样遵循实时系统编程要求。

5, 使用Valgrind或LTTng确认代码没有时间过长的等待和阻塞。

6, 在指定的硬件上测试验证软件的CPU Load, 启动延时。

系统的快速启动

启动流程: http://www.c-jump.com/CIS24/Slides/Booting/Booting.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment