我創建了一個robot
,它將根據python
運行。對於它的自主程序,我需要它運行一定的距離(比如10英尺)。目前我正在使用時間讓它走向距離,但是有沒有什麼辦法可以在代碼中實現距離,以使其更精確。謝謝。機器人距離
這是舊機器人競賽的代碼,我做過了,我想通過改進來學習。我使用這些庫:
import sys
import wpilib
import logging
from time import time
這是代碼:
def autonomous_straight(self):
'''Called when autonomous mode is enabled'''
t0 = time()
slow_forward = 0.25
t_forward_time = 6.5
t_spin_time = 11
t_shoot_time = 11.5
while self.isAutonomous() and self.isEnabled():
t = time() - t0
if t < t_forward_time:
self.motor_left.set(slow_forward)
self.motor_right.set(-slow_forward)
self.motor_gobbler.set(1.0)
elif t < t_spin_time:
self.motor_left.set(2 * slow_forward)
self.motor_right.set(2 * slow_forward)
self.motor_shooter.set(-1.0)
elif t < t_shoot_time:
self.motor_mooover.set(.5)
else:
self.full_stop()
self.motor_gear.set(-1.0)
wpilib.Timer.delay(0.01)
self.full_stop()
你能告訴我們你正在使用的代碼嗎? –
這是一個真實的物理機器人還是隻是一個模擬? –
歡迎來到Stack Overflow!你能分享你正在使用的庫和你用來與硬件接口的東西嗎?另外考慮列出可用於控制程序的傳感器。真的沒有足夠的細節在這裏提供很多幫助。 –