Sending commands through mavros to the BlueROV2

Hello. I have some troubles trying to make the camera move.
The camera channel - 8, you can see that inside the code I print status of the code in order to see whether it communicates at least. In QGroundcontrol the camera works, bluerov is armed, in manual mode.
What can be the problem?
Here is my code:

#!/usr/bin/env python

import rospy
from mavros_msgs.msg import OverrideRCIn

GIMBALL_CHANNEL = 8

def send_camera_commands():
    print('Starting node...')
    rospy.init_node('blue_rov_camera_node', anonymous=True)
    rc_pub = rospy.Publisher('/mavros/rc/override', OverrideRCIn, queue_size=10)

    command = OverrideRCIn()
    command.channels[GIMBALL_CHANNEL] = 1500  # Set camera tilt command (channel 2) to neutral position

    rate = rospy.Rate(10)  # Specify the rate (in Hz) at which to send commands

    print('Node started!')

    while not rospy.is_shutdown():
        # Send camera tilt up command
        print('Tilting up...')
        command.channels[GIMBALL_CHANNEL] = 1600  # Increase the value for tilting the camera up
        rc_pub.publish(command)
        #rate.sleep()

        # Wait for a moment
        rospy.sleep(2.0)

        # Send camera tilt down command
        print('Tilting down...')
        command.channels[GIMBALL_CHANNEL] = 1400  # Decrease the value for tilting the camera down
        rc_pub.publish(command)
        #rate.sleep()

        # Wait for a moment
        rospy.sleep(2.0)

if __name__ == '__main__':
    try:
        send_camera_commands()
        print('Done.')
    except rospy.ROSInterruptException:
        print('Interrupt')

image
this is what i see when i write rostopic echo /mavros/rc/override

Hi @vpetrov, welcome to the forum :slight_smile:

What do you mean by this? Is it not moving at all, or is it moving in a way that you didn’t expect/intend?

This thread may be worth referring to - the RC channels for camera control are not for the mount angle.

Hello. I have some troubles trying to make the camera move.
The camera channel - 8, you can see that inside the code I print status of the code in order to see whether it communicates at least. In QGroundcontrol the camera works, bluerov is armed, in manual mode.
What can be the problem?
Here is my code:

#!/usr/bin/env python

import rospy
from mavros_msgs.msg import OverrideRCIn

GIMBALL_CHANNEL = 8

def send_camera_commands():
print(‘Starting node…’)
rospy.init_node(‘blue_rov_camera_node’, anonymous=True)
rc_pub = rospy.Publisher(‘/mavros/rc/override’, OverrideRCIn, queue_size=10)
command = OverrideRCIn()
command.channels[GIMBALL_CHANNEL] = 1500  # Set camera tilt command (channel 2) to neutral position

rate = rospy.Rate(10)  # Specify the rate (in Hz) at which to send commands

print('Node started!')

while not rospy.is_shutdown():
    # Send camera tilt up command
    print('Tilting up...')
    command.channels[GIMBALL_CHANNEL] = 1600  # Increase the value for tilting the camera up
    rc_pub.publish(command)
    #rate.sleep()

    # Wait for a moment
    rospy.sleep(2.0)

    # Send camera tilt down command
    print('Tilting down...')
    command.channels[GIMBALL_CHANNEL] = 1400  # Decrease the value for tilting the camera down
    rc_pub.publish(command)
    #rate.sleep()
    # Wait for a momentrospy.sleep(2.0)
if **name** == ‘**main** ’:
try:
send_camera_commands()
print(‘Done.’)
except rospy.ROSInterruptException:
print(‘Interrupt’)

![image|619x61](upload://vo2WSlxDZtdTi6CMMKPf81ZTHhV.png)
this is what i see when i write rostopic echo /mavros/rc/override. 

I tried a different codes in order to see an executions from the bluerov2: 

#!/usr/bin/env python

import rospy
from geometry_msgs.msg import TwistStamped

def send_attitude_command():
    rospy.init_node('blue_rov_attitude_command', anonymous=True)
    att_pub = rospy.Publisher('/mavros/setpoint_attitude/cmd_vel', TwistStamped, queue_size=10)
    rate = rospy.Rate(10)  # Publish at a rate of 10 Hz

    # Create a TwistStamped message for attitude command
    command = TwistStamped()
    command.header.stamp = rospy.Time.now()
    command.twist.angular.x = 0.0  # Roll rate (set to 0 for no roll movement)
    command.twist.angular.y = 0.0  # Pitch rate (set to 0 for no pitch movement)
    command.twist.angular.z = 0.5  # Yaw rate (positive for clockwise rotation, negative for counter-clockwise)

    while not rospy.is_shutdown():
        att_pub.publish(command)
        rate.sleep()

if name == '__main__':
    try:
        send_attitude_command()
    except rospy.ROSInterruptException:
        pass

Hello, thank you for reaching me out.

The camera isn’t moving at all. When I send the command I try to observe the behaviour of the camera both on the Bluerov2 itself and in QGroundcontrol. And it doesn’t move.

I also tried some different commands and the bluerov2 doesn’t react accordingly.

Thank you for sharing the link, I’ll have a look at the thread and contact you ASAP.

Hello one more time!

I looked through the suggested thread and changed the code, but the camera isn’t rotating. Thinking whether this can be because of the mode or not? Tried for armed and disarmed the BlueROV2. May you help me regarding tilting of the camera?

#!/usr/bin/env python

import rospy
from mavros_msgs.msg import MountControl

def look_at(tilt, roll=0, pan=0):
    """
    Moves the camera gimbal to the given position.
    Args:
        tilt (float): Tilt angle in degrees.
        roll (float, optional): Roll angle in degrees.
        pan (float, optional): Pan angle in degrees.
    """
    mount_control_msg = MountControl()
    mount_control_msg.header.stamp = rospy.Time.now()
    mount_control_msg.mode = MountControl.MAV_MOUNT_MODE_RC_TARGETING #MountControl.MAV_MOUNT_MODE_MAVLINK_TARGETING
    mount_control_msg.pitch = tilt
    mount_control_msg.roll = roll
    mount_control_msg.yaw = pan

    mount_control_pub.publish(mount_control_msg)
    rospy.loginfo(f"Camera tilt: {tilt} degrees")

# Initialize ROS node
rospy.init_node('blue_rov_camera_node')

# Create the publisher for MountControl messages
mount_control_pub = rospy.Publisher('/mavros/mount_control/command', MountControl, queue_size=10)

rate = rospy.Rate(0.5)
angles = [45, -45, 0]
ang_idx = 0

# Wait for the publisher to connect
rospy.sleep(1.0)

while not rospy.is_shutdown():

    look_at(angles[ang_idx])
    ang_idx += 1
    ang_idx = ang_idx%3

    rate.sleep()

# Stop the ROS node
rospy.signal_shutdown('Camera control completed')
print("Camera control completed")

I sincerely appreciate your time!

after a while I gave up on the issue with the camera and decided to make thrusters rotate.

I wrote the code.

#!/usr/bin/env python

import rospy
from mavros_msgs.msg import OverrideRCIn

def control_thrusters():
    rospy.init_node('bluerov_thruster_control')
    rate = rospy.Rate(10)  # 10 Hz update rate

    # Create a publisher for the RC override topic
    rc_pub = rospy.Publisher('/mavros/rc/override', OverrideRCIn, queue_size=10)

    while not rospy.is_shutdown():
        # Create an instance of the OverrideRCIn message
        rc_msg = OverrideRCIn()

        # Set the desired PWM values for each thruster channel
        rc_msg.channels = [1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500]

        # Publish the RC message
        rc_pub.publish(rc_msg)

        rate.sleep()

if __name__ == '__main__':
    try:
        control_thrusters()
    except rospy.ROSInterruptException:
        pass

which publishes to the topic correctly


I do it when the bluerov2 is armed and disarmed.
But when I check the status of the /mavros/state it shows that the connection is in “false” status.

May you help me out with this?

Sorry for bothering, talking to myself. I fixed it.
image