Closed SExpert12 closed 3 months ago
This a code example for collision sensor, could you check if this is working for you? The attachment type is not necesary for sensors. After that could you check the logs? If you are not using a package they should be located in "CARLA_ROOT/Unreal/CarlaUE4/Saved/Logs"
from __future__ import print_function
import argparse
import glob
import math
import os
import sys
import time
try:
sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
sys.version_info.major,
sys.version_info.minor,
'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
pass
try:
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/carla')
except IndexError:
pass
import carla
def _on_collision(event):
print(f"Collision with {event.other_actor.type_id}")
def main():
client = carla.Client()
world = client.get_world()
bp_lib = world.get_blueprint_library()
spectator = world.get_spectator()
# Spawn the actor
bp = bp_lib.filter("*walker*")[0]
# bp.set_attribute('is_invincible', 'false')
walker = world.spawn_actor(bp, carla.Transform(carla.Location(200.7, 199.3, 0.2), carla.Rotation()))
bp = bp_lib.filter("*mkz_2020*")[0]
vehicle = world.spawn_actor(bp, carla.Transform(carla.Location(177.7, 198.8, 0.2), carla.Rotation()))
spectator.set_transform(carla.Transform(carla.Location(205.9, 193.2, 3.9), carla.Rotation(pitch=-29, yaw=135)))
collision_bp = bp_lib.find('sensor.other.collision')
sensor_collision = world.spawn_actor(collision_bp, carla.Transform(), attach_to=vehicle)
sensor_collision.listen(lambda event: _on_collision(event))
vehicle.apply_control(carla.VehicleControl(throttle=1))
for _ in range(400):
world.tick()
walker.destroy()
sensor_collision.destroy()
vehicle.destroy()
if __name__ == '__main__':
main()
We have updated dev branch, could you update your code and then try this again to know if that is working now?
Hello again, any updates? otherwise I will close this issue
Okay. Thanks. Let me check this.
Any updates?
Hi, currently I switched to imitation learning in CARLA. So I may not need it now. But really grateful for your support. Do you have any work experience for imitation learning in CARLA?
No but maybe someone does. Open a discussion or search for it in the discussions. I will be closing this issue for now.
Here is my code: I am working on synchronous mode with multiple vehicles. Here is my code: def main(): try: client = carla.Client('localhost', 2000) client.set_timeout(5.0) world = client.get_world() points = get_vehloc(world)
print("points are:",points)
finally: world.apply_settings(carla.WorldSettings(False,False,0)) if collision_sensor.is_alive: collision_sensor.destroy() print("simulation is over")
if name == 'main': try: main() except KeyboardInterrupt: pass finally: print("\n done")
Where should I write the code where collision sensor listen the collision? I am extracting information from world snapshot? Am I making any mistake in this code?
I want the information of the all the vehicles who are colliding and want to destroy them immediately as they are changing the route of other vehicles when they collide.
I have write in this code when l write code to listen to the collision sensor not working or getting error as segmentation fault.
I need help to resolve this issue.
Thanks in advance