-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
github-actions
committed
Oct 1, 2023
1 parent
ba88939
commit 9783172
Showing
1 changed file
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
#git remote set-url origin [email protected]:vortexntnu/vortex-asv.git | ||
import yaml | ||
|
||
|
||
class JoystickInterface(Node): | ||
|
||
def __init__(self): | ||
|
@@ -27,10 +28,10 @@ def __init__(self): | |
] | ||
|
||
self.joystick_axes_map = [ | ||
"horizontal_axis_left_stick", #Translation (Left and Right) | ||
"vertical_axis_left_stick", #Translation (Forwards and Backwards) | ||
"horizontal_axis_left_stick", #Translation (Left and Right) | ||
"vertical_axis_left_stick", #Translation (Forwards and Backwards) | ||
"LT", | ||
"horizontal_axis_right_stick", #Rotation | ||
"horizontal_axis_right_stick", #Rotation | ||
"vertical_axis_right_stick", | ||
"RT", | ||
"dpad_horizontal", | ||
|
@@ -39,38 +40,38 @@ def __init__(self): | |
|
||
#Create a Publisher and a suscriber from the ros2 tutorial | ||
super().__init__('joystick_interface_node') | ||
self.joy_subscriber = self.create_subscription(Joy, "/joystick/joy", self.joystick_cb, 1) | ||
|
||
self.wrench_publisher = self.create_publisher(Wrench, "/thrust/wrench_input", 1) | ||
self.joy_subscriber = self.create_subscription(Joy, "/joystick/joy", | ||
self.joystick_cb, 1) | ||
|
||
self.wrench_publisher = self.create_publisher(Wrench, | ||
"/thrust/wrench_input", | ||
1) | ||
|
||
#YAML file first need to be translating in ROS2 ; Getting the input from the controller' | ||
self.declare_parameter('surge', 100.0) | ||
self.declare_parameter('sway', 100.0) | ||
self.declare_parameter('yaw', 100.0) | ||
|
||
self.joystick_surge_scaling = self.get_parameter('surge').value #is it getting the parameters from the YAML file ? No --> TO DO | ||
self.joystick_surge_scaling = self.get_parameter( | ||
'surge' | ||
).value #is it getting the parameters from the YAML file ? No --> TO DO | ||
self.joystick_sway_scaling = self.get_parameter('sway').value | ||
self.joystick_yaw_scaling = self.get_parameter('yaw').value | ||
|
||
|
||
|
||
def create_2d_wrench_message(self, x, y, yaw): | ||
wrench_msg = Wrench() | ||
wrench_msg.force.x = x | ||
wrench_msg.force.y = y | ||
wrench_msg.torque.z = yaw | ||
return wrench_msg | ||
|
||
|
||
def publish_wrench_message(self, wrench): | ||
self.wrench_publisher.publish(wrench) | ||
|
||
|
||
def joystick_cb(self, msg): | ||
|
||
#Input from controller to joystick_interface | ||
buttons = {} #dictionnary | ||
buttons = {} #dictionnary | ||
axes = {} | ||
|
||
for i in range(len(msg.buttons)): | ||
|
@@ -88,10 +89,8 @@ def joystick_cb(self, msg): | |
|
||
self.publish_wrench_message(wrench_msg) | ||
|
||
|
||
#a = msg.buttons #to remove | ||
return wrench_msg | ||
|
||
|
||
|
||
def main(args=None): | ||
|