Skip to content

Commit

Permalink
Input Works!
Browse files Browse the repository at this point in the history
It works in that input commands are being sent to window. However,
inputs are sent too fast. I tried adding Sleep(), but program kept
freezing...

thanks to Komat and supric
(http://forum.scssoft.com/viewtopic.php?f=41&t=228761)
  • Loading branch information
zappybiby committed Feb 10, 2017
1 parent e1bc37e commit b8746df
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 31 deletions.
69 changes: 54 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,79 @@
# ChosunTruck

## Introduction
Chosun Truck is autonomous driving solution on Euro Truck Simulator 2(https://eurotrucksimulator2.com/).
ChosunTruck is an autonomous driving solution for [Euro Truck Simulator 2](https://eurotrucksimulator2.com/).
Recently, autonomous driving technology has become a big issue and we have studied the technology related to this.
It is being develop in a simulator environment called Euro Truck Simulator 2 to study it with vehicles.
Because this simulator provides a good test environment that is similar to the real road, we choose it.
It is being developed in a simulator environment called Euro Truck Simulator 2 to study it with vehicles.
Because this simulator provides a good test environment that is similar to the real road, we chose it.

## Features
* You can drive a vehicle without handling.
* You can drive a vehicle without handling it yourself.
* You can understand the principle of autonomous driving.
* This feature only works on the highway.
* These features only work while driving on a highway.

## How To Run It
### Windows
OS: Windows 7 64bits

IDE: Visual Studio 2015

## master
OS: window 7 64bits
Development Tool: Visual Studio 2015
OpenCV version: 3.0

Because mouse movements or keyboard input do not work in Windows to navigate the truck in Euro Truck Simulator 2, the master version is only available for lane detection.
** **Go to C:\Users\YOURUSERNAME\Documents\Euro Truck Simulator 2\profiles and edit controls.sii from di8.keyboard/fusion.mouse to sys.keyboard/sys.mouse.** (thanks Komat!)

**

- Open the visual studio project and build it.
- Run ETS2 in windowed mode and set resolution to 1024 * 768.(It will work properly with 1920 * 1080 screen resolution and 1024 * 768 window mode ETS2.)

### Linux
OS: Ubuntu 16.04 LTS

## linux
OS: ubuntu
OpenCV version: 3.0

- Clone the linux branch.
```
git clone -b linux https://github.com/bethesirius/ChosunTruck.git
```
- Build the source code with below command.
```
g++ -o auto_drive main2.cpp IPM.cpp lineinder.cpp uinput.c `pkg-config opencv --cflags --libs` -std=c++11 -lX11 -Wall -fopenmp -O3 -march=native
```
- Run ETS2 in windowed mode and set the resolution to 1024 * 768. (It will work properly with 1920 * 1080 screen resolution and 1024 * 768 window mode ETS2)
- It cannot find the ETS2 window automatically, you should move the ETS2 window to right-down corner to fix this.
- In ETS2 Options, set controls to `Keyboard + Mouse Steering`.
- Go to a highway and set truck's speed to 40~60km/h. (I recommend that you turn on cruise mode to set the speed easily)
- Run this program as root!
```
sudo ./auto_drive
```
----
If you have some problems to run this project, reference the demo video below. Or, open a issue to contact our team.

## Demo Video
https://drive.google.com/open?id=0B0NMsYygQ6icMXUzcEJhS1RRT2M
https://goo.gl/photos/aHQ5ZMKdTQJyMuaM9

## Contributers
## Contributors
Chiwan Song, chi3236@gmail.com
JaeCheol Sim, ssimpcp@gmail.com
Seongjoon Chu, hs4393@gmail.com

## How to Contribute
## How To Contribute
Anyone who is interest in this procject is welcome! Just Fork it and Pull Requests!

## License
GNU GENERAL PUBLIC LICENSE v3.0
ChosunTruck, Euro Truck Simulator 2 auto driving solution
Copyright (C) 2017 chi3236, bethesirius, uoyssim

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Binary file modified ets2_auto_driving.sdf
Binary file not shown.
Binary file modified ets2_auto_driving.v12.suo
Binary file not shown.
50 changes: 34 additions & 16 deletions ets2_auto_driving/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,37 +136,55 @@ int main() {

}
SetActiveWindow(hWnd);

int average = (left == -150 || right == 150) ? 0 : left + right;
if (left + right < -50)
{
cout << "go left ";

PostMessage(hWnd, WM_KEYUP, 0x44, 0);
Sleep(500);
PostMessage(hWnd, WM_KEYDOWN, 0x41, 0);
Sleep(500);
PostMessage(hWnd, WM_KEYUP, 0x41, 0);
INPUT input[2];
::ZeroMemory(input, sizeof(input));
input[0].type = INPUT_KEYBOARD;
// Translating 'A' to Scan Code, then pressing down
input[0].ki.wScan = MapVirtualKey(0x41, MAPVK_VK_TO_VSC);
input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
// Translating 'A' to Scan Code, then releasing key
input[1].ki.wScan = MapVirtualKey(0x41, MAPVK_VK_TO_VSC);
input[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(2, input, sizeof(INPUT));
}
else if (left + right > -50 && left + right < 50){
cout << "go straight ";
for (int x = 0, y = 0; x < 700 && y < 700; x += 10, y += 10)
{
// PostMessage(hWnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
// Sleep(500);
// PostMessage(hWnd, WM_KEYDOWN, 0x44, 0);
// Sleep(500);
// PostMessage(hWnd, WM_KEYDOWN, 0x41, 0);
//INPUT ip; // Using SendInput to send input commands
//ip.type = INPUT_KEYBOARD;
//ip.ki.time = 0;
//ip.ki.wVk = 0;
//ip.ki.dwExtraInfo = 0;
//ip.ki.wScan = 'D';
//ip.ki.dwFlags = KEYEVENTF_KEYUP; // Releases 'D';
//SendInput(1, &ip, sizeof(ip));
//Sleep(100);

//ip.ki.wScan = 'A';
//ip.ki.dwFlags = KEYEVENTF_KEYUP; // Releases 'A'
//SendInput(1, &ip, sizeof(ip));
}
}
else{
cout << "go right ";
{
PostMessage(hWnd, WM_KEYUP, 0x41, 0);
Sleep(500);
PostMessage(hWnd, WM_KEYDOWN, 0x44, 0);
Sleep(500);
PostMessage(hWnd, WM_KEYUP, 0x44, 0);
// keybd_event(VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
INPUT input[2];
::ZeroMemory(input, sizeof(input));
input[0].type = INPUT_KEYBOARD;
// Translating 'D' to Scan Code, then pressing down
input[0].ki.wScan = MapVirtualKey(0x44, MAPVK_VK_TO_VSC);
input[0].ki.dwFlags = KEYEVENTF_SCANCODE;
// Translating 'D' to Scan Code, then releasing key
input[1].ki.wScan = MapVirtualKey(0x44, MAPVK_VK_TO_VSC);
input[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(2, input, sizeof(INPUT));
}
}
cout << "left: " << left << ", right: " << right << ", average: " << average << endl;
Expand Down
Binary file modified ets2_auto_driving/vc120.pdb
Binary file not shown.

0 comments on commit b8746df

Please sign in to comment.