Python carla.VehicleControl() Examples
The following are 30
code examples of carla.VehicleControl().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
carla
, or try the search function
.
Example #1
Source File: CoILBaseline.py From coiltraine with MIT License | 6 votes |
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
Example #2
Source File: wrappers.py From Carla-ppo with MIT License | 6 votes |
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)
Example #3
Source File: ego_vehicle.py From ros-bridge with MIT License | 6 votes |
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())
Example #4
Source File: carla_environment.py From tensorforce with Apache License 2.0 | 6 votes |
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
Example #5
Source File: ros_agent.py From scenario_runner with MIT License | 6 votes |
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
Example #6
Source File: controller.py From macad-gym with MIT License | 6 votes |
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
Example #7
Source File: keyboard_control.py From macad-gym with MIT License | 5 votes |
def __init__(self, world, start_in_autopilot): self._autopilot_enabled = start_in_autopilot self._control = carla.VehicleControl() self._steer_cache = 0.0 self.actor_id = None self.vehicle = None # world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
Example #8
Source File: manual_control.py From macad-gym with MIT License | 5 votes |
def __init__(self, world, start_in_autopilot): self._autopilot_enabled = start_in_autopilot self._control = carla.VehicleControl() self._steer_cache = 0.0 world.vehicle.set_autopilot(self._autopilot_enabled) world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
Example #9
Source File: test_vehicle.py From macad-gym with MIT License | 5 votes |
def test_default_values(self): c = carla.VehicleControl() self.assertEqual(c.throttle, 0.0) self.assertEqual(c.steer, 0.0) self.assertEqual(c.brake, 0.0) self.assertEqual(c.hand_brake, False) self.assertEqual(c.reverse, False) c = carla.VehicleControl(1.0, 2.0, 3.0, True, True) self.assertEqual(c.throttle, 1.0) self.assertEqual(c.steer, 2.0) self.assertEqual(c.brake, 3.0) self.assertEqual(c.hand_brake, True) self.assertEqual(c.reverse, True)
Example #10
Source File: test_vehicle.py From macad-gym with MIT License | 5 votes |
def test_named_args(self): c = carla.VehicleControl( throttle=1.0, steer=2.0, brake=3.0, hand_brake=True, reverse=True) self.assertEqual(c.throttle, 1.0) self.assertEqual(c.steer, 2.0) self.assertEqual(c.brake, 3.0) self.assertEqual(c.hand_brake, True) self.assertEqual(c.reverse, True)
Example #11
Source File: basic_agent.py From macad-gym with MIT License | 5 votes |
def run_step(self, debug=False): """ Execute one step of navigation. :return: carla.VehicleControl """ # is there an obstacle in front of us? hazard_detected = False # retrieve relevant elements for safe navigation, i.e.: traffic lights # and other vehicles actor_list = self._world.get_actors() vehicle_list = actor_list.filter("*vehicle*") lights_list = actor_list.filter("*traffic_light*") # check possible obstacles vehicle_state, vehicle = self._is_vehicle_hazard(vehicle_list) if vehicle_state: if debug: print('!!! VEHICLE BLOCKING AHEAD [{}])'.format(vehicle.id)) self._state = AgentState.BLOCKED_BY_VEHICLE hazard_detected = True # check for the state of the traffic lights light_state, traffic_light = self._is_light_red(lights_list) if light_state: if debug: print('=== RED LIGHT AHEAD [{}])'.format(traffic_light.id)) self._state = AgentState.BLOCKED_RED_LIGHT hazard_detected = True if hazard_detected: control = self.emergency_stop() else: self._state = AgentState.NAVIGATING # standard local planner behavior control = self._local_planner.run_step() return control
Example #12
Source File: agent.py From macad-gym with MIT License | 5 votes |
def emergency_stop(self): """ Send an emergency stop command to the vehicle :return: """ control = carla.VehicleControl() control.steer = 0.0 control.throttle = 0.0 control.brake = 1.0 control.hand_brake = False return control
Example #13
Source File: spawn_control.py From macad-gym with MIT License | 5 votes |
def __init__(self, world, start_in_autopilot): self._autopilot_enabled = start_in_autopilot self._control = carla.VehicleControl() self._steer_cache = 0.0 world._vehicle.set_autopilot(self._autopilot_enabled) world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
Example #14
Source File: no_rendering_mode.py From scenario_runner with MIT License | 5 votes |
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)
Example #15
Source File: ERDOSTrack4Agent.py From pylot with Apache License 2.0 | 5 votes |
def run_step(self, input_data, timestamp): game_time = int(timestamp * 1000) self._logger.debug("Current game time {}".format(game_time)) erdos_timestamp = erdos.Timestamp(coordinates=[game_time]) if not self._sent_open_drive: # We do not have access to the open drive map. Send top watermark. self._sent_open_drive = True self._open_drive_stream.send( erdos.WatermarkMessage(erdos.Timestamp(is_top=True))) self.send_waypoints_msg(erdos_timestamp) for key, val in input_data.items(): if key == 'ground_objects': self.send_ground_objects(val[1], erdos_timestamp) elif key == 'scene_layout': self.send_scene_layout(val[1], erdos_timestamp) elif key == 'can_bus': self.send_pose_msg(val[1], erdos_timestamp) elif key == 'gnss': self.send_gnss_data(val[1], erdos_timestamp) else: self._logger.warning("Sensor {} not used".format(key)) # Wait until the control is set. while True: control_msg = self._control_stream.read() if not isinstance(control_msg, erdos.WatermarkMessage): output_control = carla.VehicleControl() output_control.throttle = control_msg.throttle output_control.brake = control_msg.brake output_control.steer = control_msg.steer output_control.reverse = control_msg.reverse output_control.hand_brake = control_msg.hand_brake output_control.manual_gear_shift = False return output_control
Example #16
Source File: carla_operator.py From pylot with Apache License 2.0 | 5 votes |
def _apply_control_msg(self, msg): # Transform the message to a carla control cmd. vec_control = carla.VehicleControl(throttle=msg.throttle, steer=msg.steer, brake=msg.brake, hand_brake=msg.hand_brake, reverse=msg.reverse) self._client.apply_batch_sync([ carla.command.ApplyVehicleControl(self._ego_vehicle.id, vec_control) ])
Example #17
Source File: ego_vehicle.py From ros-bridge with MIT License | 5 votes |
def update(self, frame, timestamp): """ Function (override) to update this object. On update ego vehicle calculates and sends the new values for VehicleControl() :return: """ self.send_vehicle_msgs() super(EgoVehicle, self).update(frame, timestamp) no_rotation = Transform() no_rotation.rotation.w = 1.0 self.publish_transform(self.get_ros_transform( no_rotation, frame_id=str(self.get_id()), child_frame_id=self.get_prefix()))
Example #18
Source File: basic_agent.py From Carla-ppo with MIT License | 5 votes |
def run_step(self, debug=False): """ Execute one step of navigation. :return: carla.VehicleControl """ # is there an obstacle in front of us? hazard_detected = False # retrieve relevant elements for safe navigation, i.e.: traffic lights # and other vehicles actor_list = self._world.get_actors() vehicle_list = actor_list.filter("*vehicle*") lights_list = actor_list.filter("*traffic_light*") # check possible obstacles vehicle_state, vehicle = self._is_vehicle_hazard(vehicle_list) if vehicle_state: if debug: print('!!! VEHICLE BLOCKING AHEAD [{}])'.format(vehicle.id)) self._state = AgentState.BLOCKED_BY_VEHICLE hazard_detected = True # check for the state of the traffic lights light_state, traffic_light = self._is_light_red(lights_list) if light_state: if debug: print('=== RED LIGHT AHEAD [{}])'.format(traffic_light.id)) self._state = AgentState.BLOCKED_RED_LIGHT hazard_detected = True if hazard_detected: control = self.emergency_stop() else: self._state = AgentState.NAVIGATING # standard local planner behavior control = self._local_planner.run_step() return control
Example #19
Source File: agent.py From Carla-ppo with MIT License | 5 votes |
def run_step(self, debug=False): """ Execute one step of navigation. :return: control """ control = carla.VehicleControl() if debug: control.steer = 0.0 control.throttle = 0.0 control.brake = 0.0 control.hand_brake = False control.manual_gear_shift = False return control
Example #20
Source File: agent.py From Carla-ppo with MIT License | 5 votes |
def emergency_stop(self): """ Send an emergency stop command to the vehicle :return: """ control = carla.VehicleControl() control.steer = 0.0 control.throttle = 0.0 control.brake = 1.0 control.hand_brake = False return control
Example #21
Source File: carla09interface.py From coiltraine with MIT License | 5 votes |
def __init__(self, world, start_in_autopilot): self._autopilot_enabled = start_in_autopilot self._control = carla.VehicleControl() self._command_cache = 2.0 world.hud.notification("Press 'H' or '?' for help.", seconds=4.0)
Example #22
Source File: carla_environment.py From tensorforce with Apache License 2.0 | 5 votes |
def reset(self, soft=False): self._reset_world(soft=soft) # reset actions self.control = carla.VehicleControl() self.prev_actions = self.DEFAULT_ACTIONS observation = env_utils.replace_nans(self._get_observation(sensors_data={})) return observation
Example #23
Source File: atomic_behaviors.py From scenario_runner with MIT License | 5 votes |
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
Example #24
Source File: brake_agent.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run_step(self): control = carla.VehicleControl() control.throttle = 0.0 control.brake = 1.0 control.hand_brake = True return control
Example #25
Source File: pid_agent.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 5 votes |
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])
Example #26
Source File: cl.py From Fruit-API with GNU General Public License v3.0 | 5 votes |
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()
Example #27
Source File: atomic_behaviors.py From scenario_runner with MIT License | 5 votes |
def __init__(self, actor, steer_value, throttle_value, name="Jittering"): """ Setup actor , maximum steer value and throttle value """ super(AddNoiseToVehicle, self).__init__(name, actor) self.logger.debug("%s.__init__()" % (self.__class__.__name__)) self._control = carla.VehicleControl() self._steer_value = steer_value self._throttle_value = throttle_value
Example #28
Source File: autonomous_agent.py From scenario_runner with MIT License | 5 votes |
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
Example #29
Source File: npc_agent.py From scenario_runner with MIT License | 5 votes |
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
Example #30
Source File: human_agent.py From scenario_runner with MIT License | 5 votes |
def __init__(self): """ Init """ self._control = carla.VehicleControl() self._steer_cache = 0.0