firmware version: 1.16.0alpha
so the problem is am unable to move the rover am able to arm it using mavros but not able to move the rover. as soon as i arm the rover it says its flying. also can i use mavsdk for rover or my only choice is mavros ?
What command do you use to control the rover?
If youre using offboard control command, I tried before and it’s not working. I am assuming it’s because the offboard mode that isn’t supported for rover airframe. So what I did is control it with manual control command and it works
Btw I am using MicroXRCE with ROS2. You can use both MicroXRCE or Mavros for ROS2 but for ROS1, you can only use Mavros.
You can also use MavSDK but I don’t recommend it if youre using ROS already.
ohh okey yeah just got to know that i can use ros2 and microxrce to directly control the rover. gonna try that now its much better. thanks. also are there any good examples where I can check out about how to do this for rovers.thanks a lot again
#!/usr/bin/env python3
import rospy
from geometry_msgs.msg import Twist
from mavros_msgs.srv import CommandBool, SetMode
from mavros_msgs.msg import State
class RoverControl:
def __init__(self):
rospy.init_node("rover_control_node", anonymous=True)
self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=10)
self.arm_service = rospy.ServiceProxy("/mavros/cmd/arming", CommandBool)
self.set_mode_service = rospy.ServiceProxy("/mavros/set_mode", SetMode)
self.state = State()
rospy.Subscriber("/mavros/state", State, self.state_callback)
rospy.sleep(2) # Wait for connection
def state_callback(self, msg):
self.state = msg
def arm_rover(self):
rospy.wait_for_service("/mavros/cmd/arming")
try:
self.arm_service(True)
rospy.loginfo("Rover Armed!")
except rospy.ServiceException as e:
rospy.logerr(f"Arming Failed: {e}")
def set_offboard_mode(self):
rospy.wait_for_service("/mavros/set_mode")
try:
self.set_mode_service(custom_mode="OFFBOARD")
rospy.loginfo("Offboard Mode Set!")
except rospy.ServiceException as e:
rospy.logerr(f"Failed to set mode: {e}")
def move_forward(self, duration=5):
rospy.loginfo("Moving Forward")
vel_msg = Twist()
vel_msg.linear.x = 1.0 # Move forward at 1m/s
start_time = rospy.Time.now().to_sec()
rate = rospy.Rate(10) # 10Hz
while rospy.Time.now().to_sec() - start_time < duration:
self.cmd_vel_pub.publish(vel_msg)
rate.sleep()
self.stop_rover()
def stop_rover(self):
rospy.loginfo("stopping Rover")
vel_msg = Twist()
self.cmd_vel_pub.publish(vel_msg)
if __name__ == "__main__":
rover = RoverControl()
rospy.sleep(2)
rover.arm_rover()
rover.set_offboard_mode()
rospy.sleep(2)
rover.move_forward(5)
the code i used was this
The latest main of PX4 supports offboard control for ackermann rovers now (Ackermann: Refactor by chfriedrich98 · Pull Request #24285 · PX4/PX4-Autopilot · GitHub)
Using ROS2 and MicroXRCE along with the px4-offboard example (GitHub - Jaeyoung-Lim/px4-offboard: Example of PX4 offboard control over microdds using python ROS 2), the ackermann rover can be controlled with position and velocity setpoints published in TrajectorySetpoint
.
You can try to use my code, GitHub. I tested it in both simulation (msg.data_source = 2) and real rover (msg.data_source = 1), for ackermann and differential drive rover
The main idea is here, Manual Control Code, this part:
def publish_manual_control_input(self):
msg = ManualControlSetpoint()
msg.timestamp = self.get_clock().now().nanoseconds
msg.timestamp_sample = self.get_clock().now().nanoseconds
msg.data_source = 1
msg.throttle = self.throttle_command
msg.valid = True
msg.sticks_moving = False
msg.pitch = 0.0
msg.roll = self.roll_command
msg.yaw = 0.0
msg.aux1 = 0.0 # -1.0 - LOW 1.0 - HIGH
msg.aux2 = 0.0
msg.aux3 = 0.0
msg.aux4 = 0.0
msg.aux5 = 0.0
msg.aux6 = 0.0
self.manual_control_input_publisher_.publish(msg)
self.get_logger().info(f"Manual control command sent: Throttle = {self.throttle_command}; Roll = {self.roll_command}")
The idea I got from, ARK-Electronics/ark_rover_demo
Hope you can get some insight from that
Do you have any example code that specifically for a rover control through TrajectorySetpoint?
So far I couldn’t made it works. Because as I know TrajectorySetpoint is used for Offboard mode which is (also as I understand from the documentation) not supported in any PX4 rover firmware (cmiw). Maybe in some specific firmware version, it was supported, like in version 1.15
The px4-offboard package publishes TrajectorySetpoint
and should enable offboard control of ackermann rover. This commit allows the ackermann rover to be controlled with position and velocity setpoints.
alright thanks for the good news that by using px4 +ros2 we can control our rover on offboard mode. also do you know any places where we can see and get referance am new in this field
Alright, I’ll check that again. Thanks!
alright currently trying to do mission mode by using QGC but nothing is working rover not moving