MAVROS companion computer connection problems when connected using USB

I am trying to setup a companion computer where the pixhawk2 cube is connected to the companion computer via USB cable (connected to the micro USB port on pixhawk). For testing, I have QGC on the same computer, and I connect using UDP. I can see the device connected to /dev/ttyACM0. When I start the mavros node (in ROS melodic) with px4.launch file, it shows that the mavros node is started, but there is no heartbeat nor connection to pixhawk.
roslaunch mavros px4.launch fcu_url:=/dev/ttyACM0:921600 gcs_url:="udp://@localhost:14550"
Below is the relevant output.

[ INFO] [1660313567.229164677]: Autostarting mavlink via USB on PX4
[ INFO] [1660313567.229234680]: Built-in SIMD instructions: SSE, SSE2
[ INFO] [1660313567.229250439]: Built-in MAVLink package version: 2022.3.3
[ INFO] [1660313567.229273267]: Known MAVLink dialects: common ardupilotmega ASLUAV AVSSUAS all development icarous matrixpilot paparazzi standard storm32 uAvionix ualberta
[ INFO] [1660313567.229290611]: MAVROS started. MY ID 1.240, TARGET ID 1.1

Nothing happens after this.

It is the same when I try to connect to mavlink shell. When I run ./Tools/mavlink_shell.py /dev/ttACM0, it just shows
Connecting to MAVLINK...

As a workaround, if I make a serial connection in GCS after I connect the USB cable, I can see that the pixhawk is connected to it. After this, if I close GCS (remove the serial connection to GCS) and try starting the mavros node again (with the same launch parameters), it connects, and I can connect from GCS using UDP.

[ INFO] [1660313567.229164677]: Autostarting mavlink via USB on PX4
[ INFO] [1660313567.229234680]: Built-in SIMD instructions: SSE, SSE2
[ INFO] [1660313567.229250439]: Built-in MAVLink package version: 2022.3.3
[ INFO] [1660313567.229273267]: Known MAVLink dialects: common ardupilotmega ASLUAV AVSSUAS all development icarous matrixpilot paparazzi standard storm32 uAvionix ualberta
[ INFO] [1660313567.229290611]: MAVROS started. MY ID 1.240, TARGET ID 1.1
[ INFO] [1660313567.229465365]: IMU: Attitude quaternion IMU detected!
[ INFO] [1660313567.229534213]: IMU: High resolution IMU detected!
[ INFO] [1660313567.230388767]: CON: Got HEARTBEAT, connected. FCU: PX4 Autopilot

I am able to connect to mavlink shell also after the workaround.

I have to always make this one time serial connection to GCS after each time I reconnect the pixhawk to the computer using USB. Can anyone help me fix this issue? I don’t want to (it might be even possible to) start GCS and connect pixhawk serially.

Cheers!