2017-05-30 26 views
1

我只是想知道是否有人可以帮助我。我通过Raspberry Pi控制机器人,使用Python,并想知道如何改变机器人向后移动的时间量。目前只有半秒钟,我希望是三秒钟。我已经列出了我目前使用的代码。如何更改机器人倒退的持续时间

import time 
from gopigo import * # Has the basic functions for controlling the GoPiGo Robot 
import sys # Used for closing the running program 

now = time.time() 
future = now + 0.500 
while time.time() < future: 
    bwd() # Move backward 
stop() 
sys.exit() 
+1

'future = now + 3'? – roganjosh

回答

0

从我所看到的,现在的时间现在是(“0”)加上0.500(“半秒”)。 要更改为3秒,您需要执行“现在”加“3”。

试试这个,让我们知道!

import time 
from gopigo import * 
import sys 

now = time.time() 
future = now + 3 

while time.time() < future: 
    bwd() 

stop() 
sys.exit() 
+0

您的缩进已关闭。我不确定'stop()'是否应该放在'while'循环中。对我来说这似乎很奇怪,因为如果你为了保持某种移动而不得不在循环中重复调用'bwd()','stop()'方法的用途就会丢失。 – roganjosh

+0

@roganjosh你说得对,我刚刚复制/粘贴了OP代码。我现在编辑,谢谢。 – Gabri

+0

工作感谢你。 –

相关问题