我正试图把无人驾驶飞机绕着车绕着圆形轨道飞行,停在地面上。如果无人机最初是垂直于前左轮胎的固定距离的话,它是绕着汽车的圆周方向(顺时针方向)飞行的。但是,当无人机被放置在汽车的右侧或左侧时,无人机从放置点开始以圆形轨道飞行,离车太远,而不是像Pic 2所示的那样绕车飞行。
图1-
图2-
这是我的密码:
var flightController: DJIFlightController?
var timer: Timer?
var radians: Float = 0.0
let velocity: Float = 0.1
@IBAction func actionOrbit(_ sender: Any) {
setupFlightMode()
// Schedule the timer at 2Hz while the default specified for DJI is between 5 and 25Hz
timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(timerLoop), userInfo: nil, repeats: true)
}
private func setupFlightMode() {
// Reset radians
radians = 0.0
// Invalidate timer if necessary
// This allows switching between flight modes
if timer != nil {
print("invalidating")
timer?.invalidate()
}
}
@objc func timerLoop() {
radians += velocity
if(radians >= 6.283){ //360 degree it will stop the drone once the one orbit is complete
self.timer?.invalidate()
radians = 0.0
self.verticalMoveUpward()
//vertical throttle and then move forward and land
return
}
x = cos(radians)
y = sin(radians)
z = 0
}
private func sendControlData(x: Float, y: Float, z: Float) {
print("Sending x: \(x), y: \(y), z: \(z), yaw: \(yaw)")
// Construct the flight control data object
var controlData = DJIVirtualStickFlightControlData()
controlData.verticalThrottle = z //throttle // in m/s
controlData.roll = x //roll
controlData.pitch = y //pitch
controlData.yaw = self.yaw
// Send the control data to the FC
self.flightController?.send(controlData, withCompletion: { (error: Error?) in
// There's an error so let's stop
if error != nil {
print("Error sending data")
// Disable the timer
self.timer?.invalidate()
}
else{
print("Error sending data \(error.debugDescription)")
}
})
}
使用的无人机模型: Air 2S
问题1:无论无人机的位置如何,我怎样才能让无人机绕着汽车在圆形轨道上飞行?
问题2:如何确定圆轨道的半径(以米或英尺为单位)?目前,每0.5秒,它继续增加半径0.1,直到达到6.283。是否与评论中提到的频率,即2Hz有关。
问题3:根据文档,有一个热点任务,可以识别和设置对象。然后无人机就可以绕着它飞行。无人机模型是否有可能:空气2S,如果是,我如何提供半径(米),而不是纬度和经度。
发布于 2022-05-28 21:40:08
如果我理解,你纠正你试图改变滚动和音高作为一个函数的时间?它永远不会起作用。你必须检查无人机的位置,并让pid调节器调整错误,为你想要的路径。gps-pos由gps和imu融合而成.如果您没有gps,则只使用imu (也许是传感器),从起飞点开始使用lat/lon=0。您还将在risc中获得dji令人毛骨悚然的万向节运动,因为这是他们实现虚拟棒的一个缺陷。没什么可做的。
https://stackoverflow.com/questions/72337087
复制相似问题