Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gernby 510 merge #2

Closed
wants to merge 68 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
845508b
fixed max torque, for more actual torque
Gernby Jan 10, 2019
5443792
Delete visiond
Gernby Jan 10, 2019
504f750
0.5.6 visiond
Gernby Jan 10, 2019
baa7b73
Merge branch 'devel' of https://github.com/Gernby/openpilot into devel
Gernby Jan 16, 2019
6d737ca
Merge branch 'devel' of https://github.com/commaa/openpilot into
Gernby Feb 5, 2019
167ef82
Merge fix
Gernby Feb 5, 2019
4ed0725
another merge fix
Gernby Feb 5, 2019
17a5c7b
Update README.md
Gernby Feb 16, 2019
4f8dd77
Update README.md
Gernby Feb 16, 2019
3a49dac
added sftp
Gernby Feb 22, 2019
73c8877
Merge branch 'devel' of https://github.com/commaai/openpilot into devel
Gernby Feb 22, 2019
e57a9ac
configuring git
Gernby Feb 22, 2019
4712458
Merge branch 'devel' of https://github.com/Gernby/openpilot into deve
Gernby Feb 22, 2019
5a0aae3
git config
Gernby Feb 22, 2019
9e28ef9
git config
Gernby Feb 22, 2019
4101ddc
Update README.md
Gernby Feb 22, 2019
a1819ea
git config
Gernby Feb 22, 2019
2ea0602
Merge branch 'devel' of https://github.com/gernby/openpilot into devel
Gernby Feb 22, 2019
eef45dc
Merge branch 'devel' of https://github.com/Gernby/openpilot into devel
Gernby Feb 22, 2019
2629080
git config
Gernby Feb 22, 2019
e7c52d5
Merge branch 'devel' of https://github.com/gernby/openpilot into devel
Gernby Feb 22, 2019
031996f
git cleanup
Gernby Feb 22, 2019
64cd45f
gitignore
Gernby Feb 22, 2019
db34d8c
ignore visiond
Gernby Mar 1, 2019
da84d41
preparing for PRpreparing for PR
Gernby Mar 4, 2019
dbe8a75
added syncID for Accord
Gernby Mar 4, 2019
ffd8c3a
more refinements for PR
Gernby Mar 4, 2019
1412a60
fixed a couple cleanup mistakes
Gernby Mar 4, 2019
36de288
another cleanup fixanother cleanup fix
Gernby Mar 4, 2019
104c4a8
fixed some cleanup mistakes.
Gernby Mar 4, 2019
3c96b40
Fixed issue with thermald between drives
Gernby Mar 5, 2019
52ae8fe
fixed sync issue with extended drives
Gernby Mar 21, 2019
4017b1d
merge fixes
Gernby Mar 21, 2019
a07ac15
Updated steer and mpc dampening
Gernby Mar 24, 2019
463c80b
fixed latcontrol reset damp values
Gernby Mar 24, 2019
16624bd
Merge branch 'devel' of https://github.com/commaai/openpilot into dam…
Gernby Mar 24, 2019
c97076a
Merge pull request #4 from commaai/devel
Gernby Mar 24, 2019
7f08767
fixed for angle-steer
Gernby Mar 24, 2019
d555019
Merge branch 'dampen-mpc-interp' of https://github.com/Gernby/openpil…
Gernby Mar 24, 2019
388f8cd
Broken!
Gernby Mar 25, 2019
722224c
fixed by clean reset
Gernby Mar 25, 2019
eb69a0f
revised damp and react parameters
Gernby Mar 25, 2019
84ca9a7
adding live-tuning
Gernby Mar 26, 2019
d744113
added kegman's live-tuning
Gernby Mar 26, 2019
9170a94
Merge pull request #5 from Gernby/temp-test
Gernby Mar 26, 2019
a191bdd
fix for boardd sync
Gernby Mar 27, 2019
29b2d3c
fixed default values
Gernby Mar 27, 2019
eaf9a8d
testing-sauce-0.5.10
Gernby Mar 27, 2019
78890d6
Works great!
Gernby Mar 27, 2019
ecb67bd
working awesome!
Gernby Mar 27, 2019
0845916
updated default parameters for dampening
Gernby Mar 27, 2019
875261d
lane filtering in model_parser is not tested
Gernby Mar 30, 2019
21a6e73
improved lane filtering
Gernby Mar 31, 2019
9d832a8
fixed realtime priorities and LiveParameters
Gernby Apr 1, 2019
9520ca9
fixed steer_status frame count check
Gernby Apr 1, 2019
4ef7f48
mostly tested, and awesome
Gernby Apr 3, 2019
4c445d7
Working really nicely
Gernby Apr 3, 2019
df2f4f2
improved exit filter AND added rate-based feedforward
Gernby Apr 3, 2019
fb775fb
tweaked the lane filter AND disabled rate-based FF
Gernby Apr 4, 2019
509bee5
added rate-based feed forward
Gernby Apr 4, 2019
9377c29
'dis is good'dis is good
Gernby Apr 5, 2019
c177a58
added new params to dashfile
Gernby Apr 5, 2019
0cceb50
added lane filter and rate-based feed-forward
Gernby Apr 6, 2019
89f6de9
updated tune.py
Gernby Apr 6, 2019
78fd669
cleaned up live tuning
Gernby Apr 6, 2019
9926cd4
mostly disable lane filter for now
Gernby Apr 7, 2019
13344ae
Added dampened desired rate
Gernby Apr 7, 2019
2fe8e19
fixed feed-forward params
Gernby Apr 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cereal/car.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ struct CarParams {
longitudinalKpV @37 :List(Float32);
longitudinalKiBP @38 :List(Float32);
longitudinalKiV @39 :List(Float32);

steerLimitAlert @29 :Bool;
steerMPCReactTime @51 :Float32;
steerMPCDampTime @52 :Float32;

vEgoStopping @30 :Float32; # Speed at which the car goes into stopping state
directAccelControl @31 :Bool; # Does the car have direct accel control or just gas/brake
Expand Down
9 changes: 9 additions & 0 deletions cereal/log.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ struct Live100Data {
jerkFactor @12 :Float32;
angleSteers @13 :Float32; # Steering angle in degrees.
angleSteersDes @29 :Float32;
dampAngleSteersDes @52 :Float32;
dampRateSteersDes @53 :Float32;
rateModeFF @54 :Float32;
angleModeFF @55 :Float32;
curvature @37 :Float32; # path curvature from vehicle model
hudLeadDEPRECATED @14 :Int32;
cumLagMs @15 :Float32;
Expand Down Expand Up @@ -613,6 +617,10 @@ struct PathPlan {

angleSteers @8 :Float32; # deg
rateSteers @13 :Float32; # deg/s
mpcAngles @14 :List(Float32);
mpcRates @15 :List(Float32);
mpcTimes @16 :List(Float32);
laneProb @17 :Float32;
valid @9 :Bool;
paramsValid @10 :Bool;
modelValid @12 :Bool;
Expand Down Expand Up @@ -1612,6 +1620,7 @@ struct LiveParametersData {
angleOffsetAverage @3 :Float32;
stiffnessFactor @4 :Float32;
steerRatio @5 :Float32;
laneWidth @6 :Float32;
}

struct LiveMapData {
Expand Down
534 changes: 534 additions & 0 deletions dashboard.py

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions dashfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/usr/bin/env python
import csv
import zmq
import time
import numpy as np
import selfdrive.messaging as messaging
from selfdrive.services import service_list
from common.realtime import set_realtime_priority, Ratekeeper
import os, os.path

# Polling rate should be twice the data rate to prevent aliasing
def main(rate=100):
set_realtime_priority(5)
context = zmq.Context()
poller = zmq.Poller()

live100 = messaging.sub_sock(context, service_list['live100'].port, conflate=False, poller=poller)
carState = messaging.sub_sock(context, service_list['carState'].port, conflate=True, poller=poller)
can = None #messaging.sub_sock(context, service_list['can'].port, conflate=True, poller=poller)

vEgo = 0.0
_live100 = None
_can = None

frame_count = 0
skipped_count = 0

rk = Ratekeeper(rate, print_delay_threshold=np.inf)

# simple version for working with CWD
#print len([name for name in os.listdir('.') if os.path.isfile(name)])

# path joining version for other paths
DIR = '/sdcard/tuning'
filenumber = len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))])

kegman_counter = 0
monoTimeOffset = 0
receiveTime = 0
angle_rate = 0.0

print("start")
with open(DIR + '/dashboard_file_%d.csv' % filenumber, mode='w') as dash_file:
print("opened")
dash_writer = csv.writer(dash_file, delimiter=',', quotechar='', quoting=csv.QUOTE_NONE)
print("initialized")
dash_writer.writerow(['ff_rate','ff_angle', 'angle_steers_des','angle_steers','angle_rate','dampened_angle_steers_des','dampened_angle_rate_des','dampened_angle_steers','v_ego','steer_override','p','i','f','time'])
print("first row")

while 1:
for socket, event in poller.poll(0):
if socket is can:
_can = messaging.recv_one(socket)
print(_can)

if socket is carState:
_carState = messaging.drain_sock(socket)
for cs in _carState:
angle_rate = cs.carState.steeringRate

if socket is live100:
_live100 = messaging.drain_sock(socket)
for l100 in _live100:
vEgo = l100.live100.vEgo
if vEgo > 0: # and l100.live100.active:
receiveTime = int(monoTimeOffset + l100.logMonoTime)
if (abs(receiveTime - int(time.time() * 1000000000)) > 10000000000):
monoTimeOffset = (time.time() * 1000000000) - l100.logMonoTime
receiveTime = int(monoTimeOffset + l100.logMonoTime)

frame_count += 1
dash_writer.writerow([str(round(l100.live100.rateModeFF, 2)),
str(round(l100.live100.angleModeFF, 2)),
str(round(l100.live100.angleSteersDes, 2)),
str(round(l100.live100.angleSteers, 2)),
str(round(angle_rate, 2)),
str(round(l100.live100.dampAngleSteersDes, 2)),
str(round(l100.live100.dampAngleRateDes, 2)),
str(round(l100.live100.dampAngleSteers, 2)),
str(round(l100.live100.vEgo, 1)),
1 if l100.live100.steerOverride else 0,
str(round(l100.live100.upSteer, 4)),
str(round(l100.live100.uiSteer, 4)),
str(round(l100.live100.ufSteer, 4)),
str(receiveTime)])
else:
skipped_count += 1
else:
skipped_count += 1
if frame_count % 200 == 0:
print("captured = %d" % frame_count)
frame_count += 1
if skipped_count % 200 == 0:
print("skipped = %d" % skipped_count)
skipped_count += 1

rk.keep_time()

if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion launch_chffrplus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ fi

function launch {
# apply update
'''
if [ "$(git rev-parse HEAD)" != "$(git rev-parse @{u})" ]; then
git reset --hard @{u} &&
git clean -xdf &&
exec "${BASH_SOURCE[0]}"
fi

'''

# no cpu rationing for now
echo 0-3 > /dev/cpuset/background/cpus
echo 0-3 > /dev/cpuset/system-background/cpus
Expand Down
128 changes: 95 additions & 33 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pthread_t safety_setter_thread_handle = -1;
pthread_t pigeon_thread_handle = -1;
bool pigeon_needs_init;

int big_recv;
uint32_t big_data[RECV_SIZE*2];

void pigeon_init();
void *pigeon_thread(void *crap);

Expand Down Expand Up @@ -216,11 +219,14 @@ void handle_usb_issue(int err, const char func[]) {
// TODO: check other errors, is simply retrying okay?
}

void can_recv(void *s) {
bool can_recv(void *s, bool force_send) {
int err;
uint32_t data[RECV_SIZE/4];
int recv;
uint32_t f1, f2;
int recv, big_index;
uint32_t f1, f2, address;
bool frame_sent;
uint64_t cur_time;
frame_sent = false;

// do recv
pthread_mutex_lock(&usb_lock);
Expand All @@ -236,38 +242,52 @@ void can_recv(void *s) {

pthread_mutex_unlock(&usb_lock);

// return if length is 0
if (recv <= 0) {
return;
// return if both buffers are empty
if ((big_recv <= 0) && (recv <= 0)) {
return true;
}

// create message
capnp::MallocMessageBuilder msg;
cereal::Event::Builder event = msg.initRoot<cereal::Event>();
event.setLogMonoTime(nanos_since_boot());
big_index = big_recv/0x10;
for (int i = 0; i<(recv/0x10); i++) {
big_data[(big_index + i)*4] = data[i*4];
big_data[(big_index + i)*4+1] = data[i*4+1];
big_data[(big_index + i)*4+2] = data[i*4+2];
big_data[(big_index + i)*4+3] = data[i*4+3];
big_recv += 0x10;
}
if (force_send) {
frame_sent = true;

auto canData = event.initCan(recv/0x10);
capnp::MallocMessageBuilder msg;
cereal::Event::Builder event = msg.initRoot<cereal::Event>();
event.setLogMonoTime(nanos_since_boot());

// populate message
for (int i = 0; i<(recv/0x10); i++) {
if (data[i*4] & 4) {
// extended
canData[i].setAddress(data[i*4] >> 3);
//printf("got extended: %x\n", data[i*4] >> 3);
} else {
// normal
canData[i].setAddress(data[i*4] >> 21);
auto can_data = event.initCan(big_recv/0x10);

// populate message
for (int i = 0; i<(big_recv/0x10); i++) {
if (big_data[i*4] & 4) {
// extended
can_data[i].setAddress(big_data[i*4] >> 3);
//printf("got extended: %x\n", big_data[i*4] >> 3);
} else {
// normal
can_data[i].setAddress(big_data[i*4] >> 21);
}
can_data[i].setBusTime(big_data[i*4+1] >> 16);
int len = big_data[i*4+1]&0xF;
can_data[i].setDat(kj::arrayPtr((uint8_t*)&big_data[i*4+2], len));
can_data[i].setSrc((big_data[i*4+1] >> 4) & 0xff);
}
canData[i].setBusTime(data[i*4+1] >> 16);
int len = data[i*4+1]&0xF;
canData[i].setDat(kj::arrayPtr((uint8_t*)&data[i*4+2], len));
canData[i].setSrc((data[i*4+1] >> 4) & 0xff);

// send to can
auto words = capnp::messageToFlatArray(msg);
auto bytes = words.asBytes();
zmq_send(s, bytes.begin(), bytes.size(), 0);
big_recv = 0;
}

// send to can
auto words = capnp::messageToFlatArray(msg);
auto bytes = words.asBytes();
zmq_send(s, bytes.begin(), bytes.size(), 0);
return frame_sent;
}

void can_health(void *s) {
Expand Down Expand Up @@ -456,11 +476,53 @@ void *can_recv_thread(void *crap) {
void *publisher = zmq_socket(context, ZMQ_PUB);
zmq_bind(publisher, "tcp://*:8006");

// run at ~200hz
bool frame_sent, skip_once, force_send;
uint64_t wake_time, cur_time, last_long_sleep;
int recv_state = 0;
force_send = true;
last_long_sleep = 1e-3 * nanos_since_boot();
wake_time = last_long_sleep;

while (!do_exit) {
can_recv(publisher);
// 5ms
usleep(5*1000);

frame_sent = can_recv(publisher, force_send);

// drain the Panda twice at 4.5ms intervals, then once at 1.0ms interval (twice max if sync_id is set)
if (recv_state++ < 2) {
last_long_sleep = 1e-3 * nanos_since_boot();
wake_time += 4500;
force_send = false;
if (last_long_sleep < wake_time) {
usleep(wake_time - last_long_sleep);
}
else {
if ((last_long_sleep - wake_time) > 5e5) {
// probably a new drive
wake_time = last_long_sleep;
}
else {
if (recv_state < 2) {
wake_time += 4500;
recv_state++;
if (last_long_sleep < wake_time) {
usleep(wake_time - last_long_sleep);
}
else {
printf(" lagging!\n");
}
}
}
}
}
else {
force_send = true;
recv_state = 0;
wake_time += 1000;
cur_time = 1e-3 * nanos_since_boot();
if (wake_time > cur_time) {
usleep(wake_time - cur_time);
}
}
}
return NULL;
}
Expand Down Expand Up @@ -644,7 +706,7 @@ int main() {
LOGW("starting boardd");

// set process priority
err = set_realtime_priority(4);
err = set_realtime_priority(3);
LOG("setpriority returns %d", err);

// check the environment
Expand Down
14 changes: 9 additions & 5 deletions selfdrive/can/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,19 @@ class CANParser {

// multiple recv is fine
bool first = wait;
while (1) {
while (first || drain) {
if (first) {
err = zmq_msg_recv(&msg, subscriber, 0);
first = false;
} else {
// Drain the queue at startup
usleep(500);
err = zmq_msg_recv(&msg, subscriber, ZMQ_DONTWAIT);
}
if (err < 0) break;

if (err < 0) {
drain = false;
break;
}
// format for board, make copy due to alignment issues, will be freed on out of scope
auto amsg = kj::heapArray<capnp::word>((zmq_msg_size(&msg) / sizeof(capnp::word)) + 1);
memcpy(amsg.begin(), zmq_msg_data(&msg), zmq_msg_size(&msg));
Expand All @@ -354,10 +358,9 @@ class CANParser {
auto cans = event.getCan();

UpdateCans(sec, cans);
UpdateValid(sec);
}

UpdateValid(sec);

zmq_msg_close(&msg);
}

Expand Down Expand Up @@ -386,6 +389,7 @@ class CANParser {

private:
const int bus;
bool drain = true;
// zmq vars
void *context = NULL;
void *subscriber = NULL;
Expand Down
4 changes: 3 additions & 1 deletion selfdrive/car/chrysler/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def get_params(candidate, fingerprint):
ret.steerKf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594
ret.steerActuatorDelay = 0.1
ret.steerRateCost = 0.7
ret.steerMPCReactTime = 0.025 # increase total MPC projected time by 25 ms
ret.steerMPCDampTime = 0.25 # dampen desired angle over 250ms (5 mpc cycles)

if candidate == CAR.JEEP_CHEROKEE:
ret.wheelbase = 2.91 # in meters
Expand Down Expand Up @@ -138,7 +140,7 @@ def update(self, c):
# ******************* do can recv *******************
canMonoTimes = []

self.cp.update(int(sec_since_boot() * 1e9), False)
self.cp.update(int(sec_since_boot() * 1e9), True)

self.CS.update(self.cp)

Expand Down
Loading