Hi.
I am communicating with a drone in offboard mode with the ROS2 node. So setting a specific position works well. However, now I am trying to do some simple teleoperation. When I set velocity in /fmu/in/trajectory_setpoint while publishing /fmu/in/offboard_control_mode set to velocity (others are false), I am getting weird behaviour.
It looks like even velocity is set drone behaves according to a position.
e.g. setting Z velocity to -0.5 doesn’t result in constant ascend, but the drone stabilized its position at -0.5m.
The meanings of the flags of offboard_control_mode is a bit misleading as the position controller module (which control the tracking of position AND velocity setpoints) is enabled if (not only if) offboard_control_mode has velocity or position enabled.
Therefore just setting velocity=true and postion=false does not stop the position controller from controlling both position and velocity.
You have to set to nan the position setpoints.
In your case the vehicle stops at -0.5 as a result of combining a 0 z-reference and a -5 vertical ascend.
Thank you very much. Now it works almost perfectly. But I still have some issues with yaw and yawspeed. Only these values behave absolutely. e.g. I have yaw velocity 1.0, and when I set it to yawspeed, it turns the drone about the absolute position and doesn’t go further. So what is a proper way to set yaw?
This was a handy piece of information. Are there some sources which describe this? Or do I have to read the code of PX4 autopilot?
Here is my function, which handles position and velocity.
def _keep_flying(self):
ts: TrajectorySetpoint = None
if self._desired_position is not None:
ts = TrajectorySetpoint(
timestamp=int(self._current_tick.nanoseconds / 1000),
position=[self._desired_position.x, self._desired_position.y, self._desired_position.z],
yaw=-3.14
)
elif self._desired_velocity is not None:
ts = TrajectorySetpoint(
timestamp=int(self._current_tick.nanoseconds / 1000),
velocity=[self._desired_velocity.xv, self._desired_velocity.yv, -self._desired_velocity.zv],
position=[None, None, None],
acceleration=[None, None, None],
jerk=[None, None, None],
yaw=0.0,
yawspeed=self._desired_velocity.yaw_v
)
if ts is not None:
self._trajectory_setpoint_pub.publish(ts)
self._offboard_mode_pub.publish(OffboardControlMode(
timestamp=int(self._current_tick.nanoseconds / 1000),
position=self._desired_position is not None,
velocity=self._desired_velocity is not None
))
yaw=None is not working because there is a check for float value. Therefore, it must be set as a float.
I need to control yawspeed the same way I control the velocity of xv and others.
My goal is to implement teleoperation. So when I press some key drone should move according to this key. It is working for x, y and z. But controlling rotation is not working. When I press, e.g. left arrow key drone turn round but only to a fixed value. It doesn’t continue in rotating. I think the absolute yaw value is considered, and a drone spins only to this value and not further, even though the key is still held.
You could check how the position mode is implemented: from RC to setpoints for the position controller module, after all in position mode the the RC controls the yawrate.
Or, do something like yaw = yaw + yawspeed * controllerSamplingTime