I’m using an acceleration PD control for a quad simulation on ROS Gazebo using MAVROS PX4 SITL. I have the given the x and y accelerations in the feed-forward command and use the position and velocity for the feedback. The target is to reach a pre-defined setpoint. The quad just hovers at a fixed altitude and doesn’t reach the target position.
I have set all ignore flags except velocity flags and yaw rate to zero, as initially, the drone must reach the position of (0,0,4) and then take in the acceleration inputs.
My python class has this set for the type_mask self.sp.type_mask = int('010000111000', 2)
# My desired waypoints are
x1,y1,z1 = 4,3,4
while not cnt.state.armed:
modes.setArm()
rate.sleep()
# few setpoint messages before offboard mode
k=0
while k<10:
sp_pub.publish(cnt.sp)
rate.sleep()
k = k + 1
modes.setOffboardMode()
# use a goto function that assigns the desired altitude to a variable of message type PositionTarget
while not rospy.is_shutdown():
cnt.goto(0,0,int(h) ,0)
sp_pub.publish(cnt.sp)
rate.sleep()
# now once altitude reached, use acceleration setpoint function
while not rospy.is_shutdown():
#based on a PD controller class function, the required x and y accel are calculated and set in this loop until the error is small
# self.sp.acceleration_or_force.x = self._accel_x
# self.sp.acceleration_or_force.y = self._accel_y
# publish into the topic 'mavros/setpoint_raw/local'
sp_pub.publish(cnt.sp)
Update: I’ve tried three topics to publish the accelerations into:
/mavros/local_position/accel [geometry_msgs/AccelWithCovarianceStamped] , mavros/setpoint_accel/accel [geometry_msgs/Vector3Stamped] ,
/mavros/setpoint_raw/local [mavros_msgs/PositionTarget] (geometry_msgs/Vector3 acceleration_or_force)
The first and third caused no motion to the quad even though they published into the topics well (checked using ‘rostopic echo’). The second topic gave an initial acceleration in the x direction and quickly the drone crashed at a distance.
This is the brief outline of my first code:
# My desired waypoints are
x1,y1,z1 = 4,3,4
while not cnt.state.armed:
modes.setArm()
rate.sleep()
# few setpoint messages before offboard mode
k=0
while k<10:
sp_pub.publish(cnt.sp)
rate.sleep()
k = k + 1
modes.setOffboardMode()
# use a goto function that assigns the desired altitude to a variable of message type PositionTarget
while not rospy.is_shutdown():
cnt.goto(0,0,int(h) ,0)
sp_pub.publish(cnt.sp)
rate.sleep()
# now once altitude reached, use acceleration setpoint function
while not rospy.is_shutdown():
#based on a PD controller class function, the required x and y accel are calculated and set in this loop until the error is small
# self.sp.acceleration_or_force.x = self._accel_x
# self.sp.acceleration_or_force.y = self._accel_y
# publish into the topic 'mavros/setpoint_raw/local'
sp_pub.publish(cnt.sp)