StarlingUAS / ProjectStarling

BRL Flight Arena Infrastructure 2.0
Other
16 stars 3 forks source link

Update PX4 with Jinja Spawning #126

Closed mhl787156 closed 2 years ago

mhl787156 commented 2 years ago

This PR updates the PX4 to latest stable release of v0.12.3. Closes #125

So far primary changes have included deprecating the use of xacro and replacing with jinja2. This required the xacro_launch.sh script to be updated to use jinja2. It has also been renamed to a vehicle_setup.sh.

Needs further testing to determine if other breaking changes exist.

mhl787156 commented 2 years ago

This works well for single drone spawning, but breaks for multi drone spawning using docker-compose due to a port conflict. I cannot work out which port and where the port conflict comes from as all SITL ports have been ensured to be different based on spawning implementation (vehicle_spawn.sh):

python3 ${src_path}/Tools/sitl_gazebo/scripts/jinja_gen.py \
    ${src_path}/Tools/sitl_gazebo/models/${PX4_SIM_MODEL}/${PX4_SIM_MODEL}.sdf.jinja ${src_path}/Tools/sitl_gazebo \
    --mavlink_tcp_port ${PX4_SITL_PORT} \
    --mavlink_udp_port $((${PX4_OFFBOARD_PORT_BASE}+${PX4_INSTANCE})) \
    --mavlink_id ${PX4_SYSID} \
    # --gst_udp_port $((5600+${PX4_INSTANCE}))  \
    # --video_uri $((5600+${PX4_INSTANCE}))  \
    # --mavlink_cam_udp_port $((14530+${PX4_INSTANCE})) \

(Jinja_gen.py: https://github.com/PX4/PX4-SITL_gazebo/blob/60d6844e17919e8d57aafb3a0c25064df920cfc3/scripts/jinja_gen.py)

When using docker-compose-2.yml, the port conflict comes from one of the mavros nodes. The one which starts first is fine, the second gets a port conflict and subsequently fails. Also since it is run_ros1.sh failing it points to the ROS1 mavros being the issue.

mavros_1_1           | [run_ros1.sh-1] ROS_MASTER_URI=http://localhost:11311
mavros_1_1           | [run_ros1.sh-1] 
mavros_1_1           | [run_ros1.sh-1] setting /run_id to 4d947b2e-4ded-11ec-b4cf-d8f2ca2c02f9
mavros_1_1           | [run_ros1.sh-1] Exception ignored in thread started by: <bound method XmlRpcNode.run of <rosgraph.xmlrpc.XmlRpcNode object at 0x7f0e3a3adb50>>
mavros_1_1           | [run_ros1.sh-1] Traceback (most recent call last):
mavros_1_1           | [run_ros1.sh-1]   File "/opt/ros/noetic/lib/python3/dist-packages/rosgraph/xmlrpc.py", line 249, in run
mavros_1_1           | [run_ros1.sh-1]     self._run()
mavros_1_1           | [run_ros1.sh-1]   File "/opt/ros/noetic/lib/python3/dist-packages/rosgraph/xmlrpc.py", line 318, in _run
mavros_1_1           | [run_ros1.sh-1]     self._run_init()
mavros_1_1           | [run_ros1.sh-1]   File "/opt/ros/noetic/lib/python3/dist-packages/rosgraph/xmlrpc.py", line 268, in _run_init
mavros_1_1           | [run_ros1.sh-1]     self.server = ThreadingXMLRPCServer((bind_address, port), log_requests)
mavros_1_1           | [run_ros1.sh-1]   File "/opt/ros/noetic/lib/python3/dist-packages/rosgraph/xmlrpc.py", line 146, in __init__
mavros_1_1           | [run_ros1.sh-1]     SimpleXMLRPCServer.__init__(self, addr, SilenceableXMLRPCRequestHandler, log_requests)
mavros_1_1           | [run_ros1.sh-1]   File "/usr/lib/python3.8/xmlrpc/server.py", line 605, in __init__
mavros_1_1           | [run_ros1.sh-1]     socketserver.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
mavros_1_1           | [run_ros1.sh-1]   File "/usr/lib/python3.8/socketserver.py", line 452, in __init__
mavros_1_1           | [run_ros1.sh-1]     self.server_bind()
mavros_1_1           | [run_ros1.sh-1]   File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind
mavros_1_1           | [run_ros1.sh-1]     self.socket.bind(self.server_address)
mavros_1_1           | [run_ros1.sh-1] OSError: [Errno 98] Address already in use
mavros_2_1           | [run_ros1.sh-1] RLException: run_id on parameter server does not match declared run_id: 4d947b2e-4ded-11ec-b4cf-d8f2ca2c02f9 vs 4d8c1d3a-4ded-11ec-8902-d8f2ca2c02f9
mavros_2_1           | [run_ros1.sh-1] The traceback for the exception was written to the log file
mavros_2_1           | [run_ros1.sh-1] ... logging to /root/.ros/log/4d8c1d3a-4ded-11ec-8902-d8f2ca2c02f9/roslaunch-mickey-laptop-toshiba-200626.log
mavros_2_1           | [run_ros1.sh-1] Checking log directory for disk usage. This may take a while.
mavros_2_1           | [run_ros1.sh-1] Press Ctrl-C to interrupt
mavros_2_1           | [run_ros1.sh-1] Done checking log file disk usage. Usage is <1GB.

I think this ros1->ros2 business is starting to really hamstring us, thankfully I think they are almost complete mavros extras was recently finished! (https://github.com/mavlink/mavros/projects/1)

@rob-clarke your choice as to whether to merge this partial fix for PX4

mhl787156 commented 2 years ago

It just occured to me that this will probably be a breaking change for the AP iris-with-standoffs model. Am unsure as to how to proceed here... Ignore that, the changes here will only affect PX4 Iris model.

mhl787156 commented 2 years ago

Configured and tested that it is working with the rest of the starling system again, My only concern is that the version is now quite far compared to that of the actual Clovers.... but oh well - maybe we should buy some PixRacers for the clovers...

mhl787156 commented 2 years ago

@rob-clarke this is ready to merge now I think pending review :) It will hopefully quickly fix any user's issues.

mhl787156 commented 2 years ago

Tested on windows with non-host, looks like it all works fine still! @rob-clarke