Home        Store        Learn        Blog

Pymavlink with bluesim simulation

So i downloaded the bluesim simulation from github, and everything is working fine i connected it to Qground and managed to control the vehicle, but then i wanted to run a python script using pymavlink to move the vehicle just forward. i used the scripts form pymavlink Ardusub documentation and changed the port.
here is the script

import time
import sys
master = mavutil.mavlink_connection('tcp:127.0.0.1:5760')
master.wait_heartbeat()

def set_rc_channel_pwm(channel_id, pwm=1500):
    if channel_id < 1 or channel_id > 18:
        print("Channel does not exist.")
        return
    rc_channel_values = [65535 for _ in range(18)]
    rc_channel_values[channel_id - 1] = pwm
    master.mav.rc_channels_override_send(
        master.target_system,
        master.target_component,
        *rc_channel_values)

while True:
    try:
        set_rc_channel_pwm(5, 1600)
        time.sleep(0.2)
        print('command sent')
    except Exception as error:
        print(error)
        sys.exit(0)

but i still have errors!

BlueSim starts its own SITL instance, where it communicates via an intern json protocol for simulation.
If you want to use mavlink as a bridge, you’ll need to run SITL using the README instructions and with an argument for the mavlink endpoint for you script.

so the script i am using will work for the ROV in real world but won’t for the bluesim, is there any other simulation that you can hint me for to try the scripts, also about the readme you mean this ?https://github.com/bluerobotics/bluesim/blob/master/README.md

You can try SITL directly with QGC and mavproxy or SITL with gazebo.

yes

the gazebo simulation needs gazebo 7 or 8 and when ever I try downloading it the does not install and askes me to install gazebo 11, and what do you mean by SITL directly with QGC and mavproxy may you point me to where should i look for theses?

You can run the SITL “headless”. Check our SITL docs.

Your pymavlink seems to be working on MAVLink 1 mode (8 channels instead of 18 for RC_CHANNELS_OVERRIDE). I’m not sure why.

do you mean headless without the bluesim simulation, also why do you think its not possible to overcome the Qground with pymavlink script ?

Hi @Youssefattia_98 ,

Yes.

Would you mind telling us what exactly you are trying to achieve?

QGC and Pymavlink should be able to talk to the sim at the same time, with few issues.

Hello @williangalvani,
I am trying to apply simple forward command to move the ROV in the simulation without Qground.
thank you for replay and care.

I hacked an example together. Try this.

just perfect i added the heartbeat and everything went perfect. Thank you for your time

1 Like