Im training an RL model using SITL in Gazebo, where the model is connected through dronekit.
At every crash a new world is loaded and the SITL gets re instantiated in that world.
As I Need to be in GUIDED mode for velocity commands, i need to wait for EKF3 is using GPS every time . Due to there being 100’s- 1000’s of trials thats a lot of waiting.
Does anyone know whether its possible to just save the vehicle state reached just before taking of? As though the worlds differ, the spawn point remains excactly the same. Therefor the EKF is calibrating to the exact same values every time.
After over a month of research, I have finally found a way! (Still a workaround, could be more optimised)
At the desired moment of respawn enter ACRO mode - self.vehicle.mode = “ACRO”
Pauze the simulation:
b) Python:
pauze = Node()
service_pauze = f"world/{self.world.name.split(‘.’)[0]}/control"
pauze_msgs = WorldControl()
pauze_msgs.pause = True
p = pauze.request(
service=service_pauze,
request=pauze_msgs,
timeout=300,
request_type=gz.msgs10.world_control_pb2.WorldControl,
response_type=gz.msgs10.boolean_pb2.Boolean
)
or
b ) CLI: gz service -s /world/WORLD_NAME/control --reqtype gz.msgs.WorldControl --reptype gz.msgs.Boolean --timeout 3000 --req ‘pause: true’
TELEPORT (to a place on the ground)
a) Python:
future = tp.request(
service=service_name,
request=req,
timeout=300,
request_type=gz.msgs10.pose_pb2.Pose,
response_type=gz.msgs10.boolean_pb2.Boolean
)
or
START SIMULATION
Same as pauze but now pause == False. so pauze_msgs.pause = False or ‘pause: True’
Wait a couple of seconds
set vehicle mode GUIDED – vehicle.mode = “GUIDED”
arm throttle - vehicle.arm()
takeoff 5 - vehicle.simple_takeoff(5)
the vehicle is ready to take commands again.
There you go for all my future AI / Robotics fanatics (and past that had this struggle)
SIDENOTE: After crashing a dozen times at quite some speed and teleporting often the SITL is going to give errors, so code a safety that does respawn the whole SITL + gazebo whenever the altitude of the vehicle doesnt change after the takeoff sequence:
if abs(self.drone.vehicle.location.local_frame.down) < 1:
self.drone.kill_simulation() – write this function yourself or ask me nicely XD