diff --git a/ansible/donkeycar.yml b/ansible/donkeycar.yml index 656f6c76..f3ff546c 100644 --- a/ansible/donkeycar.yml +++ b/ansible/donkeycar.yml @@ -10,11 +10,13 @@ become: yes # This role need root privileges - role: donkeycar # Donkeycar installation become: no # This role doesn't need root privileges - - role: openCV - become: yes + - role: openCV # Install openCV (optional) + become: yes # This role need root privileges - role: shutdown-btn # shutdown button service become: yes # This role need root privileges - - role: mycar # shutdown button service - become: no # This role need root privileges + - role: mycar # create car with configurations + become: no # This role no need root privileges + - role: ps4-controller # install and configure ds4drv + become: no # This role no need root privileges - role: hostname become: yes diff --git a/ansible/group_vars/all b/ansible/group_vars/all index 4eeb8132..ad273ba2 100644 --- a/ansible/group_vars/all +++ b/ansible/group_vars/all @@ -14,4 +14,7 @@ steering_left_pwm: 622 steering_right_pwm: 520 throttle_forward_pwm: 515 throttle_stopped_pwm: 470 -throttle_reverse_pwm: 445 \ No newline at end of file +throttle_reverse_pwm: 445 + +# PS4 controller config +ps4_contoller_led_color: 00CED1 # hexadecimal color ( don't forget, remove the `#` before ) \ No newline at end of file diff --git a/ansible/roles/ps4-controller/defaults/main.yml b/ansible/roles/ps4-controller/defaults/main.yml new file mode 100644 index 00000000..49bb494e --- /dev/null +++ b/ansible/roles/ps4-controller/defaults/main.yml @@ -0,0 +1 @@ +ps4_contoller_led_color: 00CED1 # hexadecimal color ( don't forget, remove the `#` before ) \ No newline at end of file diff --git a/ansible/roles/ps4-controller/handlers/main.yml b/ansible/roles/ps4-controller/handlers/main.yml new file mode 100644 index 00000000..b7284bc5 --- /dev/null +++ b/ansible/roles/ps4-controller/handlers/main.yml @@ -0,0 +1,9 @@ +--- +# ps4 controller handlers + +- name: Start ds4drv service + systemd: + name: ds4drv + daemon-reload: yes + state: started + enabled: yes \ No newline at end of file diff --git a/ansible/roles/ps4-controller/tasks/main.yml b/ansible/roles/ps4-controller/tasks/main.yml new file mode 100644 index 00000000..daa026fb --- /dev/null +++ b/ansible/roles/ps4-controller/tasks/main.yml @@ -0,0 +1,59 @@ +--- + +- name: Install git + become: true + apt: + name: git + state: latest + +- name: Put rules in /etc/udev/rules.d/ + become: yes + get_url: + url: https://raw.githubusercontent.com/chrippa/ds4drv/master/udev/50-ds4drv.rules + dest: /etc/udev/rules.d/50-ds4drv.rules + +- name: reload ds4drv rules + become: yes + command: udevadm control --reload-rules + +- name: activate rules + become: yes + command: udevadm trigger + +- name: Install ds4drv (version with controller limit) + become: no + pip: + name: git+https://github.com/Benvii/ds4drv.git@193_limit_simultaneous_controllers + virtualenv: /home/pi/venv/ + virtualenv_command: /usr/bin/python3 -m venv + +- name: Create the /etc/donkeycar directory + file: + path: /etc/donkeycar + state: directory + +- name: Configure ds4drv.conf file + become: yes + template: + src: ds4drv.conf.j2 + dest: /etc/donkeycar/ds4drv.conf + owner: root + group: root + +- name: Create the environment file for ds4drv + become: yes + template: + src: ds4drv.env.j2 + dest: /etc/donkeycar/ds4drv.env + owner: root + group: root + +- name: Copy systemd service file to server + become: yes + template: + src: ds4drv.service.j2 + dest: /etc/systemd/system/ds4drv.service + owner: root + group: root + notify: + - Start ds4drv service diff --git a/ansible/roles/ps4-controller/templates/ds4drv.conf.j2 b/ansible/roles/ps4-controller/templates/ds4drv.conf.j2 new file mode 100644 index 00000000..e5ef086f --- /dev/null +++ b/ansible/roles/ps4-controller/templates/ds4drv.conf.j2 @@ -0,0 +1,182 @@ +# Many of the settings used here are directly connected to their command line +# counterparts, see "ds4drv --help" for more information about available options. + +## +# Global options +## +[ds4drv] +# Run ds4drv in background as a daemon +#daemon = true + +# Location of the log file in daemon mode +#daemon-log = ~/.cache/ds4drv.log + +# Location of the PID file in daemon mode +#daemon-pid = /tmp/ds4drv.pid + +# Enable hidraw mode +#hidraw = true + + +## +# Controller settings +# +# This is the default profile for each controller. +# Multiple controllers slots are defined by increasing the number. +# +# Controller sections contain: +# Key: A option, these are the same options that can used on the command line +# but without the "--" prefix. +# Value: The option's value, should be "true" if no value is needed. +# +# See "ds4drv --help" for a complete list of available options. +## +[controller:1] +# Enables LED flash on low battery +#battery-flash = true + +# Sets LED color +#led = 0000ff + +# Enables profile switching +#profile-toggle = PS + +# Profiles to cycle through +#profiles = xpad,kbmouse + + +## +# Profiles +# +# Profiles allows switching controller settings during runtime. +# +# Profile sections always require a name and are then enabled on a controller +# with "profiles = [,]". +# +# The same settings available for controllers are used here. +## +[profile:xpad] +led = ff0000 +# Emulate the same button mapping as wired Xbox 360 controllers +emulate-xpad = true + +[profile:kbmouse] +led = 00ff00 +# Enable trackpad mouse +trackpad-mouse = true +# Custom button mapping +mapping = keyboard +# Custom action bindings +bindings = exec_stuff + + +## +# Mappings +# +# Mappings let you map buttons and sticks to mouse, key and joystick events. +# +# Mapping sections always require a name and are then enabled in a profile +# with "mapping = ". +# +# Mapping sections contain: +# Key: A Linux input event, see /usr/include/linux/input-event-codes.h for a complete list +# Value: Button on the DS4, use --dump-reports to see all the available buttons +## + +[mapping:keyboard] +# General button to key mapping +KEY_UP = dpad_up +KEY_LEFT = dpad_left +KEY_DOWN = dpad_down +KEY_RIGHT = dpad_right +KEY_Z = button_cross +KEY_X = button_circle + +# Turn analog stick directions into buttons +KEY_W = -left_analog_y +KEY_A = -left_analog_x +KEY_S = +left_analog_y +KEY_D = +left_analog_x + +# Map relative mouse movement to a analog stick +REL_X = right_analog_x +REL_Y = right_analog_y + +# Map mouse buttons +BTN_LEFT = button_r2 +BTN_RIGHT = button_l2 + +# Emulate mouse wheel on r1 and l1 +REL_WHEELUP = button_l1 +REL_WHEELDOWN = button_r1 + +# Mouse settings +#mouse_sensitivity = 0.6 +#mouse_deadzone = 5 + +# Scroll wheel emulation settings (values are in seconds) +#mouse_scroll_repeat_delay = 0.25 # How long to wait before continual scrolling +#mouse_scroll_delay = 0.05 # Lower this to scroll faster; raise to scroll slower + + +## +# Bindings +# +# Bindings let you bind button combos to special built-in actions. +# +# Binding sections can be defined with a name and are then enabled in a profile +# with "bindings = ". +# +# It's also possible to define a global bindings section that is enabled +# on all profiles. +# +# Sections contains: +# Key: A button combo +# Value: An action, see next section for valid actions. +# +# +# Valid actions: +# next-profile Loads the next profile +# prev-profile Loads the previous profile +# load-profile Loads the specified profile +# exec [arg1] [arg2] ... Executes the command with +# specified arguments +# exec-background [arg1] [arg2] ... Same as exec but launches in +# the background +# +# +# Actions will be pre-processed and replace variables with real values. +# +# Valid variables: +# $profile The current profile +# $name Pretty name of the current device +# $device_addr Bluetooth address of the device +# $report. Replace with a valid attribute, +# use --dump-reports to see which are available +## + +[bindings] +# Cycle profiles +#PS+Right = next-profile +#PS+Left = prev-profile + +# Go directly to specified profile +#PS+Up = load-profile kbmouse +#PS+Down = load-profile default + + +[bindings:exec_stuff] +# Execute a command in the foreground, blocking until it has finished +PS+Cross = exec echo '$name' + +# Execute a command in the background +PS+Triangle = exec-background sh -c 'echo "disconnect $device_addr" | bluetoothctl' + +[bindings:test] +# Round = exec echo round +L2 = exec echo L2 +Ps+Cross = exec echo sus +PS+Triangle+L2+Circle = exec echo shutdown + +[bindings:donkeycar] +PS+Triangle+L2+Circle = exec sudo shutdown -h now \ No newline at end of file diff --git a/ansible/roles/ps4-controller/templates/ds4drv.env.j2 b/ansible/roles/ps4-controller/templates/ds4drv.env.j2 new file mode 100644 index 00000000..58040834 --- /dev/null +++ b/ansible/roles/ps4-controller/templates/ds4drv.env.j2 @@ -0,0 +1 @@ +CONTROLLER_LED_COLOR={{ ps4_contoller_led_color }} \ No newline at end of file diff --git a/ansible/roles/ps4-controller/templates/ds4drv.service.j2 b/ansible/roles/ps4-controller/templates/ds4drv.service.j2 new file mode 100644 index 00000000..9c86133a --- /dev/null +++ b/ansible/roles/ps4-controller/templates/ds4drv.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=ds4drv daemon +Requires=bluetooth.service +After=bluetooth.service + +[Service] +EnvironmentFile=/etc/donkeycar/ds4drv.env +ExecStartPre=/bin/sleep 5 +ExecStart=/home/pi/venv/bin/ds4drv --controller-limit 1 --led ${CONTROLLER_LED_COLOR} --config /etc/donkeycar/ds4drv.conf --bindings donkeycar +Restart=on-abort + +[Install] +WantedBy=bluetooth.target \ No newline at end of file diff --git a/ansible/roles/raspi-config/tasks/main.yml b/ansible/roles/raspi-config/tasks/main.yml index c3cb640e..1bab150b 100644 --- a/ansible/roles/raspi-config/tasks/main.yml +++ b/ansible/roles/raspi-config/tasks/main.yml @@ -4,7 +4,7 @@ name: ssh enabled: yes -- name: Put the wpa configuration in /boot # first boot on the +- name: Put the wpa configuration in /boot template: src: wpa-suplicant-conf.j2 dest: /boot/wpa_supplicant.conf @@ -33,4 +33,14 @@ command: raspi-config nonint do_i2c 1 - name: Enable camera - command: raspi-config nonint do_camera 1 \ No newline at end of file + command: raspi-config nonint do_camera 1 + +- name: modifie the dhcpd5 service + template: + src: dhcpd.service.j2 + dest: /lib/systemd/system/dhcpcd.service + owner: root + group: root + # We won't notify to restart DHCP service because it could cause Ansible deconnexion + # Change will be taken into account at restart, it's not an issue as our fixe covers + # timeout issue at the first boot of the raspberry pi. diff --git a/ansible/roles/raspi-config/templates/dhcpd.service.j2 b/ansible/roles/raspi-config/templates/dhcpd.service.j2 new file mode 100644 index 00000000..4acad1b3 --- /dev/null +++ b/ansible/roles/raspi-config/templates/dhcpd.service.j2 @@ -0,0 +1,16 @@ +[Unit] +Description=dhcpcd on all interfaces +Wants=network.target +Before=network.target +Restart=always + +[Service] +Type=forking +PIDFile=/run/dhcpcd.pid +ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b +ExecStop=/sbin/dhcpcd -x +TimeoutStartSec=180 + +[Install] +WantedBy=multi-user.target +Alias=dhcpcd5.service \ No newline at end of file