Serious Autonomous Vehicles


  • Home

  • Archives

  • Tags

  • Search

reactjs introduction

Posted on 2019-08-30 |

React is the front-end framework used in lg-sim WebUI(version 2019.07). as well for Cruise webviz, Uber visualization, Apollo, they all choose a web UI design, there is something great about web framework.

what is React

used to build complex UI from small and isolated pieces of code “components”

1
2
3
4
5
6
7
class vehicleManager extends React.Component {
render()
{
return <html></html>
}
}

React will render the html on screen, and any changes in data will update and rerender. render() returns a description(React element) of what you want to see on the screen, React takes the descriptions and displays the result.

build a react hello-world app

1
2
3
4
5
npx create-react-app react-demo
cd react-demo
npm start

index.js

index.js is the traditional and actual entry point for all Node apps. in React, it tells what to render and where to render.

components

components works as a func, and props is the func’s paramters, the func will return a React element which then rendered in view

components can be either class, derived from React.Component, which then has this.state and this.setState() ;

or a function, which need use Hook to keep its state.

the design advantage of components is obvious: to make components/modules reuseable. usually in route.js will define the logic switch to each component based on the HTTP request.

setState

whenever this.setState() takes an object or a function as its parameter, update it, and React rerender this component. when need to change a component state, setState() is the right way, rather than to use this.state = xx, which won’t register in React.

Hook

example from stateHoook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { useState } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}

Hook is a speicial feature, used to share sth with React function. e.g. useState is a way to keep React state in function, which by default has no this.state

in Hook way, even afer function() is executed, the function’s variable is not clear, but keep until next render. so basically Hook give a way to make function stateable.

  • intial hook

the only parameter pass in hook::useState(new Map()) is the initial state. useState(initState)

  • return from useState

it returns a pair [currentState, setStatefunc], e.g. [maps, setMaps], setStatefunc here is similar as this.setState in class component

  • access state

directly {currentState}

  • update state

{() => setStatefunc(currentState)}

Context

image

context gives the way to access data, not in the strict hierachy way. the top is the context Provider, and the is the context consumer, there can be multi consumers.

createContext

as in react context official doc

1
const Context = React.createContext(defaultValue);

during render, the component which subscribe this context will get the context content from its context provider and put in rendering, only when no avialable provider is found, defaultValue is used.

1
<Context.Provider value={/xx/} >

whenever the value in Provider changes, all consumers will rerender.

EventSource

EventSource is HTTP based one-way communication from server to client, which is lighter than Websocket eventsource vs websocket, also the message type is only txt in EventSource, while in Websocekt it can be either txt or binary stream.

by default, when client received a [“/event”] message, will trigger onMessage(). but EveentSource allow to define user-speicial event type, e.g. VehicleDownload, so in client need to a new listener:

1
myEventSource.addEventListener('VehicleDownload', (e)=>handleVehicleEvents(e))

react route

js special

first class object

  • a function is an instance of the Object type
  • a function can have properties and has a link back to its constructor method
  • can store a function in a variable
  • pass a function as a parameter to another function
  • return a function from another function

promise

arrow function

nancyfx study

Posted on 2019-08-30 |

document, Nancy is used in lg-sim webUI 2019.07 version, pretty new staff for me.

Introduction

Nancy is a lightweight, low-ceremony framework for building HTTP based services on .NET and Mono. Nancy is designed to handle DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH request and provides a simple, elegant Domain Specific Language(DSL) for returning a response.

build to run anywhere

Nancy was designed to not have any dependenceis on existing frameworks, it’s used pretty much wherever you want to. host in Nancy acts as an adaptor for a hosting environment, thus enabling Nancy to run on existing techs, such as ASP.NET, WCF.

the bare minimum requires to build a Nancy service are the core framework and a host.

helloworld service

all module should be derived from NancyModule, and define a route handler. tips: always make the module public, so NancyFx can discover it.

1
2
3
4
5
6
7
8
public class HelloWorld : NancyModule
{
public HelloModule()
{
Get["/"] = parameters => "Hello World" ;
}
}

exploring modules

module is where you define the logic, is the minimum requirement for any Nancy app. module should inherit from NancyModule, then define the behaviors, with routes and actions.

modules are globally discovered

the global discovery of modules will perform once and the information is then cached, so not expensive.

Define routes

to define a Route need to specify a Method + Pattern + Action + (optional) Condition

1
2
3
4
5
6
7
8
9
public class VehicleModule : NancyModule
{
public VehicleModule()
{
Get["/vehicle"] = _ => {
// do sth
};
}
}

or async run:

1
2
3
4
5
6
7
8
9
public class VehicleModule : NancyModule
{
public VehicleModule()
{
Get["/vehicle", runAsnyc: true ] = async(_, token) => {
// do sth long and tedious
};
}
}

Method

method is the HTTP method used to access the resource, Nancy support: DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH.

secret for selecting the right route to invoke

in case when two routes capture the same request, remember :

  • the order in which modules are loaded are non-deterministic

  • routes in a given module are discovered in the order in which they are defined

  • if several possible matches found, the most specific match.

root path

all pathes used in Nancy are relative to root path, which tell Nancy where its resources are stored on the file system, which is defined in IRootPathProvider

static content

static content is things e.g. javascript files, css, images etc. Nancy uses a convention based approach to figure out what static content it is able to serve at runtime.

Nancy supports the notion of having multiple conventions for static content and each convention is represented by a delegate with the signature Func<NancyContext, string, Response>

the delegate accepts two parameters: the context of the current request and the application root path, the output of the delegate is a standard Nancy Response object or null, which means the convention has no static content.

define your own conventions usign the bootstrapper

link

View engines

view engine, takes a template and an optional model(the data) and outputs(usually) HTML to be rendered into the browser. in lg-sim, the view is rendered in nodejs.

MVC

model view controller

  • understand controller

a controller is reponsible for controlling the flow logic in the app. e.g. what reponse to send back to a user when a user makes a browser request.

any public method in a controller is exposed as a controller action.

  • understand view

a view contains the HTML markup and content that is send to the browser. in general to return a view for a controller action, need to create a subfolder in the Views folder with the same name as the controller.

  • understand model

the model is anything not inside a controller or a view. e.g. validation logic, database access. the view should only contain logic related to generating the user interface. the controller should only contain the bare minimum of logic required to return the right view.

C# anonymous

c# programming guide

1
2
3
4
5
(input-parameters) => expression
(input-parameters) => {<sequence-of-statements>}
TestDelegate testD = (x) => {(Console.WriteLine(x);};
  • => is the Lambda operator, on its left is input paramters(if exist). Lambda expression/sequence is equal to a delegate class.
  • delegate is a refer type, used to pass one function as paramter to another function. e.g. in event handle.

Nancy in lg-sim WebUI

/Assets/Scripts/Web

a few steps to build Nancy server:

  • Nancyhost.start()
  • add NancyModule instance(where define route logic)

a few other libs used :

  • PetaPoco, a light-weight ORM(object relational mapper) framework in C#

  • SQLite

refer

meet nancy

nancy doc in chinese

`

未来5年在哪里 (8).md

Posted on 2019-08-24 |

这一系列的思考来源两个事件:深圳汽车电子行业代表来司交流;与全球机器人大赛参展。

深圳的中小企业 vs 资本大户

布谷鸟 智能驾驶座舱解决方案供应商。主要产品,车载显示屏,仪表屏和基于Android操作系统的上层应用。展示完,第一感受就是深圳华强北来了。

当年(2007年),中国风靡深圳山赛手机。甚至多年以后,山赛智能手机成了中国发展的一个典型案例,为众人津津乐道: 眼看他起高楼,眼看他宴宾客,眼看他楼塌了。 这个产业最初蓬勃,但凡投资进去的人,都躺着赚钱,只是没能力在蓬勃发展期间为转型蓄力。后来政策、市场、甚至原材料的任何风吹草动,都足以摧毁它。

这个产业的问题放大了看,就是 华为/阿里 与 中兴/联想 的对比。国内的制造业小企业,最初都是代理、组装、贴标签、山赛货。如果碰到市场爆发,春风得意,赚的盆满钵满。但是,后续如何发展,创始人的vision就立判高下了。

一个选择是立足长远利益,未雨绸缪,生于有患。在打开了市场之后,立马投入产品和相关技术、供应链、品牌积累。可以接受眼前的低资金回报,选择了艰辛但持久的终成就行业头部的道路。

一个选择是只看赚钱。自己做产品积累,回钱周期太久,根本不考虑。资本趋利,大不了赚到钱,再转战下一片红海。这是势利的商人思路,他们对某一个具体行业不带任何感情,冷血。任何行业只是一个资本生长的土壤,不管是做手机、地产、保险、造车等等,都不是出于热爱,而是资本逐利。比如,宝能收购万科,就是冷血的资本挑战性情的行业中人。

但凡对行业还有所爱的,都难以忍受被资方强奸。所以,恒大站出来说要造车,我的第一反应,就是恒大要来强奸造车人。恒大没有对汽车的感情,只不过跟进资本进军汽车领域。资本原本是公司的生产要素之一,但是资本又最不具有公司界限约束,任何外部资本都能挑战公司自身。所以,如何让资本服务于行业公司?

制造业创业

回到布谷鸟,号称做车载计算平台,不自己做计算芯片,不自己做车载屏幕,不自己做车载定制Android操作系统,顶多开发几个上层app。这不又是一家华强北组装厂吗。创业还靠廉价组装竞争?相比,北上的创业公司,诸如硬件地平线、软件旷视等算是技术/境界高多了。

也不得不提本司。背靠大树,天然壁垒,但实际做的还是华强北的活儿。不同之处是,资本压力小,对技术储备有规划但没有环境和姿态的转变。会聘一两个外国人、一两个教授撑面儿,但这几位基本处于边缘,决策、项目规划都不考虑他们。估计其他家,也好不了哪里去。要不然,市场会有反馈的。

这样的团队/小公司里面,对想要拔高产品/技术见识的年轻人其实很艰难。因为打开市场,销售是关乎存活的,相比产品是自研的,还是贴牌的,有没有底层开发/设计积累都是次要的。

要去这种小团队做产品/技术,就需要能单挑担子的产品人/技术大牛。当然,付出与回报怎么权衡。给ceo待遇,似乎可以考虑。

传统制造业大公司里面的小团队,虽然没有自己去开辟市场的压力,大不了内销,但同时带来的问题,是积重的公司元老,对职业经理人,工程师文化,都是严重的挑战。

公司元老

经常会看到,职业mba人在中国企业水土不服,或者回国的硅谷工程师对中国企业文化的抱怨。虽然,宏观数据国内企业似乎都很国际化了,底层的/微观的现代公司管理/制度上,却不是一代就能跟上国际的。比如,mbaer到中国公司,很难战胜资源/权利在握的元老们,按照现代管理办法去调整公司,那基本上就等着被边缘化,然后公司不养闲人,下一步就是踢出去。公司又回到原来的管理模式。老人们再次证明自己不瞎折腾,是公司的积重,继续升官发财。

工程师文化,不管是如google等互联网公司,还是如ford等汽车制造业公司,都比较明显。hr, manager, 甚至leader团队把自己归为工程师团队提供服务的,在衣食住行、工作环境、设备、交流、培训等等都照顾的很好。

虽然北美是更成熟的资本社会,他们的企业反而不那么见钱就撒网,没见过ford投资移动互联网,google要去收购造车厂,或者发展文化传媒业务的。他们的业务更倾向纵深,专注,在一个领域深耕,然后成为行业头部。这可能也是成熟资本市场的现代化公司该有的样子。

相比,国内的企业太草莽。国内的工程师只有听命于人。技术积累对绝大多数企业,都是可以谈谈但不会认真做的。这样的情况,当然长远是没前途的。一波政策、市场的红利之后,基本作死。

人口基数

国内也有很多有情怀的创业人或中小企业主,他们也许并不甘与政策红利,也想认真做产品。但是,在这个社会没办法。

美国的创业环境,想想apple, google, facebook,cruise等等创业经历。首先他们自己没有生存压力,出于热爱开始的;创业阶段,市场/政策对他们的包容度很好,允许决策失败;然后,资本市场、专业人才的补充都有成熟的供应体系。

国内,一方面有廉价的人口红利,但对大部分创业公司,规模经济反而很难真正成为其产品的利好因素,除了资本玩家,比如,摩拜单车、瑞幸咖啡、yy连锁酒店,滴滴出行等等,这些玩家,根本不是在拼产品,而是资本。谁占有更多资本,谁就能笑到最后。

这样的创业环境,不能培养社会范围内更好的创业土壤,反而破坏了创业各方面的供应系统,包括创始人的初衷,专业人才队伍,资本法务系统建立等等。归结一个词:浮躁。

人口基数大,在政治家、资本家眼里是好词,但是对个体,就意味着就业竞争、服务质量差、人际关系不温存。

经历过大公司的年轻人

在三四线小城市,有很多生活无忧的年轻人。他们大学毕业后,在大城市瞎晃了一年半载,找不到合适的企业,就打道回府了。家里有条件,在当地慢慢都会活的滋润。我是觉得,经历下一个现代化管理的大公司,也是个不错的体验。至少知道人类社会,最优秀的组织体系是怎么运作的。

当然,没有上升,一辈子在大公司的系统里打工,就有点无趣。不如回家悠哉悠哉。

世界机器人大会2019

整体感受,小企业生存多艰。

real-world env in ADS simulation

Posted on 2019-08-20 |

this topic is based on lg-sim, the advantage is plenty Unity3D resources. to drive planning design, simulation has to keep as real-world env as possible. for L3 and below, the high-fidelity is actually most about HD map, since in L3 ADS, sensors only cares about the road parternors on road, and planning module take hd map as input.

so there is a need to build simulation envs based on hd map.

osm

in the Unity engine, all in the env(e.g. traffic light, road lanes, lane mark etc) are GameObjects. to describe a map info, one of most common used map format is OSM (another is opendrive, but no open parser in unity yet), however which is not born to used in hd map, but still is very flexible to extend to descripe all info, a hd map requires. e.g. lane id, lane width, lane mark type e.t.c

the open-source tool OsmImporter is good enough to parse osm meta data into Unity GameObjects. for different map vendors, first to transfer their map format into the extended-osm format. and then can generate all map info related gameObjects in Unity env. that’s the main idea to create real-world env in simualtor.

the end is to make a toolchain from map vendor input to Unity 3D env.

waypoints

in either lg-sim or carla, the npc vehicles in self-driving mode, is actually controlled by following waypoints in the simulator, and waypoints is generated during creating map in step above.

carla has plenty client APIs to manage the waypoints, and then drive npcs.

hd-map tool

by default, both lg-sim and carla has a tool to create hd-map, that’s basically mark waypoints on the road in an existing map, which is not strong. carla later support Vector one to build in map more efficiently.

L3+ virtual env generator

there are plenty teams working on building/rendering virtual envs directly from sensor data, e.g Lidar cloud point or camera image, and plenty image-AI techs here, which of course gives better immersed experince. and the test task is mostly for perception, data-fusion modules, which is heavier in L3+

threading and websockets

Posted on 2019-08-16 |

threading.Thread

1
2
3
4
5
6
7
8
9
10
11
12
run()
start()
join([time])
isAlive()
getName()
setName()

to initialize a thread with: threadID, name, counter

start() and run()

start() once for each thread, run() will not spawn a separate thread, but run in current thread

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class myThread(threading.Thread):
def __init__(self, *args, **kwargs):
super(myThread, self).__init__(*args, **kwargs)
def run(self):
print("run ... from start()")
if __name__ == "__main__":
demo = myThread()
demo.start()
demo.join()

lock objects

a primitive lock does not belongto a certain thread when locked. by default, when constructed, the lock is in unlocked state.

  • acquire(), will set the lock to locked and return the lock immediately(atom operator); if current lock is locked, then acquire() blocks (the thread) untill the occuping-lock thread calls release().

if multi-thread blocked by acquire(), only one thread will get the lock when release() is called, but can’t sure which one from the suspended threads

condition objects

1
2
3
4
5
6
7
8
9
10
threading.Condition(lock=None)
acquire()
wait()
notify()
release()

thread A aquire() the condition variable, to check if condition satification, if not, thread A wait; if satisfied, update the condition variable status and notify all other threads in waiting.

websocket

background

webocket is better than http when the server need actively push message to client, rather than waiting client request first.

client

usually webSocket client has two methods: send() to send data to server; close() to close websocket connection, as well a few event callbacks:

  • onopen(): triggered when websocket instance get connected
  • onerror(),
  • onclose(),
  • onmessage(), which triggered when received data from server.

when constructing a webSocket instance, a connection is built between server and client.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// client connect to server
var ws = new WebSocket('ws://localhost:8181');
ws.onopen = function(){
ws.send("hello server");
}
// if need run multi callback
ws.addEventListener('open', function(event) {
ws.send('hello server');
});
ws.onmessage = function(event){
var data = event.data ;
};
ws.addEventListener("message", function(event){
var data = event.data ;
});
ws.send('client message');

onmessage()

whenever the server send data, onmessage() events get fired.

server

  • onOpen(), triggered when a new client-server connection setup
  • onMessage(), triggered when message received
  • onClose(),
  • onError(),

implementation

in c#, there is websocket-sharp, in python is python-websockets, in js is nodejs-websocket. as well as websocket protocol is satisified, server can write using websocket-sharp, and client in python-websockets. an example is in lg-simulator.

the message type in websocket can be json or binary, so there should be json parse in c#(SimpleJSON), python(json module) and js (JSON).

refer

sending message to a client

sent message from server to client

python websockets

nodjs websocket

c# websocket

Unet intro

Posted on 2019-08-16 |

unity3d manual

High Level API(HLAPI)

HLAPI is a server authoritative system, triggered from UnityEngine.Networking

authority

host has the authority over all non-player GameObjects; Player GameObjects are a special case and treated as having “local authority”.

local/client authority for npc

method1: spawn the npc using NetworkServer.SpawnWithClientAuthority
method2: NetworkIdentity.AssignClientAuthority

network context properties

isServer()
isClient()
sLOcalPlayer()
hasAuthority()

networked GameObjects

multiplayer games typically built using Scenes that contain a mix of networked GOs and regular GOs.  networked GOs needs t obe synchronized across all users; non-networked GOs are either static obstacles or GOs don't need to synchronized across players 

 networked GO is one which has a NetworkIdentiy component. beyond that, you need define what to syncronize. e.g. transform ,variables ..

player GO

NetworkBehavior class has a property: isLocalPlayer, each client player GO.isLocalPlayer == true, and invoke OnStartLOcalPlayer()

Player GOs represent the player on the server, and has the ability to run comands from the player’s client.

spawning GOs

the Network Manager can only spawn and synchronize GOs from registered prefabs, and these prefabs must have a NetworkIdentity component

spawning GOs with client authority

NetworkServer.SpawnWithClientAuthority(go, NetworkConnection),
for these objects, hasAuthority is true on this client and OnStartAuthority() is called on this client. Spawned with client authority must have LocalPlayerAuthority set to NetworkIdentity,

state synchronization

[SyncVars] synchronzed from server to client; if opposite, use [Commands]

the state of SyncVars is applied to GO on clients before OnStartClient() called.

engine and editor integration

  • NetworkIdentity component for networked objects
  • NetworkBehaviour for networked scripts
  • configurable automatic synchronization of object transforms
  • automatic snyc var

build-in Internet services

network visibility

relates to whether data should or not sent about the GOs to a particulr clinet.

method1: add Network Proximity Checker component to networked GO
method2:

Scene GOs

saved as part of a Scene, no runtime spawn

actions and communication

method1: remote actions, call a method across network
method2: networking manager/behavior callbacks
method3: LL network messages

host migration

host: a player whose game is acting as a server and a “local client”
remote client: all other players
so when the host left, host need migrate to one remote client to keep the game alive

how it works:
enable host migration. so Unity will distribute the address of all peers to other peers. so when host left, one peer was selected to be the new host (heart-keeping)

network discovery

allow players to find each other on a local area network(LAN)

need component ,

in server mode, the Network Discovery sends broadcast message over the network o nthe specified port in Inspector;

in client mode, the component listens for broadcast message on the specified port

using transport Layer API (LL API)

socket-based networking

in the end

network is basic cornerstone in server-client applications, Unet is deprecated at this moment, but still many good network resource can take in charge. e.g. websockets, nodejs, and what behind these network protocol or languages, e.g. async/coroutines are charming as well.

python generator and asynico

Posted on 2019-08-16 |

python iterator

in python, iterator is any object that follows iterator protocol. which means should include method: __iter()__, next(), if no next element should raise StopIteration exception.

take an example, dict and list have implemented __iter()__ and __getitem__() methods, but not implemented next() method. so they are iterable but not iterator.

generator

to support delay operations, only return result when need, but not immediately return

  • generator funcion (with yield)

  • generator expression

Python generator in other languages is called coroutines

yield

yield is almost of return, but it pauses every step after executing the line with yield, and till call next() will continue from the next line of yield.

1
2
3
4
5
6
7
8
while True:
sim.run(timeout, cb)
def cb():
a = 1
yield print(a)
a += 1

coroutines

example:

1
2
3
4
5
6
7
8
def cor1(name):
print("start cor1..name..", name)
x = yield name
print("send value", x)
cor_ = cor1("zj")
print("next return", next(cor_))
print("send return", cor_.send(6))

to run coroutine, need first call next(), then send() is called. namely, if not call next() first, send() will wait, and never be called.

the thing is, when define a python generator/coroutine, it never will run; only through await(), next() call first, which then trigger the generator/coroutine start.

asyncio

asyncronized IO, event-driven coroutine, so users can add async/await to time-consuming IO.

  • event-loop

event loop will always run, track events and enqueue them, when idle dequeue event and call event-handling() to deal with it.

  • asyncio.Task

await

await only decorate async/coroutine, which is a waitable object, it works to hold the current coroutine(async func A) and wait the other coroutine(async func B) to the end.

1
2
3
4
5
6
7
8
9
async def funcB():
return 1
async def funcA():
result = await funcB()
return result
run(funcA())

multi-task coroutines

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
loop.create_task()
run_until_complete() #block the thread untill coroutine completed
asyncio.sleep() #nonblock event-loop, with `await`, will return the control-priority to event-loop, at the end of sleep, control-priority will back to this coroutine
asyncio.wait(), #nonblock event-loop, immeditialy return coroutine object, and add this corutine object to event-loop
```
the following example: get the event-loop thread, add coroutine objct(task) in this event-loop, execute task till end.
```python
import asyncio
async def cor1(name):
print("executing: ", name)
await asyncio.sleep(1)
print("executed: ", name)
loop = asyncio.get_event_loop()
tasks = [cor1("zj_" + str(i)) for i in range(3)]
wait_cor = asyncio.wait(tasks)
loop.run_until_complete(wait_cor)
loop.close()
```
### dynamically add coroutine
```shell
loop.call_soon_threadsafe() # add coroutines sequencially
asyncio.run_coroutine_threadsafe() #add coroutines async

add coroutine sequencially

in this sample, main_thread(_loop) will sequencely run from begining to end, during running, there are two coroutines registered, when thread-safe, these two coroutines will be executed.

the whole process actually looks like run in sequencialy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asyncio
from threading import Thread
def start_loop(loop):
asyncio.set_event_loop(loop)
loop.run_forever()
def thread_(name):
print("executing name:", name)
return "return nam:" + name
_loop = asyncio.new_event_loop()
t = Thread(target=start_loop, args=(_loop,)) #is a thread or coroutine ?
t.start()
handle = _loop.call_soon_threadsafe(thread_, "zj")
handle.cancel()
_loop.call_soon_threadsafe(thread_, "zj2")
print("main thread non blocking...")
_loop.call_soon_threadsafe(thread_, "zj3")
print("main thread on going...")

add coroutines async

in this way, add/register async coroutine objects to the event-loop and execute the coroutines when thead-safe

1
2
3
4
5
6
7
8
9
10
11
future = asyncio.run_coroutine_threadsafe(thread_("zj"), _loop)
print(future.result())
asyncio.run_coroutine_threadsafe(thread_("zj2"), _loop)
print("main thread non blocking...")
asyncio.run_coroutine_threadsafe(thread_("zj3"), _loop)
print("main thread on going...")

async callback vs coroutines

compare callback and coroutines is hot topic in networking and web-js env.

dns server in lan

Posted on 2019-08-10 |

DNS server in LAN

to use domain name(e.g. gitlab.com) in LAN rather than IP, it needs every local host machine to store all key-values:: host-IP. if the LAN has many host machines, it will be difficult to maintain. Setting up DNS server will help to automatically map the ip to domain or reverse in the LAN.

bind9

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
apt-get install bind9
```
### /etc/bind/named.conf.local
```shell
zone "gitlab.com" {
type: master;
file "/etc/bind/db.ip2gitlab.com" ;
};
zone "101.20.10.in-addr.arpa" {
type: master;
file "/etc/bind/db.gitlab2ip.com" ;
};
```
### /etc/bind/db.gitlab2ip.com
[dns zone file format](https://help.dyn.com/how-to-format-a-zone-file/)
gitlab2ip zone file is mapping from domain to ip, as following sample, it works like:
www.$ORIGIN --> 10.20.101.119
```shell
; command
$TTL 6000
;@ refer to current zone file
; DNS-server-FDNQ notification-email
$ORIGIN gitlab.com
@ IN SOA server email (
2 ;
1d ;
1h ;
5min ;
)
@ IN NS server
www IN A 10.20.101.119
server IN A 10.20.101.119

/etc/bind/db.ip2gitlab.com

ip2gitlab zone file is from ip to domain mapping,

1
2
3
4
5
6
7
8
9
10
11
$TTL 6000
$ORIGIN 101.20.10.in-addr.arpa
@ IN SOA server. email. (
2 ;
1d ;
1h ;
5min ;
)
@ IN NS server
119 IN A www.gitlab.com
119 IN A server.gitlab.com

nslookup

nslookup www.gitlab.com   #dns forward (domain 2 ip)

nslookup  10.20.101.119   #reverse (ip 2 domain)

settings

if the DNS setted above(DNS-git) is the only DNS server in the LAN, then this DNS works like a gateway, to communicate by domain name, every local host talk to it first, to understand the domain name.

but in a large size company LAN newtwork, there may already has a DNS server hosted at IT department (DNS-IT), with a fixed IP e.g. 10.10.101.101, and all localhost machines actually set DNS-IT as the default DNS. DNS-git will work as a sub-DNS server.

Inside the small team, either every localhost change default DNS to DNS-git, then DNS-git become the sub-network server.

if every localhost still keep DNS-IT, there is no way(?) to use DNS-git service in LAN, and even make conflicts, as the DNS-git localhost machine will listen on all TCP/IP ports, every new gitlab.com access request (input as IP address) will get an output as domain name, but the others can’t understand this domain-name…

what happened with two DNS server in LAN ?

how email works

Mail User Agent(MUA), e.g. Outlook, Foxmail, used to receive and send emails.

MUA is not directly sent emails to end users, but through Mail Transfer Agent(MTA), e.g. SendMail, Postfix.

an email sent out from MUA will go through one or more MTA, finally reach to Mail Delivery Agent(MDA), the email then store in some database, e.g. mailbox

the receiver then use MUA to review the email in the mailbox

ps, one day work as a IT admin ….

design scenarios in ADS simulation

Posted on 2019-07-25 |

to design scenarios in self-driving test, one reference is: a framework for automated driving system testable cases and sceanrios, most other scenario classifications have almost the same elements: ODD, e.g. road types, road surfaces; OEDR, namely object and event detection and response, e.g. static obstacles, other road actors, traffic signature, environment conditions, special zones; and failure mode behaviors.

in general, test cases can be grouped as black box test, in which the scenario parterners’ behavior is not pre-defined or unpredictable, e.g. random traffic flow(npcs) scenario, or white box test, where the npcs behavior is pre-defined, e.g. following user-define routings. white box testing is helpful to support performance metrics; while black-box testing is helpful to verify the system completeness and robust.

as for ADS test, there are a few chanllenges coming from:

  • heuristics decision-making algorithms, deep-learning algorithms, which is not mathematically completed

  • the test case completeness, as the number of tests required to achieve statistically significant to claim safe would be staggering

  • undefined conditions or assumptions

a sample test scenario set maybe looks like:

ODD OEDR-obj OEDR-loc maneuver
in rump static obstacles in front of current lane
in rump static obstacles in front of targe lane
in rump dynamic obstacles in front of current lane

scenarios_runner

carla has offered an scenario engine, which is helpful to define scenarios by test_criteria and behaviors, of course the timeout as well.

test_criteria, is like an underline boundary for the scenario to keep, if not, the scenario failed. e.g. max_speed_limitation, collision e.t.c. these are test criterias, no matter simualtion test or physical test, that have to follow the same criterias; in old ways, we always try to find a way to evaluate the simulation result, and thought this may be very complex, but as no clue to go complex further, simple criterias actually is good. even for reinforcement learning, the simple criterias is good enough for the agent to learn the drive policy.

of course, I can expect there are some expert system about test criterias.

For simulation itself, there has another metric to descibe how close the simulation itself to physical world, namley to performance how well the simulator is, which is beyond here.

behaivor is a good way to describe the dynamic processing in the scenario. e.g. npc follow lane to next intersection, and stop in right lane, ego follow npc till the stop area.

OpenScenario has similar ideas to descibe the dynamic. to support behaivor, the simulator should have the features to control ego and npc with the atomic behaviors, e.g. lane-follow, lane-change, stop at intersection e.t.c.

in lg simulator, npc has simple AI routing and lane-following API, basically is limited to follow pre-defined behaviors; ego has only cruise-control, but external planner is avialable through ROS.

for both test_criteria and behavior, carla has a few existing atomic elements, which is a good idea to build up complex scenarios.

OpenScenario

not sure if this is a project still on-going, carla has interface and a few other open source parsers there, but as it is a standard in popular projects, e.g. PEGUS, should be worthy to take further study.

model based design sucks

Posted on 2019-07-18 |

AV development includes perception, sensor fusion, location & mapping, decision-making & control (or motion planning), embedded, simulation and maybe many system-glue software tools.

L3 planning & control is now expert-based decision system, which basically defines rules to make decision, where model based design(mbd) is a helper.

Waymo mentioned their hybrid decision-making solution, basically Machine Learning(ML) will take a big part of the situations, but still space to allow rule-based solution to take priority.

when consider to ML decision making, mdb will become less useful.

why model-based

Traditional OEMs follow vehicle-level safety requirements(ASIL-D) to develop vehicle products and components, usually can be represented as the V style development, from user requirs, system design, implmenent to test verification.

to go through the whole V process take a rather long time, e.g. for a new vehicle model, it means 2~5 years. Commercial hardware and software(mobile apps) products which has lower level safety requirements, however, can iterate in a quicker frequency.

the safety requirements drive the product development in a very different way, compared to common Internet products, which include more straight-forward programming skills and software architecture mindset. but to satisfy the additional, or should say the priority safety requirements, how to organize the code is less important than how to verify the functions is to satisfy the safety.

so there comes the model-based design, the most-highly feature of which is to support system test and verify at pre-product period.

of course, model-based design should be easily to build up prototype and visualize the system, which is the second feature of mbd, working similar like a microsoft vision e.t.c

thirdly, from design to product, is auto code generation. which means once the design is verified, you don’t need to go back to write code again, but directly generate code from the design graph.

model-based design toolchain is already a whole eco-system, e.g. system design, auto code generator, test tools. and all these tools should be first verified by ASIL-D standard.

Internet AI companies once thought it would be easy to take over this traditional development by Internet agile development, while the reality is they still depends on model-based design at first to verify the system, then back to implement code again, which should be more optimized than auto-generated ones, which is one drawbacks of mbd, as mbd is tool-depended, e.g. Matlab, if Matlab doesn’t support some most updated libs, then they are not in the auto-code, and most time Matlab is far behind the stable version of libs outside.

what mbd can’t do

mbd is born to satisfy safety requirments in product development. so any non safety required product won’t use mbd.

and by nature, mbd is good at turning mathematical expressions to system languages, and logical relations to state flows, so any non-articulatable system is difficult to represent in mdb languages.

in vehicle product development, engine, powertrain, ECU, brake system, ADAS, L3 motion planning, e.t.c have depends heavily on mbd.

but also we can predict, L3+ applications arise, with image, cloud point based object detection, data fusion, SLAM, AI-driven planning, IVI, V2X, will hybrid mbd with many Internet code style.

industry experience: a metaphysics

some friends say mass-product-experience makes him more value than new birds. since industry experience is not transparent, as there is a no clear bar to test the ability/value of the enginer, unlike developers, who can valued by their product, or skills, also the same reason make these guys who stay long in the industry sounds more valued, and they have more likey went through one or many mass product experience.

but at most, industry product depends e.g. vehicle, on teamwork, even the team lead can’t make it by himself, unlike developer, a top developer can make a huge difference, much valued than a team of ordinary ones.

1…91011…20
David Z.J. Lee

David Z.J. Lee

what I don't know

193 posts
51 tags
GitHub LinkedIn
© 2020 David Z.J. Lee
Powered by Hexo
Theme - NexT.Muse