Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Bidault committed Aug 27, 2018
2 parents b63df21 + cfd65d8 commit 4601a68
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 86 deletions.
9 changes: 2 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ target_link_libraries(

endif()

if(APOLLO)
if(KIA_SOUL_EV)
if(APOLLO AND (KIA_SOUL_EV OR KIA_NIRO))

find_package(catkin
REQUIRED COMPONENTS
Expand All @@ -188,7 +187,6 @@ add_library(
link_directories(
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/canbus/
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/control/
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/localization/
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/common/proto
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/drivers/canbus/common/
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/drivers/canbus/proto/
Expand All @@ -202,6 +200,7 @@ add_executable(
target_include_directories(
${PROJECT_NAME}_apollo PUBLIC
include
oscc/api/include
)

add_dependencies(
Expand All @@ -217,13 +216,10 @@ target_link_libraries(
${PROJECT_NAME}_pid_control
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/canbus/proto/libcanbus_proto_lib.a
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/control/proto/libcontrol_proto_lib.a
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/localization/proto/liblocalization_proto_lib.a
/apollo/bazel-apollo/bazel-out/local-dbg/bin/modules/localization/proto/libpose_proto_lib.a
canbus_proto_lib
protobuf
canbus_lib
control_lib
localization_lib
canbus_common
vehicle_signal_proto_lib
pnc_point_proto_lib
Expand All @@ -235,7 +231,6 @@ target_link_libraries(
vehicle_state_proto_lib
)

endif()
endif()

#############
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:16.04

WORKDIR /app

# common packages
RUN apt-get update && \
apt-get install -y \
build-essential cmake git wget && \
rm -rf /var/lib/apt/lists/*

# add ROS packages to apt package manager
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu xenial main" > /etc/apt/sources.list.d/ros-latest.list'

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

# install ros
RUN apt-get update && \
apt-get install -y ros-kinetic-ros-base

# install arduino toolchain
RUN wget -nv http://arduino.cc/download.php?f=/arduino-1.8.5-linux64.tar.xz -O arduino-1.8.5.tar.xz

RUN tar -xf arduino-1.8.5.tar.xz && \
cd arduino-1.8.5 && \
mkdir -p /usr/share/arduino && \
cp -R * /usr/share/arduino
97 changes: 60 additions & 37 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,66 @@
#!groovy
node('xenial') {
try {
stage('Checkout') {
sh 'mkdir -p catkin_ws/src/roscco'
dir('catkin_ws/src/roscco')
{
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: false,
extensions: scm.extensions + [[$class: 'CleanBeforeCheckout'],
[$class: 'SubmoduleOption',
disableSubmodules: false,
parentCredentials: true,
recursiveSubmodules: true,
reference: '',
trackingSubmodules: false]],
submoduleCfg: [],
userRemoteConfigs: scm.userRemoteConfigs
])
}

node() {
def builds = [:]
def platforms = [:]

sh 'mkdir -p catkin_ws/src/roscco'
dir('catkin_ws/src/roscco') {
checkout scm
sh "git submodule update --init --recursive"

def image = docker.build("catkin_make-build:${env.BUILD_ID}")


def output = image.inside {
sh returnStdout: true, script: "cmake -LA ./oscc/firmware | grep 'VEHICLE_VALUES' | cut -d'=' -f 2"
}

platforms = output.trim().tokenize(';')\
}
stage('Build') {
parallel 'kia soul firmware': {
sh '. /opt/ros/kinetic/setup.sh && cd catkin_ws && catkin_make -DKIA_SOUL=ON'
}
echo 'Build Complete!'

for(int j=0; j<platforms.size(); j++) {
def platform_idx = j
def platform = platforms[platform_idx]
builds[platform] = {
node {
sh 'mkdir -p catkin_ws/src/roscco'
dir('catkin_ws/src/roscco') {
checkout scm
sh "git submodule update --init --recursive"
}

image = docker.build("catkin_make-build:${env.BUILD_ID}", "./catkin_ws/src/roscco")

stage("Build ${platform}"){
image.inside {
sh ". /opt/ros/kinetic/setup.sh && \
cd catkin_ws && \
catkin_make -DVEHICLE=${platform}"

echo "${platform}: Build Complete!"
}
}

def workspace = pwd()

stage("Test ${platform}"){
image.inside{
sh ". /opt/ros/kinetic/setup.sh && \
cd catkin_ws && \
ROS_HOME=${workspace} ROS_LOG_DIR=${workspace} catkin_make run_tests -DVEHICLE=${platform} && \
catkin_test_results --verbose"
}
}
}
}
}
stage('Test') {
parallel 'kia soul tests': {
sh '. /opt/ros/kinetic/setup.sh && cd catkin_ws && catkin_make run_tests -DKIA_SOUL=ON && catkin_test_results'
echo 'ROS Tests Complete!'
}

try {
parallel builds
}
stage('Release') {
echo 'Release Package Created!'
finally {
deleteDir()
}
}
finally {
deleteDir()
}

}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for roscco_node and the roscco_node sends it's received messages to OSCC API.
ROSCCO can serve as a bridge to Baidu's open autonomous driving platform Apollo.

This example only support the Kia Soul EV. We are planning on extending support to the Kia Niro.
You will need a double channel Kvaser or two single channel Kvaser, can0 will be drivekit CAN and can1 will be diagnostics CAN.
You will need a double channel Kvaser or two single channel Kvaser, to connect to drivekit CAN and diagnostics CAN.

#### Installation and build

Expand Down
54 changes: 28 additions & 26 deletions example/roscco_apollo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ RosccoApollo::RosccoApollo()
steering_sub = nh.subscribe( "/apollo/control", 1, &RosccoApollo::steeringCallback, this );
brake_sub = nh.subscribe( "/apollo/control", 1, &RosccoApollo::brakeCallback, this );
throttle_sub = nh.subscribe( "/apollo/control", 1, &RosccoApollo::throttleCallback, this );
localization_sub = nh.subscribe( "/apollo/localization/pose", 1, &RosccoApollo::localizationCallback, this );

can_frame_sub = nh.subscribe( "/can_frame", 1, &RosccoApollo::EVCanFrameCallback, this );
can_frame_sub = nh.subscribe( "/can_frame", 1, &RosccoApollo::canFrameCallback, this );
}


Expand Down Expand Up @@ -50,27 +49,35 @@ void RosccoApollo::throttleCallback( const apollo::control::ControlCommand& inpu
}


void RosccoApollo::EVCanFrameCallback( const roscco::CanFrame& input )
void RosccoApollo::canFrameCallback( const roscco::CanFrame& input )
{
switch( input.frame.can_id )
{
case 512:
case KIA_SOUL_OBD_THROTTLE_PRESSURE_CAN_ID:
{
throttle_report = input.frame.data[4];
#if defined( KIA_SOUL_EV )
throttle_report = input.frame.data[4];
#elif defined( KIA_NIRO )
throttle_report = input.frame.data[7];
#endif

throttle_report = throttle_report * THROTTLE_RATIO;

break;
}
case 544:
case KIA_SOUL_OBD_BRAKE_PRESSURE_CAN_ID:
{
brake_report = input.frame.data[4] + input.frame.data[5] * 256;
#if defined( KIA_SOUL_EV )
brake_report = input.frame.data[4] + input.frame.data[5] * 256;
#elif defined( KIA_NIRO )
brake_report = input.frame.data[3] + input.frame.data[4] * 256;
#endif

brake_report = brake_report * EV_BRAKE_RATIO;
brake_report = brake_report * BRAKE_RATIO;

break;
}
case 688:
case KIA_SOUL_OBD_STEERING_WHEEL_ANGLE_CAN_ID:
{
steering_angle_report = input.frame.data[0] + input.frame.data[1] * 256;

Expand All @@ -83,17 +90,19 @@ void RosccoApollo::EVCanFrameCallback( const roscco::CanFrame& input )

break;
}
case 1200:
case KIA_SOUL_OBD_SPEED_CAN_ID:
{
speed_report = input.frame.data[0] + input.frame.data[2]
+ input.frame.data[4] + input.frame.data[6];
#if defined( KIA_SOUL_EV )
speed_report = input.frame.data[3] + input.frame.data[2] * 128;

speed_report += ( input.frame.data[1] + input.frame.data[3]
+ input.frame.data[5] + input.frame.data[7] ) * 256;
speed_report = speed_report * SPEED_RATIO;

speed_report = speed_report / 4;
#elif defined( KIA_NIRO )
speed_report = input.frame.data[0];

speed_report = speed_report * EV_SPEED_RATIO;
speed_report = speed_report * SPEED_RATIO;

#endif

break;
}
Expand All @@ -115,13 +124,6 @@ void RosccoApollo::EVCanFrameCallback( const roscco::CanFrame& input )
}


void RosccoApollo::localizationCallback( const apollo::localization::LocalizationEstimate& input )
{
std::cout << std::to_string( input.pose().position().x() ) << ", "
<< std::to_string( input.pose().position().y() ) << "\n";
}


void closedLoopControl( double setpoint,
roscco::SteeringCommand& output,
double steering_angle_report )
Expand All @@ -134,9 +136,9 @@ void closedLoopControl( double setpoint,
params.max = 1;
params.min = -1;
params.p_term = 0.016;
params.i_term = 0.0001;
params.d_term = 0.01;
params.i_max = 5000;
params.i_term = 0.004;
params.d_term = 0.001;
params.i_max = 250;

output.steering_torque = pidController( &params, &state, steering_angle_report );
}
Expand Down
22 changes: 9 additions & 13 deletions example/roscco_apollo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
#include <roscco/CanFrame.h>
#include <modules/canbus/proto/chassis.pb.h>
#include <modules/control/proto/control_cmd.pb.h>
#include <modules/localization/proto/localization.pb.h>
#include <roscco/pid_control.h>
#include <string>
#include <math.h>
#include <vehicles.h>

#define THROTTLE_RATIO 0.393
#define EV_BRAKE_RATIO 0.118
#define PETROL_BRAKE_RATIO 0.056
#define STEERING_RATIO 0.018
#define EV_SPEED_RATIO 0.003
#define PETROL_SPEED_RATIO 0.02

#if defined( KIA_SOUL_EV )
#define BRAKE_RATIO 0.12
#define SPEED_RATIO 0.002
#elif defined( KIA_NIRO )
#define BRAKE_RATIO 0.033
#define SPEED_RATIO 0.3
#endif

class RosccoApollo
{
Expand Down Expand Up @@ -57,14 +60,7 @@ class RosccoApollo
*
* @param roscco can frame message to be consumed
*/
void EVCanFrameCallback( const roscco::CanFrame& input );

/**
* @brief Callback function to log localization
*
* @param apollo localization message to be consumed
*/
void localizationCallback( const apollo::localization::LocalizationEstimate& input );
void canFrameCallback( const roscco::CanFrame& input );

ros::NodeHandle nh;

Expand Down
2 changes: 1 addition & 1 deletion test/test_oscc_to_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <roscco/oscc_to_ros.h>

// Time to allow ROS to process callbacks and publish a message
const double SLEEP_TIME = 0.02;
const double SLEEP_TIME = 0.05;

template <class T>
class MessageHelper
Expand Down

0 comments on commit 4601a68

Please sign in to comment.