Skip to content

Commit

Permalink
Merge remote-tracking branch 'commaai/panda/master' into camera-scc-long
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Oct 19, 2022
2 parents c68c2dc + b95a65d commit 638d94d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 45 deletions.
64 changes: 37 additions & 27 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
name: tests
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/master' && github.ref || github.run_id }}-${{ github.event_name }}
cancel-in-progress: true

env:
RUN: docker run --rm panda /bin/bash -c
PERSIST: docker run --name panda panda /bin/sh -c
RUN: docker run -v $GITHUB_WORKSPACE:/tmp/openpilot/panda -w /tmp/openpilot/panda --rm panda /bin/bash -c
PERSIST: docker run -v $GITHUB_WORKSPACE:/tmp/openpilot/panda -w /tmp/openpilot/panda --name panda panda /bin/bash -c
BUILD: |
docker pull $(grep -ioP '(?<=^from)\s+\S+' Dockerfile.panda) || true
docker pull ghcr.io/commaai/panda:latest || true
docker build --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile.panda .
export DOCKER_BUILDKIT=1
docker build --pull --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from ghcr.io/commaai/panda:latest -t panda -f Dockerfile.panda .
jobs:
docker_push:
name: docker push
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/panda'
steps:
- uses: actions/checkout@v2
- name: Build Docker image
timeout-minutes: 11
run: eval "$BUILD"
- name: Login to dockerhub
run: docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -29,69 +33,71 @@ jobs:
build:
name: build
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Test python package installer
run: $RUN "cd /tmp/openpilot/panda && python setup.py install"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && python setup.py install"
- name: Build panda STM image and bootstub
run: $RUN "cd /tmp/openpilot/panda && scons"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && scons"
- name: Build pedal STM image and bootstub
run: $RUN "cd /tmp/openpilot/panda && PEDAL=1 scons"
run: ${{ env.RUN }} "cd /tmp/openpilot/panda && PEDAL=1 scons"

unit_tests:
name: unit tests
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Test pack/unpack for USB protocol
run: $RUN "cd /tmp/openpilot/panda/tests/usbprotocol &&
run: ${{ env.RUN }} "cd /tmp/openpilot/panda/tests/usbprotocol &&
python -m unittest discover ."

safety:
name: safety
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety tests
timeout-minutes: 3
run: |
$RUN "cd /tmp/openpilot && \
scons -c && \
scons -j$(nproc) opendbc/ cereal/ && \
cd panda/tests/safety && \
./test.sh"
${{ env.RUN }} "cd /tmp/openpilot && \
scons -c && \
scons -j$(nproc) opendbc/ cereal/ && \
cd panda/tests/safety && \
./test.sh"
safety_replay:
name: safety replay
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety replay
run: $RUN "cd /tmp/openpilot/panda/tests/safety_replay &&
scons -u --test .. &&
./test_safety_replay.py"
run: ${{ env.RUN }} "cd tests/safety_replay &&
scons -u --test .. &&
./test_safety_replay.py"

misra:
name: misra c2012
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run Misra C 2012 analysis
run: $PERSIST "cd /tmp/openpilot/panda/tests/misra && ./test_misra.sh"
timeout-minutes: 4
run: ${{ env.PERSIST }} "cd tests/misra && ./test_misra.sh"
- name: Copy analysis outputs
run: docker cp panda:/tmp/misra /tmp
- uses: actions/upload-artifact@v2
Expand All @@ -104,15 +110,19 @@ jobs:
with:
name: misra_output
path: /tmp/misra/misra_*_output.txt
- run: docker rm panda
if: always()

python_linter:
name: python linter
runs-on: ubuntu-20.04
timeout-minutes: 45
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run static analysis
run: |
$RUN "cd /tmp/openpilot/panda && git init && git add -A && pre-commit run --all"
timeout-minutes: 3
run: ${{ env.RUN }} "pre-commit run --all"


14 changes: 8 additions & 6 deletions Dockerfile.panda
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
unzip \
wget \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/* && \
cd /usr/lib/gcc/arm-none-eabi/9.2.1 && \
rm -rf arm/ && \
rm -rf thumb/nofp thumb/v6* thumb/v8* thumb/v7+fp thumb/v7-r+fp.sp

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && locale-gen
ENV LANG en_US.UTF-8
Expand All @@ -56,13 +59,15 @@ RUN pyenv install 3.8.10 && \
pyenv rehash && \
pip install --no-cache-dir -r /tmp/requirements.txt

ENV CPPCHECK_DIR=/tmp/cppcheck
COPY tests/misra/install.sh /tmp/
RUN /tmp/install.sh

RUN git config --global --add safe.directory /tmp/openpilot/panda
RUN cd /tmp && \
git clone https://github.com/commaai/openpilot.git tmppilot || true && \
cd /tmp/tmppilot && \
git fetch && \
git fetch origin $OPENPILOT_REF && \
git checkout $OPENPILOT_REF && \
git submodule update --init cereal opendbc rednose_repo && \
git -C opendbc fetch && \
Expand All @@ -71,12 +76,9 @@ RUN cd /tmp && \
git -C opendbc clean -xfd && \
mkdir /tmp/openpilot && \
cp -pR SConstruct site_scons/ tools/ selfdrive/ system/ common/ cereal/ opendbc/ rednose/ third_party/ /tmp/openpilot && \
rm -rf /tmp/openpilot/panda && \
rm -rf /tmp/tmppilot

RUN cd /tmp/openpilot && \
pip install --no-cache-dir -r opendbc/requirements.txt && \
pip install --no-cache-dir --upgrade aenum lru-dict pycurl tenacity atomicwrites serial smbus2 scons

COPY . /tmp/openpilot/panda
RUN mv /tmp/cppcheck /tmp/openpilot/panda/tests/misra && \
rm -rf /tmp/openpilot/panda/.git
9 changes: 6 additions & 3 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const int GM_MAX_RATE_DOWN = 17;
const int GM_DRIVER_TORQUE_ALLOWANCE = 50;
const int GM_DRIVER_TORQUE_FACTOR = 4;

const int GM_STANDSTILL_THRSLD = 10; // 0.311kph

const int GM_MAX_GAS = 3072;
const int GM_MAX_REGEN = 1404;
const int GM_MAX_BRAKE = 400;
Expand Down Expand Up @@ -67,10 +69,11 @@ static int gm_rx_hook(CANPacket_t *to_push) {
update_sample(&torque_driver, torque_driver_new);
}

// sample speed, really only care if car is moving or not
// rear left wheel speed
// sample rear wheel speeds
if (addr == 842) {
vehicle_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1);
int left_rear_speed = (GET_BYTE(to_push, 0) << 8) | GET_BYTE(to_push, 1);
int right_rear_speed = (GET_BYTE(to_push, 2) << 8) | GET_BYTE(to_push, 3);
vehicle_moving = (left_rear_speed > GM_STANDSTILL_THRSLD) || (right_rear_speed > GM_STANDSTILL_THRSLD);
}

// ACC steering wheel buttons (GM_CAM is tied to the PCM)
Expand Down
13 changes: 10 additions & 3 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const SteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = {
.driver_torque_allowance = 250,
.driver_torque_factor = 2,
.type = TorqueDriverLimited,

// the EPS faults when the steering angle is above a certain threshold for too long. to prevent this,
// we allow setting torque actuation bit to 0 while maintaining the requested torque value for two consecutive frames
.min_valid_request_frames = 89,
.max_invalid_request_frames = 2,
.min_valid_request_rt_interval = 810000, // 810ms; a ~10% buffer on cutting every 90 frames
.has_steer_req_tolerance = true,
};

const CanMsg HYUNDAI_CANFD_HDA2_TX_MSGS[] = {
Expand Down Expand Up @@ -205,10 +212,10 @@ static int hyundai_canfd_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed
// steering
const int steer_addr = (hyundai_canfd_hda2 && !hyundai_longitudinal) ? 0x50 : 0x12a;
if (addr == steer_addr) {
int desired_torque = ((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U);
desired_torque -= 1024;
int desired_torque = (((GET_BYTE(to_send, 6) & 0xFU) << 7U) | (GET_BYTE(to_send, 5) >> 1U)) - 1024U;
bool steer_req = GET_BIT(to_send, 52U) != 0U;

if (steer_torque_cmd_checks(desired_torque, -1, HYUNDAI_CANFD_STEERING_LIMITS)) {
if (steer_torque_cmd_checks(desired_torque, steer_req, HYUNDAI_CANFD_STEERING_LIMITS)) {
tx = 0;
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/misra/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
: "${CPPCHECK_DIR:=$DIR/cppcheck/}"

cd $DIR
if [ ! -d cppcheck/ ]; then
git clone https://github.com/danmar/cppcheck.git
if [ ! -d "$CPPCHECK_DIR" ]; then
git clone https://github.com/danmar/cppcheck.git $CPPCHECK_DIR
fi

cd cppcheck
cd $CPPCHECK_DIR
git fetch
git checkout e1cff1d1ef92f6a1c6962e0e4153b7353ccad04c
git -c user.name=a -c user.email="a@b.c" cherry-pick 7199dde1618b5166735f07619dcdb9f4eafdb557
Expand Down
2 changes: 1 addition & 1 deletion tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Buttons:


class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
STANDSTILL_THRESHOLD = 0
STANDSTILL_THRESHOLD = 10 * 0.0311
RELAY_MALFUNCTION_ADDR = 384
RELAY_MALFUNCTION_BUS = 0
BUTTONS_BUS = 0
Expand Down
7 changes: 6 additions & 1 deletion tests/safety/test_hyundai_canfd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class TestHyundaiCanfdBase(HyundaiButtonBase, common.PandaSafetyTest, common.Dri
DRIVER_TORQUE_ALLOWANCE = 250
DRIVER_TORQUE_FACTOR = 2

# Safety around steering req bit
MIN_VALID_STEERING_FRAMES = 89
MAX_INVALID_STEERING_FRAMES = 2
MIN_VALID_STEERING_RT_INTERVAL = 810000 # a ~10% buffer, can send steer up to 110Hz

PT_BUS = 0
STEER_BUS = 0
STEER_MSG = ""
Expand All @@ -41,7 +46,7 @@ def _torque_driver_msg(self, torque):
return self.packer.make_can_msg_panda("MDPS", self.PT_BUS, values)

def _torque_cmd_msg(self, torque, steer_req=1):
values = {"TORQUE_REQUEST": torque}
values = {"TORQUE_REQUEST": torque, "STEER_REQ": steer_req}
return self.packer.make_can_msg_panda(self.STEER_MSG, self.STEER_BUS, values)

def _speed_msg(self, speed):
Expand Down

0 comments on commit 638d94d

Please sign in to comment.