shawn-pi-noob
Posts: 10
Joined: Mon Jun 10, 2013 6:37 am
Location: Meridian, MS, USA

pi car

Mon Jun 24, 2013 11:36 am

i have a program to for the raspberry pi to drive a car and i was wondering how my program could automatically do what it is supposed to do right when the key is pressed. my program is

Code: Select all

# car controls

def left():
   print "turning left"
   return ()
   
def forword():
   print "forword"
   return ()

def down():
   print "reverse"
   return ()

def right():
   print "turning right"
   return ()

   
# main 

while 1:
   
   inkey = raw_input()
   if inkey == "a":
      left()
   elif inkey == "w":
      forword()
   elif inkey == "s":
      down()
   elif inkey == "d":
      right()
   else:
      print "Other input"
   
print "Out of loop"
eventually it will start gpio for dc motor and servos.

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: pi car

Mon Jun 24, 2013 3:47 pm

Who will be the first to insert their own "will it crash" joke?
Antikythera

jawbonegroove
Posts: 37
Joined: Sun Jun 23, 2013 8:17 am
Location: pdx/usa
Contact: Website

Re: pi car

Mon Jun 24, 2013 6:02 pm

we have a winner!

shawn-pi-noob
Posts: 10
Joined: Mon Jun 10, 2013 6:37 am
Location: Meridian, MS, USA

Re: pi car

Tue Jun 25, 2013 6:54 pm

well i need to make it to where if i hold down w it will loop the dc motor going forward so i wouldn't have to press w then enter.

User avatar
joan
Posts: 14884
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: pi car

Tue Jun 25, 2013 7:02 pm

shawn-pi-noob wrote:well i need to make it to where if i hold down w it will loop the dc motor going forward so i wouldn't have to press w then enter.
You need to detail the mechanics of the car and its motors. Do you have a means of controlling the motors?

User avatar
solar3000
Posts: 1051
Joined: Sat May 18, 2013 12:14 am

Re: pi car

Wed Jun 26, 2013 1:11 pm

Yes, it would be much more interesting if you show us more.
Tell us about the bot.
Antikythera

shawn-pi-noob
Posts: 10
Joined: Mon Jun 10, 2013 6:37 am
Location: Meridian, MS, USA

Re: pi car

Fri Jun 28, 2013 4:06 am

Well im planning on taking this 2 foot car body and loading it up with the rpi me and my dad thaught of it and adafruit tutorials have been helping some but can someone PLEASE help with the programing?????? :?:

User avatar
DeeJay
Posts: 2027
Joined: Tue Jan 01, 2013 9:33 pm
Location: East Midlands, UK

Re: pi car

Fri Jun 28, 2013 6:59 am

I think the enquirer wants to know how to get the controlling loop to respond to a single keypress?

It's not 'straightforward' - Python wants to deal with lines of information terminated by a '\n' (newline) character, which is what the [Return] key gives you.

There is an example of how to deal with it here - http://www.raspberrypi.org/phpBB3/viewt ... 88#p115238

I hope I've understood the question correctly and that you can use this as a part of your program.
How To Ask Questions The Smart Way: http://www.catb.org/~esr/faqs/smart-questions.html
How to Report Bugs Effectively: http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

dankey
Posts: 1
Joined: Fri Jun 28, 2013 8:29 am

Re: pi car

Fri Jun 28, 2013 8:38 am

who is the winner? by the way .I want someone help me pick a gift for my brother as birthday present http://www.rctophobby.com/rc-helicopter ... lkera.html is ok?

Return to “General discussion”