Skip to content

Commit

Permalink
Added the correct vehicle dynamics and made interface interaction wit…
Browse files Browse the repository at this point in the history
…h unreal possible using the cloudiness settings

Former-commit-id: c5b796526c67ec9de91ebaa55896e6b542635017
  • Loading branch information
timomelman committed Jan 13, 2021
1 parent e398a84 commit c1e8260
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
JOANHQACTION = HQManager()

# adding modules (instantiates them too)
#JOANHQACTION.add_module(JOANModules.TEMPLATE, time_step_in_ms=100)
# JOANHQACTION.add_module(JOANModules.TEMPLATE, time_step_in_ms=100)
JOANHQACTION.add_module(JOANModules.HARDWARE_MANAGER, time_step_in_ms=10)
JOANHQACTION.add_module(JOANModules.CARLA_INTERFACE, time_step_in_ms=10)
JOANHQACTION.add_module(JOANModules.DATA_PLOTTER, time_step_in_ms=10)
JOANHQACTION.add_module(JOANModules.HAPTIC_CONTROLLER_MANAGER, time_step_in_ms=10)
# JOANHQACTION.add_module(JOANModules.HAPTIC_CONTROLLER_MANAGER, time_step_in_ms=10)
# JOANHQACTION.add_module(JOANModules.CONTROLLER_PLOTTER, time_step_in_ms=500)
JOANHQACTION.add_module(JOANModules.DATA_RECORDER, time_step_in_ms=10)
JOANHQACTION.add_module(JOANModules.EXPERIMENT_MANAGER, time_step_in_ms=500)
# JOANHQACTION.add_module(JOANModules.DATA_RECORDER, time_step_in_ms=10)
# JOANHQACTION.add_module(JOANModules.EXPERIMENT_MANAGER, time_step_in_ms=500)

APP.exec_()
35 changes: 29 additions & 6 deletions modules/carlainterface/carlainterface_agentclasses/ego_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,28 +153,46 @@ def __init__(self, carla_mp, settings, shared_variables):
self._BP = random.choice(self.carlainterface_mp.vehicle_blueprint_library.filter("vehicle." + self.settings.selected_car))
self._control = carla.VehicleControl()
self.world_map = self.carlainterface_mp.world.get_map()
self.weather = self.carlainterface_mp.world.get_weather()

torque_curve = []
gears = []

# JG
torque_curve.append(carla.Vector2D(x=0, y=600))
torque_curve.append(carla.Vector2D(x=14000, y=600))
gears.append(carla.GearPhysicsControl(ratio=7.73, down_ratio=0.5, up_ratio=1))

#TM Same as peter
torque_curve_TM = []
gears_TM = []
torque_curve_TM.append(carla.Vector2D(x=0, y=600))
torque_curve_TM.append(carla.Vector2D(x=6000, y=600))
torque_curve_TM.append(carla.Vector2D(x=8000, y=0))
gears_TM.append(carla.GearPhysicsControl(ratio=7.73, down_ratio=0.5, up_ratio=1))

if self.settings.selected_spawnpoint != 'None':
if self.settings.selected_car != 'None':
self.spawned_vehicle = self.carlainterface_mp.world.spawn_actor(self._BP, self.carlainterface_mp.spawn_point_objects[
self.carlainterface_mp.spawn_points.index(self.settings.selected_spawnpoint)])

physics = self.spawned_vehicle.get_physics_control()
physics.torque_curve = torque_curve
physics.torque_curve = torque_curve_TM
physics.max_rpm = 14000
physics.moi = 1.5
physics.final_ratio = 1
physics.clutch_strength = 1000 # very big no clutch
physics.moi = 0.06 # 1.5
physics.clutch_strength = 1000 # very big no clutch
physics.final_ratio = 1 # ratio from transmission to wheels
physics.forward_gears = gears
physics.forward_gears = gears_TM
physics.gear_switch_time = 0
physics.mass = 2316
physics.drag_coefficient = 0.24
physics.gear_switch_time = 0
physics.damping_rate_zero_throttle_clutch_engaged = True
physics.damping_rate_full_throttle = True

# TM added:
physics.use_gear_autobox = True
physics.damping_rate_full_throttle = 0.0
# TM added end
self.spawned_vehicle.apply_physics_control(physics)

def do(self):
Expand All @@ -183,6 +201,11 @@ def do(self):
self._control.reverse = self.carlainterface_mp.shared_variables_hardware.inputs[self.settings.selected_input].reverse
self._control.hand_brake = self.carlainterface_mp.shared_variables_hardware.inputs[self.settings.selected_input].handbrake
self._control.brake = self.carlainterface_mp.shared_variables_hardware.inputs[self.settings.selected_input].brake

self.weather.cloudiness = self._control.brake*100
self.carlainterface_mp.world.set_weather(self.weather)


if self.settings.set_velocity:
vel_error = self.settings.velocity - (math.sqrt(
self.spawned_vehicle.get_velocity().x ** 2 + self.spawned_vehicle.get_velocity().y ** 2 + self.spawned_vehicle.get_velocity().z ** 2) * 3.6)
Expand Down
17 changes: 11 additions & 6 deletions modules/hardwaremanager/hardwaremanager_inputs/joanjoystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def do(self):
Processes all the inputs of the joystick and writes them to self._data which is then written to the news in the
action class
:return: self._data a dictionary containing :self._data['brake'] = self.brake
self._data['throttle'] = self.throttle
self._data['steering_angle'] = self.steer
self._data['Handbrake'] = self.handbrake
self._data['Reverse'] = self.reverse
"""
if self._joystick_open:
joystick_data = self._joystick.read(self.settings.degrees_of_freedom, 1)
Expand All @@ -55,8 +51,15 @@ def do(self):

if joystick_data:
if self.settings.use_separate_brake_channel:
self.throttle = ((joystick_data[self.settings.gas_channel]) / 255)
self.brake = - ((joystick_data[self.settings.brake_channel]) / 255)
#self.throttle = ((joystick_data[self.settings.gas_channel]) / 255)
#self.brake = - ((joystick_data[self.settings.brake_channel]) / 255)

#Thrustmaster settings
self.throttle = 1 - ((joystick_data[self.settings.gas_channel]+1) + (joystick_data[6]*256)) / 1024 #4*256 = 1020
self.brake = 1 - ((joystick_data[self.settings.brake_channel]+1) + (joystick_data[4]*256)) / 1024
#print(joystick_data[6])
#print(joystick_data[self.settings.gas_channel])
print(self.throttle)
else:
input_value = 1 - ((joystick_data[self.settings.gas_channel]) / 128)
if input_value > 0:
Expand All @@ -82,6 +85,8 @@ def do(self):
self.steer = ((joystick_data[self.settings.first_steer_channel]) / 255) * (
self.settings.max_steer - self.settings.min_steer) - self.settings.max_steer



self.shared_variables.brake = self.brake
self.shared_variables.throttle = self.throttle
self.shared_variables.steering_angle = self.steer
Expand Down

0 comments on commit c1e8260

Please sign in to comment.