Skip to content

Commit

Permalink
make flowpilot compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
MankaranSingh committed Sep 15, 2022
2 parents bd2f7fa + f3503b8 commit ee4dfbf
Show file tree
Hide file tree
Showing 43 changed files with 1,465 additions and 2,909 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ __pycache__
*.os
*.o
*.a
build
bin
.gradle

test_runner

Expand Down
34 changes: 6 additions & 28 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import shutil

cereal_dir = Dir('.')
gen_dir = Dir('gen')
java_gen_dir = Dir('java/ai.flow.definitions')
messaging_dir = Dir('messaging')

# Build cereal
Expand All @@ -13,6 +14,11 @@ env.Command(["gen/c/include/c++.capnp.h"], [], "mkdir -p " + gen_dir.path + "/c/
env.Command([f'gen/cpp/{s}.c++' for s in schema_files] + [f'gen/cpp/{s}.h' for s in schema_files],
schema_files,
f"capnpc --src-prefix={cereal_dir.path} $SOURCES -o c++:{gen_dir.path}/cpp/")

java_outs = ["Definitions.java", "CarDefinitions.java", "Legacy.java"]
env.Command([f'java/ai.flow.definitions/{out}' for out in java_outs],
schema_files,
f"capnpc --src-prefix={cereal_dir.path} $SOURCES -ojava:{java_gen_dir.path}")

# TODO: remove non shared cereal and messaging
cereal_objects = env.SharedObject([f'gen/cpp/{s}.c++' for s in schema_files])
Expand Down Expand Up @@ -41,34 +47,6 @@ Depends('messaging/bridge.cc', services_h)
envCython.Program('messaging/messaging_pyx.so', 'messaging/messaging_pyx.pyx', LIBS=envCython["LIBS"]+[messaging_lib, "zmq", common])


# Build Vision IPC
vipc_sources = [
'visionipc/ipc.cc',
'visionipc/visionipc_server.cc',
'visionipc/visionipc_client.cc',
'visionipc/visionbuf.cc',
]

if arch == "larch64":
vipc_sources += ['visionipc/visionbuf_ion.cc']
else:
vipc_sources += ['visionipc/visionbuf_cl.cc']

vipc_objects = env.SharedObject(vipc_sources)
vipc = env.Library('visionipc', vipc_objects)


vipc_frameworks = []
vipc_libs = envCython["LIBS"] + [vipc, messaging_lib, common, "zmq"]
if arch == "Darwin":
vipc_frameworks.append('OpenCL')
else:
vipc_libs.append('OpenCL')
envCython.Program('visionipc/visionipc_pyx.so', 'visionipc/visionipc_pyx.pyx',
LIBS=vipc_libs, FRAMEWORKS=vipc_frameworks)

if GetOption('test'):
env.Program('messaging/test_runner', ['messaging/test_runner.cc', 'messaging/msgq_tests.cc'], LIBS=[messaging_lib, common])

env.Program('visionipc/test_runner', ['visionipc/test_runner.cc', 'visionipc/visionipc_tests.cc'],
LIBS=['pthread'] + vipc_libs, FRAMEWORKS=vipc_frameworks)
23 changes: 23 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
plugins {
id 'java-library'
}

repositories {
mavenCentral()
}

sourceSets {
main {
java {
srcDirs = ['java']
}
resources {
srcDirs = ['resources']
}
}
}

dependencies {
implementation 'org.capnproto:runtime:0.1.13'
implementation project(path: ':messaging')
}
78 changes: 30 additions & 48 deletions car.capnp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using Cxx = import "./include/c++.capnp";
$Cxx.namespace("cereal");

using Java = import "./include/java.capnp";
$Java.package("ai.flow.definitions");
$Java.outerClassname("CarDefinitions");

@0x8e2af1e708af8b8d;

# ******* events causing controls state machine transition *******
Expand All @@ -17,8 +21,7 @@ struct CarEvent @0x9b1657f34caf3ad3 {
immediateDisable @6 :Bool;
preEnable @7 :Bool;
permanent @8 :Bool; # alerts presented regardless of openpilot state
overrideLateral @10 :Bool;
overrideLongitudinal @9 :Bool;
override @9 :Bool;

enum EventName @0xbaa8c5d505f727de {
canError @0;
Expand All @@ -36,7 +39,6 @@ struct CarEvent @0x9b1657f34caf3ad3 {
pedalPressed @13; # exits active state
pedalPressedPreEnable @73; # added during pre-enable state for either pedal
gasPressedOverride @108; # added when user is pressing gas with no disengage on gas
steerOverride @114;
cruiseDisabled @14;
speedTooLow @17;
outOfSpace @18;
Expand Down Expand Up @@ -113,7 +115,6 @@ struct CarEvent @0x9b1657f34caf3ad3 {
lkasDisabled @107;
canBusMissing @111;
controlsdLagging @112;
resumeBlocked @113;

radarCanErrorDEPRECATED @15;
communityFeatureDisallowedDEPRECATED @62;
Expand Down Expand Up @@ -151,11 +152,9 @@ struct CarState {
canTimeout @40 :Bool; # CAN bus dropped out

# car speed
vEgo @1 :Float32; # best estimate of speed
aEgo @16 :Float32; # best estimate of acceleration
vEgoRaw @17 :Float32; # unfiltered speed from CAN sensors
vEgoCluster @44 :Float32; # best estimate of speed shown on car's instrument cluster, used for UI

vEgo @1 :Float32; # best estimate of speed
aEgo @16 :Float32; # best estimate of acceleration
vEgoRaw @17 :Float32; # unfiltered speed from CAN sensors
yawRate @22 :Float32; # best estimate of yaw rate
standstill @18 :Bool;
wheelSpeeds @2 :WheelSpeeds;
Expand All @@ -177,12 +176,12 @@ struct CarState {
steeringTorque @8 :Float32; # TODO: standardize units
steeringTorqueEps @27 :Float32; # TODO: standardize units
steeringPressed @9 :Bool; # if the user is using the steering wheel
steeringRateLimited @29 :Bool; # if the torque is limited by the rate limiter
steerFaultTemporary @35 :Bool; # temporary EPS fault
steerFaultPermanent @36 :Bool; # permanent EPS fault
stockAeb @30 :Bool;
stockFcw @31 :Bool;
espDisabled @32 :Bool;
accFaulted @42 :Bool;

# cruise state
cruiseState @10 :CruiseState;
Expand Down Expand Up @@ -211,7 +210,6 @@ struct CarState {
rightBlindspot @34 :Bool; # Is there something blocking the right lane change

fuelGauge @41 :Float32; # battery or fuel tank level from 0.0 to 1.0
charging @43 :Bool;

struct WheelSpeeds {
# optional wheel speeds
Expand All @@ -224,7 +222,6 @@ struct CarState {
struct CruiseState {
enabled @0 :Bool;
speed @1 :Float32;
speedCluster @6 :Float32; # Set speed as shown on instrument cluster
available @2 :Bool;
speedOffset @3 :Float32;
standstill @4 :Bool;
Expand Down Expand Up @@ -267,7 +264,6 @@ struct CarState {

errorsDEPRECATED @0 :List(CarEvent.EventName);
brakeLightsDEPRECATED @19 :Bool;
steeringRateLimitedDEPRECATED @29 :Bool;
}

# ******* radar state @ 20hz *******
Expand Down Expand Up @@ -342,16 +338,17 @@ struct CarControl {
off @0;
pid @1;
stopping @2;
starting @3;

startingDEPRECATED @3;
}

}

struct CruiseControl {
cancel @0: Bool;
resume @1: Bool;
speedOverrideDEPRECATED @2: Float32;
accelOverrideDEPRECATED @3: Float32;
override @1: Bool;
speedOverride @2: Float32;
accelOverride @3: Float32;
}

struct HUDControl {
Expand Down Expand Up @@ -418,17 +415,19 @@ struct CarParams {
enableApgs @6 :Bool; # advanced parking guidance system
enableBsm @56 :Bool; # blind spot monitoring
flags @64 :UInt32; # flags for car specific quirks
experimentalLongitudinalAvailable @71 :Bool;

minEnableSpeed @7 :Float32;
minSteerSpeed @8 :Float32;
maxSteeringAngleDeg @54 :Float32;
safetyConfigs @62 :List(SafetyConfig);
alternativeExperience @65 :Int16; # panda flag for features like no disengage on gas

# Car docs fields
maxLateralAccel @68 :Float32;
autoResumeSng @69 :Bool; # describes whether car can resume from a stop automatically
steerMaxBPDEPRECATED @11 :List(Float32);
steerMaxVDEPRECATED @12 :List(Float32);
gasMaxBPDEPRECATED @13 :List(Float32);
gasMaxVDEPRECATED @14 :List(Float32);
brakeMaxBPDEPRECATED @15 :List(Float32);
brakeMaxVDEPRECATED @16 :List(Float32);

# things about the car in the manual
mass @17 :Float32; # [kg] curb weight: all fluids no cargo
Expand Down Expand Up @@ -457,13 +456,12 @@ struct CarParams {
vEgoStopping @29 :Float32; # Speed at which the car goes into stopping state
vEgoStarting @59 :Float32; # Speed at which the car goes into starting state
directAccelControl @30 :Bool; # Does the car have direct accel control or just gas/brake
stoppingControl @31 :Bool; # Does the car allow full control even at lows speeds when stopping
stoppingControl @31 :Bool; # Does the car allows full control even at lows speeds when stopping
stopAccel @60 :Float32; # Required acceleraton to keep vehicle stationary
steerRateCost @33 :Float32; # Lateral MPC cost on steering rate
steerControlType @34 :SteerControlType;
radarOffCan @35 :Bool; # True when radar objects aren't visible on CAN
stopAccel @60 :Float32; # Required acceleration to keep vehicle stationary
stoppingDecelRate @52 :Float32; # m/s^2/s while trying to stop
startAccel @32 :Float32; # Required acceleration to get car moving
startingState @70 :Bool; # Does this car make use of special starting state

steerActuatorDelay @36 :Float32; # Steering wheel actuator delay in seconds
longitudinalActuatorDelayLowerBound @61 :Float32; # Gas/Brake actuator delay in seconds, lower bound
Expand All @@ -482,9 +480,8 @@ struct CarParams {

struct SafetyConfig {
safetyModel @0 :SafetyModel;
safetyParam @3 :UInt16;
safetyParam @2 :UInt32;
safetyParamDEPRECATED @1 :Int16;
safetyParam2DEPRECATED @2 :UInt32;
}

struct LateralParams {
Expand All @@ -506,7 +503,6 @@ struct CarParams {
ki @2 :Float32;
friction @3 :Float32;
kf @4 :Float32;
steeringAngleDeadzoneDeg @5 :Float32;
}

struct LongitudinalPIDTuning {
Expand Down Expand Up @@ -575,10 +571,9 @@ struct CarParams {
subaruLegacy @22; # pre-Global platform
hyundaiLegacy @23;
hyundaiCommunity @24;
stellantisDEPRECATED @25; # Consolidated with Chrysler; may be recycled for the next new model
hongqi @26;
stellantis @25;
faw @26;
body @27;
hyundaiCanfd @28;
}

enum SteerControlType {
Expand All @@ -597,17 +592,13 @@ struct CarParams {
struct CarFw {
ecu @0 :Ecu;
fwVersion @1 :Data;
address @2 :UInt32;
subAddress @3 :UInt8;
responseAddress @4 :UInt32;
request @5 :List(Data);
brand @6 :Text;
bus @7 :UInt8;
address @2: UInt32;
subAddress @3: UInt8;
}

enum Ecu {
eps @0;
abs @1;
esp @1;
fwdRadar @2;
fwdCamera @3;
engine @4;
Expand All @@ -628,9 +619,6 @@ struct CarParams {
electricBrakeBooster @15;
shiftByWire @16;

# Chrysler only
hcp @18; # Hybrid Control Processor

debug @17;
}

Expand All @@ -646,19 +634,13 @@ struct CarParams {
}

enableCameraDEPRECATED @4 :Bool;
steerRateCostDEPRECATED @33 :Float32;
isPandaBlackDEPRECATED @39 :Bool;
hasStockCameraDEPRECATED @57 :Bool;
safetyParamDEPRECATED @10 :Int16;
safetyModelDEPRECATED @9 :SafetyModel;
safetyModelPassiveDEPRECATED @42 :SafetyModel = silent;
minSpeedCanDEPRECATED @51 :Float32;
startAccelDEPRECATED @32 :Float32;
communityFeatureDEPRECATED @46: Bool;
startingAccelRateDEPRECATED @53 :Float32;
steerMaxBPDEPRECATED @11 :List(Float32);
steerMaxVDEPRECATED @12 :List(Float32);
gasMaxBPDEPRECATED @13 :List(Float32);
gasMaxVDEPRECATED @14 :List(Float32);
brakeMaxBPDEPRECATED @15 :List(Float32);
brakeMaxVDEPRECATED @16 :List(Float32);
}
7 changes: 7 additions & 0 deletions include/java.capnp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@0xc5f1af96651f70ea;

annotation package @0x9ee4c8f803b3b596 (file) : Text;
# Name of the package, such as "org.example.foo", in which the generated code will reside.

annotation outerClassname @0x9b066bb4881f7cd3 (file) : Text;
# Name of the outer class that will wrap the generated code.
3 changes: 3 additions & 0 deletions java/ai.flow.definitions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CarDefinitions.java
Definitions.java
Legacy.java
Loading

0 comments on commit ee4dfbf

Please sign in to comment.