树莓派控制(TANK) [英] Raspberry pi controlled (TANK)
问题描述
大家好,我创建了一个Raspberry pi控制坦克,为此我需要一个如下代码:
(4轮驱动,通过L298N电机驱动控制)
(这应该通过电脑控制)
当按下以下键时,应发生以下情况
*按向上箭头 - 坦克前进(所有4个车轮向前)
*按下箭头 - 坦克向后(所有4个车轮向后)
*按左箭头 - 坦克向左(左2个车轮向后,右2个车轮向前)
*按右箭头 - 坦克向右(右2个车轮向后,左2个车轮向前)
和额外的:
一个鼠标应该用来控制两个舵机,用于炮塔系统。(就像一个fpv游戏)
我尝试了什么:
通过OriginalGriff回答解决方案#1:
啊好的,谢谢。无论如何我没有想到这么快的回复。
好吧至少可以纠正这个:
//开始
hello guys , im creating an Raspberry pi controlled Tank , and for that i need an code which are as follows:
(4 wheel drive , controlled through L298N Motor Driver)
(this should be controlled through computer)
when pressed the following keys the following should happen
*press up arrow- the tank goes forward(all 4 wheels go forward)
*press down arrow - the tank goes backwards (all 4 wheels go backwards)
*press left arrow- tank goes left (left 2 wheels go backward, right 2 wheels go forward)
*press right arrow- tank goes right(right 2 wheels go backwards, left 2 wheels go forward)
and additional:
an mouse should be abbled to control an two servos ,for turret system.(like an fpv games)
What I have tried:
Answering to Solution #1 by OriginalGriff:
ah okay thanks for that. reply, anyhow i didnt thought of this much quick resppnse.
okay atleast can u correct this :
//start
# import curses and GPIO
import curses
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
#set GPIO numbering mode and define output pins
GPIO.setmode(GPIO.BOARD)
motor1a = 7
motor1b = 11
motor1e = 22
motor2a = 13
motor2b = 16
motor2e = 15
GPIO.setup(motor1a,GPIO.OUT)
GPIO.setup(motor1b,GPIO.OUT)
GPIO.setup(motor1e,GPIO.OUT)
GPIO.setup(motor2a,GPIO.OUT)
GPIO.setup(motor2b,GPIO.OUT)
GPIO.setup(motor2e,GPIO.OUT)
# Get the curses window, turn off echoing of keyboard to screen, turn on
# instant (no waiting) key response, and use special values for cursor keys
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.halfdelay(3)
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == curses.KEY_UP:
GPIO.output(motor1a,GPIO.HIGH)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.HIGH)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_DOWN:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.HIGH)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.HIGH)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_RIGHT:
GPIO.output(motor1a,GPIO.HIGH)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.HIGH)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_LEFT:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.HIGH)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.HIGH)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.HIGH)
elif char == 10:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
finally:
#Close down curses properly, inc turn echo back on!
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()
GPIO.cleanup()
//结束<上面代码中的
,电机一直运行直到按下下一个键,所以如何使其工作如按键运行,并在键被释放时停止
// end
in the above code , the motor keeps running until next key is pressed , so how to make it to work like "press key to run , and stop when the key is relesed"
推荐答案
因为我需要一个如下代码:
for that i need an code which are as follows:
它不是那样的工作。
我们不为你工作。
如果你想让别人写你的代码,你必须支付 - 我建议你去Freelancer.com并在那里问。
但要注意:你得到你付出的代价。支付花生,买猴子。
发展的概念就像这句话所暗示的那样:系统地运用科学和技术知识来满足特定的目标或要求。 BusinessDictionary.com [ ^ ]
这与有一个不一样快速谷歌并放弃,如果我找不到完全正确的代码。
所以要么付钱给别人去做,要么学会如何自己写。我们不是来为你做这件事。
It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to Freelancer.com and ask there.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
是的,谢谢你。无论如何我没有想到这么快的回复。
好吧至少可以纠正这个:
//开始
yeah okay thanks for that. reply, anyhow i didnt thought of this much quick resppnse.
okay atleast can u correct this :
//start
# import curses and GPIO
import curses
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
#set GPIO numbering mode and define output pins
GPIO.setmode(GPIO.BOARD)
motor1a = 7
motor1b = 11
motor1e = 22
motor2a = 13
motor2b = 16
motor2e = 15
GPIO.setup(motor1a,GPIO.OUT)
GPIO.setup(motor1b,GPIO.OUT)
GPIO.setup(motor1e,GPIO.OUT)
GPIO.setup(motor2a,GPIO.OUT)
GPIO.setup(motor2b,GPIO.OUT)
GPIO.setup(motor2e,GPIO.OUT)
# Get the curses window, turn off echoing of keyboard to screen, turn on
# instant (no waiting) key response, and use special values for cursor keys
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.halfdelay(3)
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == curses.KEY_UP:
GPIO.output(motor1a,GPIO.HIGH)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.HIGH)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_DOWN:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.HIGH)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.HIGH)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_RIGHT:
GPIO.output(motor1a,GPIO.HIGH)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.HIGH)
GPIO.output(motor2e,GPIO.HIGH)
elif char == curses.KEY_LEFT:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.HIGH)
GPIO.output(motor1e,GPIO.HIGH)
GPIO.output(motor2a,GPIO.HIGH)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.HIGH)
elif char == 10:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
finally:
#Close down curses properly, inc turn echo back on!
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()
GPIO.cleanup()
//结束<在上面的代码中,
,电机一直运行直到按下下一个键,所以如何使其工作如按键运行,并在键被释放时停止
// end
in the above code , the motor keeps running until next key is pressed , so how to make it to work like "press key to run , and stop when the key is relesed"
这篇关于树莓派控制(TANK)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!