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')
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
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.
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")