Hello ,
I am using Carla_0.9.4 on windows10.
Recently, I focus on motion planning problem. After one episode(sometimes when a collision occurs) , the scene must be reset.
1、I try to read and modify the codes of manual_control.py. It is troublesome and i do not want to call too many useless classes.
2、I know from Carla_0.9.1: Add collision event sensor, but i do not understand how it works. Could you please take some examples ? Even the simplest reaction(whether a collision occurs) is okay.
Help!
@nsubiron @iFuSiiOnzZ
Well, it is all about callback function now, so you need to create a collision sensor with the blueprint library and then define the function (in this case, function_handler()) that will be called each time the vehicle hits something.
blueprint_library = world.get_blueprint_library()
collision_sensor = world.spawn_actor(blueprint_library.find('sensor.other.collision'),
carla.Transform(), attach_to=vehicle)
collision_sensor.listen(lambda event: function_handler(event))
and then you can react to it
def function_handler(event):
lane_types = set(x.type for x in event.crossed_lane_markings)
text = ['%r' % str(x).split()[-1] for x in lane_types]
print('Crossed line %s' % ' and '.join(text))
Hope it helps
_EDIT: this is the wrong handler, use the one proposed by nsubiron_
Like that but you added the handler for the lane invasion sensor :wink: it would be something like this
def function_handler(event):
actor_we_collide_against = event.other_actor
impulse = event.normal_impulse
intensity = math.sqrt(impulse.x**2 + impulse.y**2 + impulse.z**2)
Got it !
Now i can enjoy coding.
Thanks a lot!
@nsubiron @JMorceaux
Like that but you added the handler for the lane invasion sensor it would be something like this
def function_handler(event): actor_we_collide_against = event.other_actor impulse = event.normal_impulse intensity = math.sqrt(impulse.x**2 + impulse.y**2 + impulse.z**2)
Hi @nsubiron , thanks for your answer along with your other replies that I benefitted from.
May I ask what do you suggest if we want to use collision detector in the synchronous mode?
1. We retrieve data from the queue each frame and wait out for those frames that no collision happened?
2. Or we only trigger an event when it happens and compare the timestamp or frame number?
Thanks!
Hi @shuhangchen
Have you find a way to use collision sensor with synchronous mode?
I am also trying to make a Vehicle Class where each vehicle has it own collision sensor. When I create many instances of this vehicle class, some of the vehicles has their collision sensor working and some don't, and I have no idea why. Hope anyone can help me on this matter.
Thanks in advance.
Most helpful comment
Like that but you added the handler for the lane invasion sensor :wink: it would be something like this