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

update oscc to v1.2.4, add validation modifications #31

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
654e9ef
Update README with vehicle compatibility list
vertexmachina Nov 9, 2017
047933b
Add deadzone for steering joystick
vertexmachina Nov 29, 2017
f7d062c
Clear out exponential filter averages on disable
vertexmachina Nov 29, 2017
7ae3fd2
Update torque range to 20% of max range
Dec 8, 2017
75fd4fe
Fix typoo in documentation
Dec 8, 2017
da0fe09
Fix another typo
Dec 8, 2017
92b6dce
Merge remote-tracking branch 'origin/maint/update-torque-feel' into d…
vertexmachina Dec 13, 2017
ffeda9a
Merge 'origin/maint/update-readme' into devel
Dec 13, 2017
d8806e9
Merge 'origin/maint/zero-filters-on-disable' into devel
Dec 13, 2017
cd5bbf5
Add Jenkinsfile
Dec 14, 2017
21b5f03
Fix typo
Dec 14, 2017
90ecfbc
More carefully fix typoo because testing Jenkins locally is hard
Dec 14, 2017
83edf6a
Pull in OSCC repo for building
Dec 14, 2017
2f1377c
Remove unnecessary catch block
Jan 2, 2018
3b61d81
Merge 'origin/maint/add-jenkinsfile' into devel
Jan 2, 2018
f7cca5b
Make initialization of `joystick_data` explicit
Jan 16, 2018
752b391
Merge remote-tracking branch 'snewt/bug/explicit-joystick-data-init' …
Jan 24, 2018
9410337
Add OSCC configuration file
rebpdx Jun 7, 2018
0b2269a
Add OSCC submodule
rebpdx Jun 7, 2018
e1f0c70
Merge pull request #27 from PolySync/maint/update-cmake-config
Jun 7, 2018
9cae150
Merge pull request #30 from PolySync/master
cotos Oct 25, 2018
3454aa3
update oscc to v1.2.4, add validation modifictions
cotos Jul 9, 2019
45bc4c6
Updated README and LICENSE files
cotos Jul 10, 2019
2a60f8f
Update README.md
cotos Jul 10, 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: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "oscc"]
path = oscc
url = https://github.com/PolySync/oscc.git
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ project(oscc-joystick-commander)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)

if(KIA_SOUL)
add_definitions(-DKIA_SOUL)
elseif(KIA_SOUL_EV)
add_definitions(-DKIA_SOUL_EV)
endif()
include(oscc/api/OsccConfig.cmake)

add_executable(
oscc-joystick-commander
Expand All @@ -29,4 +25,3 @@ target_link_libraries(
oscc-joystick-commander
PRIVATE
${SDL2_LIBRARIES})

15 changes: 15 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!groovy
node('xenial') {
try {
stage('Checkout') {
clean_checkout()
}
stage('Build') {
sh 'git clone [email protected]:PolySync/oscc.git --branch master && mkdir build && cd build && cmake .. -DKIA_SOUL=ON && make'
echo 'Build Complete!'
}
}
finally {
deleteDir()
}
}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 PolySync Technologies
Copyright (c) 2019 PolySync Technologies

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
88 changes: 53 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<img src="https://raw.githubusercontent.com/wiki/PolySync/OSCC/images/oscc_logo_title.png">

# Joystick Commander

## Overview

Joystick commander is an example application designed to show how the Open Source Car Control API can be used to recieve reports from and send commands to a drive by-wire enabled vehicle.

Using an SDL2 supported game controller, inputs are normalized and converted to relative torque, throttle, and brake commands. This application also demonstrates registering callback functions to recieve and parse OSCC reports as well as vehicle state reports from the car's OBD-II CAN network.

For more information about OSCC, check out our [github](https://github.com/PolySync/oscc).


# Pre-requisites:
## Getting Started

These instructions have been tested with a new Ubuntu 18.04 installation.

- OSCC's API and firmware modules are both required, and the modules must be installed on the vehicle
- The socketcan driver for USB and PCIe CAN interfaces is required, and is pre-installed on most Linux systems
Expand All @@ -20,98 +26,110 @@ This application has been tested with a Logitech F310 gamepad and a wired Xbox 3

[Logitech Gamepad F310](http://a.co/3GoUlkN)

Install the SDL2 library with the command below.

```
sudo apt install libsdl2-dev
### 1. Install Dependencies

You will need several packages installed on your machine in order to build the oscc-joystick-commander application. Use the following command to install them using `apt`:

```sh
sudo apt install git cmake libsdl2-dev
```

### 2. Set up this repository locally

# Getting OSCC & Joystick Commander
Clone this repository to your machine, if you have not already done so:

If you haven't already, install the OSCC hardware modules onto the target vehicle.
```sh
# clone the repository
$ git clone [email protected]:PolySync/oscc-joystick-commander.git

Once the hardware is installed and the firmware is flashed, clone and enter the joystick commander repo:

```
git clone [email protected]:PolySync/oscc-joystick-commander.git
cd oscc-joystick-commander
# change the current directory to the repository
$ cd oscc-joystick-commander
```

From within the joystick commander directory, clone the OSCC repo:
Note: If you do not have a github account you will need to clone the repository using HTTPS.

```
git clone [email protected]:PolySync/oscc.git --branch master
Then, from within that directory, sync and initialize Git submodules:

```sh
$ git submodule sync
$ git submodule update --init --recursive
```

This will clone into a directory called `oscc` where CMake will look for the OSCC API when it builds joystick commander.
## Building Joystick Commander

### 1. CMake Configuration

# Building Joystick Commander
Before you can build the oscc-joystick-commander application, you must use cmake to configure the project. From within the oscc-joystick-commander repository on your machine:

From the joystick commander directory, run the following sequence to build it:
```sh
# create a build directory that will act as our workspace, and cd to it
$ mkdir build/
$ cd build/
```

From there, you will run `cmake` to build a platform-specific Makefile. `cmake` will require some arguments, including the vehicle that the firmware is being built for. You can get a list of supported vehicles using the following command:

```sh
$ cmake -LA .. 2>/dev/null | grep 'VEHICLE_VALUES'
```
mkdir build
cd build
cmake .. -DKIA_SOUL=ON
make

For example, to configure `cmake` to build a platform-specific Makefile for the Kia Niro, you would use the following command (from within the `build/` directory you created):

```sh
$ cmake -DVEHICLE=kia_niro ..
```

The KIA_SOUL CMake option enables the API to swap between different vehicle specifications, allowing the firmware and API to remain car agnostic.

### CAN interface

After initializing the CAN interface, use the channel number to start joystick commander and begin sending commands to the OSCC modules.

For example with a Kvaser Leaf Light attached, using a bitrate of 500000 and a CAN channel of 0:

```
```sh
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
```

You would then run:

```
```sh
./oscc-joystick-commander 0
```

For more information on setting up a socketcan interface, check out [this guide](http://elinux.org/Bringing_CAN_interface_up).

# Application Details

# Controlling the Vehicle with the Joystick Gamepad
## Controlling the Vehicle with the Joystick Gamepad

Once the joystick commander is up and running you can use it to send commands to the Arduino modules.
Once the joystick commander is up and running you can use it to send commands to DriveKit.
Use the left trigger to brake, the right trigger for throttle, and the left gamepad axis to control steering.

The vehicle will only respond to commands if control is enabled with the start button. The back button disables control.


# Application Details


### main

Entry point of joystick commander. Initializes OSCC interface, checks for controller updates in 50 ms intervals, and closes the interface when the program terminates. This contains the applications main loop.

`main.c` is the entry point of joystick commander. Initializes OSCC interface, checks for controller updates in 5 ms intervals, and closes the interface when the program terminates. This contains the applications main loop.

### joystick

`joystick.c` contains the functionality necessary to initialize and interact with the game controller.


### commander

The commander files contain the joystick commander's interactivity with the OSCC API. It demonstrates opening and closing the CAN channel communications with OSCC's control CAN network, sending enable/disable commands to the modules through the API, retrieving OSCC reports through callback functions, and sending commands through the OSCC `publish` functions.


# Using OSCC API

To use the OSCC API in your applications, you need to include any relevant header files.

* The can message protocols are located in `oscc/api/include/can_protocols/`
* These specify the structs we use for steering, throttle, brake, and fault reports
* Vehicle specific macros and values are located in `oscc/api/include/vehicles/`
* You only need to include `vehicles.h`, which will include the relevant vehicle-specific header depending on the option provided to CMake (e.g., `-DKIA_SOUL=ON` will include `kia_soul.h`)
* You only need to include `vehicles.h`, which will include the relevant vehicle-specific header depending on the option provided to CMake (e.g., `-DVEHICLE=kia_niro` will include `kia_niro.h`)
* `oscc/api/include/oscc.h` includes the functionality to interface with the OSCC API


Expand All @@ -130,4 +148,4 @@ Please direct questions regarding OSCC and/or licensing to [email protected].

*Distributed as-is; no warranty is given.*

Copyright (c) 2017 PolySync Technologies, Inc. All Rights Reserved.
Copyright (c) 2019 PolySync Technologies, Inc. All Rights Reserved.
1 change: 1 addition & 0 deletions oscc
Submodule oscc added at 45ce9f
52 changes: 43 additions & 9 deletions src/commander.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define JOYSTICK_AXIS_STEER (SDL_CONTROLLER_AXIS_LEFTX)
#define JOYSTICK_BUTTON_ENABLE_CONTROLS (SDL_CONTROLLER_BUTTON_START)
#define JOYSTICK_BUTTON_DISABLE_CONTROLS (SDL_CONTROLLER_BUTTON_BACK)
#define STEERING_RANGE_PERCENTAGE (0.36)
#define BRAKES_ENABLED_MIN (0.05)
#define JOYSTICK_DELAY_INTERVAL (50000)
#define COMMANDER_ENABLED ( 1 )
Expand Down Expand Up @@ -166,8 +167,7 @@ int check_for_controller_update( )
}
}

if ( (return_code == OSCC_OK)
&& (control_enabled == true) )
if ( return_code == OSCC_OK )
{
return_code = command_brakes( );

Expand All @@ -191,21 +191,37 @@ static int get_normalized_position( unsigned long axis_index, double * const nor

int axis_position = 0;

static const float deadzone = 0.3;

return_code = joystick_get_axis( axis_index, &axis_position );

if ( return_code == OSCC_OK )
{
// this is between -1.0 and 1.0
double raw_normalized_position = ((double) axis_position / INT16_MAX);

if ( axis_index == JOYSTICK_AXIS_STEER )
{
( *normalized_position ) = CONSTRAIN(
((double) axis_position) / INT16_MAX,
-1.0,
1.0);
// if axis is in deadzone, do nothing
if ( fabs(raw_normalized_position) < deadzone)
{
( *normalized_position ) = 0.0;
}
else
{
// normalize over non deadzone range
raw_normalized_position *= (fabs(raw_normalized_position) - deadzone) / (1.0 - deadzone);

( *normalized_position ) = CONSTRAIN(
raw_normalized_position,
-1.0,
1.0);
}
}
else
{
( *normalized_position ) = CONSTRAIN(
((double) axis_position) / INT16_MAX,
raw_normalized_position,
0.0,
1.0);
}
Expand Down Expand Up @@ -348,6 +364,12 @@ static int command_brakes( )
return_code = oscc_publish_brake_position( average );
}
}
else
{
average = 0.0;

return_code = OSCC_OK;
}

return ( return_code );
}
Expand Down Expand Up @@ -392,6 +414,12 @@ static int command_throttle( )
return_code = oscc_publish_throttle_position( average );
}
}
else
{
average = 0.0;

return_code = OSCC_OK;
}

return ( return_code );
}
Expand Down Expand Up @@ -421,11 +449,17 @@ static int command_steering( )

printf("Steering: %f\n", average);

return_code = oscc_publish_steering_torque( average );
// use only 20% of allowable range for controllability
return_code = oscc_publish_steering_torque( average * STEERING_RANGE_PERCENTAGE );
}
}
else
{
average = 0.0;


return_code = OSCC_OK;
}

return ( return_code );
}

Expand Down
Loading