本文整理匯總了Python中carla.VehicleControl方法的典型用法代碼示例。如果您正苦於以下問題:Python carla.VehicleControl方法的具體用法?Python carla.VehicleControl怎麽用?Python carla.VehicleControl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類carla
的用法示例。
在下文中一共展示了carla.VehicleControl方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_vehicle_control
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def on_vehicle_control(self, data):
"""
callback if a new vehicle control command is received
"""
cmd = carla.VehicleControl()
cmd.throttle = data.throttle
cmd.steer = data.steer
cmd.brake = data.brake
cmd.hand_brake = data.hand_brake
cmd.reverse = data.reverse
cmd.gear = data.gear
cmd.manual_gear_shift = data.manual_gear_shift
self.current_control = cmd
if not self.vehicle_control_event.is_set():
self.vehicle_control_event.set()
# After the first vehicle control is sent out, it is possible to use the stepping mode
self.step_mode_possible = True
示例2: _reset_world
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def _reset_world(self, soft=False):
# init actor
if not soft:
spawn_point = env_utils.random_spawn_point(self.map)
else:
spawn_point = self.spawn_point
if self.vehicle is None:
blueprint = env_utils.random_blueprint(self.world, actor_filter=self.vehicle_filter)
self.vehicle = env_utils.spawn_actor(self.world, blueprint, spawn_point) # type: carla.Vehicle
self._create_sensors()
self.synchronous_context = CARLASyncContext(self.world, self.sensors, fps=self.fps)
else:
self.vehicle.apply_control(carla.VehicleControl())
self.vehicle.set_velocity(carla.Vector3D(x=0.0, y=0.0, z=0.0))
self.vehicle.set_transform(spawn_point)
# reset reward variables
self.collision_penalty = 0.0
示例3: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self, input_data, timestamp):
# Get the current directions for following the route
directions = self._get_current_direction(input_data['GPS'][1])
logging.debug("Directions {}".format(directions))
# Take the forward speed and normalize it for it to go from 0-1
norm_speed = input_data['can_bus'][1]['speed'] / g_conf.SPEED_FACTOR
norm_speed = torch.cuda.FloatTensor([norm_speed]).unsqueeze(0)
directions_tensor = torch.cuda.LongTensor([directions])
# Compute the forward pass processing the sensors got from CARLA.
model_outputs = self._model.forward_branch(self._process_sensors(input_data['rgb'][1]),
norm_speed,
directions_tensor)
steer, throttle, brake = self._process_model_outputs(model_outputs[0])
control = carla.VehicleControl()
control.steer = float(steer)
control.throttle = float(throttle)
control.brake = float(brake)
logging.debug("Output ", control)
# There is the posibility to replace some of the predictions with oracle predictions.
self.first_iter = False
return control
示例4: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self, target_speed, waypoint):
"""
Execute one step of control invoking both lateral and longitudinal PID controllers to reach a target waypoint
at a given target_speed.
:param target_speed: desired vehicle speed
:param waypoint: target location encoded as a waypoint
:return: distance (in meters) to the waypoint
"""
throttle = self._lon_controller.run_step(target_speed)
steering = self._lat_controller.run_step(waypoint)
control = carla.VehicleControl()
control.steer = steering
control.throttle = throttle
control.brake = 0.0
control.hand_brake = False
control.manual_gear_shift = False
return control
示例5: control_command_updated
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def control_command_updated(self, ros_vehicle_control, manual_override):
"""
Receive a CarlaEgoVehicleControl msg and send to CARLA
This function gets called whenever a ROS CarlaEgoVehicleControl is received.
If the mode is valid (either normal or manual), the received ROS message is
converted into carla.VehicleControl command and sent to CARLA.
This bridge is not responsible for any restrictions on velocity or steering.
It's just forwarding the ROS input to CARLA
:param manual_override: manually override the vehicle control command
:param ros_vehicle_control: current vehicle control input received via ROS
:type ros_vehicle_control: carla_msgs.msg.CarlaEgoVehicleControl
:return:
"""
if manual_override == self.vehicle_control_override:
vehicle_control = VehicleControl()
vehicle_control.hand_brake = ros_vehicle_control.hand_brake
vehicle_control.brake = ros_vehicle_control.brake
vehicle_control.steer = ros_vehicle_control.steer
vehicle_control.throttle = ros_vehicle_control.throttle
vehicle_control.reverse = ros_vehicle_control.reverse
self.carla_actor.apply_control(vehicle_control)
self._vehicle_control_applied_callback(self.get_id())
示例6: __init__
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def __init__(self, world, transform=carla.Transform(),
on_collision_fn=None, on_invasion_fn=None,
vehicle_type="vehicle.lincoln.mkz2017"):
# Setup vehicle blueprint
vehicle_bp = world.get_blueprint_library().find(vehicle_type)
color = vehicle_bp.get_attribute("color").recommended_values[0]
vehicle_bp.set_attribute("color", color)
# Create vehicle actor
actor = world.spawn_actor(vehicle_bp, transform)
print("Spawned actor \"{}\"".format(actor.type_id))
super().__init__(world, actor)
# Maintain vehicle control
self.control = carla.VehicleControl()
if callable(on_collision_fn):
self.collision_sensor = CollisionSensor(world, self, on_collision_fn=on_collision_fn)
if callable(on_invasion_fn):
self.lane_sensor = LaneInvasionSensor(world, self, on_invasion_fn=on_invasion_fn)
示例7: parse_input
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def parse_input(self, clock):
self._parse_events()
self._parse_mouse()
if not self._autopilot_enabled:
if isinstance(self.control, carla.VehicleControl):
self._parse_keys(clock.get_time())
self.control.reverse = self.control.gear < 0
world = module_manager.get_module(MODULE_WORLD)
if (world.hero_actor is not None):
world.hero_actor.apply_control(self.control)
示例8: __init__
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def __init__(self, actor, actor_reference, target_location, gain=1, name="SyncArrival"):
"""
Setup required parameters
"""
super(SyncArrival, self).__init__(name, actor)
self.logger.debug("%s.__init__()" % (self.__class__.__name__))
self._control = carla.VehicleControl()
self._actor_reference = actor_reference
self._target_location = target_location
self._gain = gain
self._control.steering = 0
示例9: setup
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def setup(self, path_to_conf_file):
"""
Setup the agent parameters
"""
self.agent_engaged = False
self.current_control = carla.VehicleControl()
self.current_control.steer = 0.0
self.current_control.throttle = 1.0
self.current_control.brake = 0.0
self.current_control.hand_brake = False
self._hic = HumanInterface(self)
self._thread = Thread(target=self._hic.run)
self._thread.start()
示例10: __init__
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def __init__(self):
"""
Init
"""
self._control = carla.VehicleControl()
self._steer_cache = 0.0
示例11: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self, input_data, timestamp):
"""
Execute one step of navigation.
"""
control = carla.VehicleControl()
control.steer = 0.0
control.throttle = 0.0
control.brake = 0.0
control.hand_brake = False
if not self._agent:
hero_actor = None
for actor in CarlaDataProvider.get_world().get_actors():
if 'role_name' in actor.attributes and actor.attributes['role_name'] == 'hero':
hero_actor = actor
break
if hero_actor:
self._agent = BasicAgent(hero_actor)
return control
if not self._route_assigned:
if self._global_plan:
plan = []
for transform, road_option in self._global_plan_world_coord:
wp = CarlaDataProvider.get_map().get_waypoint(transform.location)
plan.append((wp, road_option))
self._agent._local_planner.set_global_plan(plan) # pylint: disable=protected-access
self._route_assigned = True
else:
control = self._agent.run_step()
return control
示例12: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self, input_data, timestamp):
"""
Execute one step of navigation.
:return: control
"""
control = carla.VehicleControl()
control.steer = 0.0
control.throttle = 0.0
control.brake = 0.0
control.hand_brake = False
return control
示例13: step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def step(self, actions):
if not self.autopilot:
self.vehicle.apply_control(carla.VehicleControl(throttle=actions[0], steer=actions[1], brake=actions[2],
hand_brake=actions[3], reverse=actions[4],
manual_gear_shift=actions[5], gear=actions[6]))
else:
self.vehicle.apply_control(
carla.VehicleControl(throttle=1, steer=0, brake=0,
hand_brake=0, reverse=0,
manual_gear_shift=0, gear=0))
if len(self.fines) <= 0:
return 1
else:
return self.fines.pop()
示例14: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self):
transform = self._vehicle.get_transform()
if self.waypoints:
# If too far off course, reset waypoint queue.
if distance_vehicle(self.waypoints[0], transform) > 5.0 * self.radius:
self.waypoints = []
# Get more waypoints.
if len(self.waypoints) < self.max_waypoints // 2:
self.add_next_waypoints()
# If no more waypoints, stop.
if not self.waypoints:
print('Ran out of waypoints; stopping.')
control = carla.VehicleControl()
control.throttle = 0.0
return control
# Remove waypoints we've reached.
while distance_vehicle(self.waypoints[0], transform) < self.min_dist:
self.waypoints = self.waypoints[1:]
# Draw next waypoint
draw_waypoints(self._vehicle.get_world(),
self.waypoints[:1],
self._vehicle.get_location().z + 1.0)
return self.controller.run_step(self.target_speed, self.waypoints[0])
示例15: run_step
# 需要導入模塊: import carla [as 別名]
# 或者: from carla import VehicleControl [as 別名]
def run_step(self):
control = carla.VehicleControl()
control.throttle = 0.0
control.brake = 1.0
control.hand_brake = True
return control