-
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.
Merge pull request #132 from UOA-FSAE/fs_driverless_sim
Fs driverless sim
- Loading branch information
Showing
9 changed files
with
236 additions
and
83 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
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
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
66 changes: 66 additions & 0 deletions
66
src/driverless_sim/simulator/simulator/set_car_controls.py
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/python3 | ||
import rclpy | ||
from rclpy.node import Node | ||
|
||
from ackermann_msgs.msg import AckermannDrive | ||
|
||
import os | ||
import sys | ||
import numpy as np | ||
|
||
## adds the fsds package located the parent directory to the pyhthon path | ||
path = os.path.abspath(os.path.join('Formula-Student-Driverless-Simulator', 'python')) | ||
sys.path.insert(0, path) | ||
# sys.path.append('/home/Formula-Student-Driverless-Simulator/python') | ||
# print(sys.path) | ||
import fsds | ||
|
||
class set_car_controls(Node): | ||
def __init__(self): | ||
super().__init__("set_car_controls") | ||
|
||
self.max_throttle = 21 # m/s | ||
self.max_steering = 25 # degrees | ||
# connect to the simulator | ||
self.client = fsds.FSDSClient(ip=os.environ['WSL_HOST_IP']) | ||
# Check network connection, exit if not connected | ||
self.client.confirmConnection() | ||
# After enabling setting trajectory setpoints via the api. | ||
self.client.enableApiControl(True) | ||
# create publisher | ||
self.create_subscription(AckermannDrive, 'drive', self.callback, 10) | ||
|
||
|
||
def callback(self, msg:AckermannDrive): | ||
"""Set the car controls in the simulator using the given ackerman msg""" | ||
steering = msg.steering_angle | ||
speed = msg.speed | ||
|
||
steering, throttle = self.get_simulator_controls(steering, speed) | ||
|
||
# class is part of types.py file in sim repo | ||
self.client.setCarControls(fsds.CarControls(throttle=throttle,steering=steering,brake=0.0)) | ||
|
||
def get_simulator_controls(self, steering, speed): | ||
throttle = speed/self.max_throttle # max throttle is 1 in sim where the max speed is ~20m/s | ||
steering = steering/self.max_steering # max absolute steering is 1 in sim where the max steering angle is 25 degrees by default | ||
|
||
return steering, throttle | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
|
||
simulator_car_controls = set_car_controls() | ||
|
||
rclpy.spin(simulator_car_controls) | ||
|
||
# Destroy the node explicitly | ||
# (optional - otherwise it will be done automatically | ||
# when the garbage collector destroys the node object) | ||
simulator_car_controls.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import launch | ||
import launch_ros.actions | ||
|
||
def generate_launch_description(): | ||
return launch.LaunchDescription([ | ||
# get cones | ||
launch_ros.actions.Node( | ||
package='simulator', | ||
executable='get_cones', | ||
name='get_cones', | ||
), | ||
|
||
# car position | ||
launch_ros.actions.Node( | ||
package='simulator', | ||
executable='get_car_position', | ||
name='get_car_position', | ||
), | ||
|
||
# path generation | ||
launch_ros.actions.Node( | ||
package='path_planning', | ||
executable='trajectory_generation', | ||
name='trajectory_generation', | ||
parameters=[{'debug': True, | ||
'timer': 1.0}], | ||
), | ||
|
||
# path optimization | ||
launch_ros.actions.Node( | ||
package='path_planning', | ||
executable='trajectory_optimisation', | ||
name='trajectory_optimisation', | ||
parameters=[{'delete': False, | ||
'interpolate': False}], | ||
), | ||
|
||
# controller | ||
launch_ros.actions.Node( | ||
package='stanley_controller', | ||
executable='controller', | ||
name='controller', | ||
), | ||
|
||
# simulator controller | ||
launch_ros.actions.Node( | ||
package='simulator', | ||
executable='set_car_controls', | ||
name='set_car_controls' | ||
), | ||
|
||
# steer torque | ||
# launch_ros.actions.Node( | ||
# package='steer_torque_from_ackermann', | ||
# executable='steer_torque_from_ackermann', | ||
# name='steer_torque_from_ackermann', | ||
# ), | ||
|
||
# path viz | ||
launch_ros.actions.Node( | ||
package='path_planning_visualization', | ||
executable='visualize', | ||
name='path_viz', | ||
), | ||
|
||
# track viz | ||
launch_ros.actions.Node( | ||
package='cone_map_foxglove_visualizer', | ||
executable='visualizer', | ||
name='track_viz', | ||
), | ||
]) |
File renamed without changes.
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
Oops, something went wrong.