Controlling RC-Car with keyboard
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Controlling RC-Car with keyboard

  1. #1
    Join Date
    Mar 2008
    Posts
    6

    Controlling RC-Car with keyboard

    Hi I'm new here.
    I am currently working on a program to control a RC-Car with my keyboard.
    I have written a code that allows me to send a number to a PIC-microcontroller which is connected to the original controller for the car over the serial port. I have made it so that I can send numbers from 1-8, each corresponding to a 'mode', so that 1 is drive straight forward, 2 is drive back etc. I currently write these numbers in a textbox and send them with a button in a windows forms application in C++ using Microsoft Visual C++.

    What I wanna do is enable the user to control the car with the arrow-key on the keyboard. That way I could do some simple stuff like sending a specific number to the microcontroller if a combination of the arrowkeys, like right+up, was pressed. This is where I run into some problems.

    I have been googling alot to find info on how to do this and have found several articles on the Microsoft website, but these solutions are all too advanced for me, and even though it seems to be easy-to-follow guides, I am unable to do this as my knowledge of C++ is very limited.
    (http://support.microsoft.com/kb/816190) and
    (http://support.microsoft.com/kb/320583/en-us)

    It seems simple enough, and so was the sending og bits to the microcontroller, but for some reason it seems to be very difficult to capture these keyevents, even though it was extremely easy in Javascript. Is there anyone here that would be so kind as to tell me how to do this in a simple way?

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Controlling RC-Car with keyboard

    What is a "windows forms application"? Are you using MFC? .NET? Or the Windows API directly?

    Viggy

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: Controlling RC-Car with keyboard

    Look up ROBOTICS on Microsoft/Lego equipment. MS has a language based on C# designed for robots. Lego has a kit, that they have in local schools around here. (6 thru 8th grade)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Mar 2008
    Posts
    6

    Re: Controlling RC-Car with keyboard

    Quote Originally Posted by MrViggy
    What is a "windows forms application"? Are you using MFC? .NET? Or the Windows API directly?

    Viggy
    I am using .NET, I forgot to mention that

    Quote Originally Posted by dglienna
    Look up ROBOTICS on Microsoft/Lego equipment. MS has a language based on C# designed for robots. Lego has a kit, that they have in local schools around here. (6 thru 8th grade)
    Thanks for the tip dglienna, but I believe I have that part covered.
    When I have this working I plan to expand the project to include automatic following a white line on the ground, by using two optical sensors to detect the light levels, emitted from two LED's, reflected from the ground. Therefore I will not be needing any traditional robotic movement algorithms, as the movement would be quite simple.
    I am using a normal RC-car for this, so I will not be able to recieve a signal from the car, only send it, as the controller isn't made to recieve signals. This means the microcontroller will have to be attached to the car directly in order to manipulate the car movements based on external values.

  5. #5
    Join Date
    Jul 2007
    Posts
    52

    Re: Controlling RC-Car with keyboard

    sorry for the OT, Keba i am trying to learn programming micropic with pc but i dunno where to start, documentation is so confusing. Do you use msn or other Im program? Or can I ask you some question about programming pic with pc via mail?

  6. #6
    Join Date
    Mar 2008
    Posts
    6

    Re: Controlling RC-Car with keyboard

    Quote Originally Posted by NasterMain
    sorry for the OT, Keba i am trying to learn programming micropic with pc but i dunno where to start, documentation is so confusing. Do you use msn or other Im program? Or can I ask you some question about programming pic with pc via mail?
    Well, I can send you the code I burned on the microcontroller, as well as the C++ code. I used a full 5 minutes to find out wheather was allowed to post a link of the source here, but didn't find the postingrules to codeguru anywhere, so here goes: http://rapidshare.com/files/10328839...ojekt.rar.html
    This includes a .JAL-file (the language used in the microcontroller) which basically reads the info sent from the computer, and writes that to the controller for the RC-Car. There is also a projects-folder for Microsoft Visual C++ 2005 Express Edition, that has the C++ project. This basically just sends the signal from the computer throught a serial COM port to the PIC.
    Due to some errors in transmission probably caused by interference, I used a method for sending that first sent a fixed number, then another fixed number, then the actual number I am trying to send, and then the sum of all those numbers. The microcontroller would then only send the signal to the RC-Car controller if the numbers from the pc matched the sum. This way I would not be able to write out any errors, but often the command from the pc would fail.
    All the commentary in the code is Danish, so you probably won't understand it, and the code is very messy, I apologice for that. I hope it can help you anyway.

    EDIT: By the way, as I am not aware of yur current progress NasterMain, Usually you have a microcontroller-burner connected to your pc that lets you burn software onto the microcontroller. I use JAL-edit for the programming, and Microbrn to burn it. I have then connected my pc to a MAX323 (I think its called) that translates the signal from the pc to a serial input my microcontroller can understand. the microcontroller I use (PIC16f628) has two ports, A and B, A with 5 bits and B with 8 bits. As I only need few bits for the serial communication, I have many leftover bits, and 4 of these are connected to some transisters controlling each button in the RC-Car controller. That is how my setup is.

    Can anyone help me with my original question?
    Last edited by Keba; March 29th, 2008 at 08:05 PM.

  7. #7
    Join Date
    Mar 2008
    Posts
    6

    Re: Controlling RC-Car with keyboard

    Sorry for the doublepost.
    Does anyone know how to capture keys from the keyboard, in order to start different events based on it? I need to somehow do this, and it would be great if anyone had a samplecode for doing this in a .NET C++ forms application. Please post any thoughts you have on this matter.

    Keba

    EDIT: (SOLUTION FOUND)
    Thx for the help guys (irony included).
    I got help from my teacher who was nice enough to use his free time to look into this for me, as there was no help from mr. google, nor any forums.
    I am nice enough to include the code he got for me, so that I might help others.
    This traps the arrowkeys, and displays it in a textbox that has readonly=true & enable=false.
    http://rapidshare.com/files/104623821/tast.rar.html
    Last edited by Keba; April 3rd, 2008 at 03:24 PM. Reason: SOLUTION

  8. #8
    Join Date
    Jan 2013
    Posts
    6

    Re: Controlling RC-Car with keyboard

    Quote Originally Posted by Keba View Post
    I am nice enough to include the code he got for me, so that I might help others.
    This traps the arrowkeys, and displays it in a textbox that has readonly=true & enable=false.
    http://rapidshare.com/files/104623821/tast.rar.html
    "I used a full 5 minutes to find out wheather was allowed to post a link of the source here, but didn't find the postingrules to codeguru anywhere, so here goes: http://rapidshare.com/files/10328839...ojekt.rar.html"


    The links are corrupted...
    Could U please relink them?

  9. #9
    Join Date
    Jan 2013
    Posts
    6

    Re: Controlling RC-Car with keyboard


  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,229

    Re: Controlling RC-Car with keyboard

    Dude, that poster hasn't been here for 5 years.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center