Society of Robots - Robot Forum

Software => Software => Topic started by: shyam4uall on October 21, 2008, 12:34:55 AM

Title: Moving a Robotic Car Using Keyboard
Post by: shyam4uall on October 21, 2008, 12:34:55 AM
I want to control the movement using the arrow keys.I have been able to control it to an extent,the problem arises when I want both the movement like FORWARD & LEFT and all those combinations.

The programming involves parallel port and I am not able to send two data or rather the transmitter (of a R/C car) is not able to handle both data at the same time.

Hope i am able to clear my doubts.Now how should I proceed?

I am using Matlab for this but if anyone can give a code in any other language that too will help me.
Title: Re: Moving a Robotic Car Using Keyboard
Post by: Razor Concepts on October 21, 2008, 04:06:24 AM
Is there a particular reason it needs to be controlled by arrow keys? Arrow keys arent proportional, using a joystick or game controller might be better.
Title: Re: Moving a Robotic Car Using Keyboard
Post by: ArcMan on October 21, 2008, 08:23:00 AM
... or rather the transmitter (of a R/C car) is not able to handle both data at the same time.

Are you sure?  Every decent R/C car transmitter/receiver transmits all channels at the same time.  Perhaps you don't have a decent one?  They can be had on ebay for cheap.

Title: Re: Moving a Robotic Car Using Keyboard
Post by: Admin on October 23, 2008, 07:02:26 AM
Can you tell us more about your setup (electronics, interface, etc)?

And if it's R/C, whats wrong with the remote? (a serious question!) :P
Title: Re: Moving a Robotic Car Using Keyboard
Post by: shyam4uall on October 28, 2008, 01:33:49 AM
Can you tell us more about your setup (electronics, interface, etc)?

And if it's R/C, whats wrong with the remote? (a serious question!) :P

There's nothing wrong with the remote when worked manually and also it can control both forward and left at the same time (edited what i said first that the remote is not able to handle) but what i am trying to do is that i have interfaced it with parallel port and want to control the movement from my PC.

I am using 4 bits from parallel port for its fours movement viz. forward(1 0 0 0)/backward(0 1 0 0 )/left(0 0 1 0)/right(0 0 0 1) but when i am pressing forward and left (both pressed) the last pressed key is only working.

my motor configuration is like one at the back for forward/backward and one at the front for left/right movement and i want to have both motor working when i press forward and left but only one motor is working (as the bit assigned to the key which is pressed last is send out though parallel port)

I am using MATLAB for this.
 
Title: Re: Moving a Robotic Car Using Keyboard
Post by: mbateman on October 28, 2008, 07:41:30 AM
I would guess that the problem is with you key detect routine on the PC. You need to check for each key separately and then combine the results.

Here is a link to some example VB code...

http://www.vb-helper.com/howto_detect_arrow_keys.html

You may be using a different language, but the concept will be the same.
Title: Re: Moving a Robotic Car Using Keyboard
Post by: jamort on October 29, 2008, 02:44:00 PM
I would suggest using a joint stick therefore you can make go as you wish and if the joint stick as a thing as if you were shooting on a jet game then you could maybe use that for arms or something....
Title: Re: Moving a Robotic Car Using Keyboard
Post by: Xone G0D on October 29, 2008, 05:19:03 PM
I would guess that the problem is with you key detect routine on the PC. You need to check for each key separately and then combine the results.

Here is a link to some example VB code...

http://www.vb-helper.com/howto_detect_arrow_keys.html

You may be using a different language, but the concept will be the same.

+1 mbateman Had the same problem playing In browser Flash Games...

 Might also be your keyboard it self, I did what you are trying to do a few years ago. At that time I had an old DELL keyboard and for some odd reason it wouldn't send the data of more than 2 keys at the same time.  As in, I pressed forward with arrows, and pressed letter H for horn, and then pressed left... only the forward and horn would work until I pressed Left again.. this made it difficult to accurately maneuver.  I got a GE keyboard and it solve that problem.  ;)


..X..
Title: Re: Moving a Robotic Car Using Keyboard
Post by: jamort on November 02, 2008, 07:37:08 AM
The problem is that you need to do controls such as below
...
up---move forward
down--go in reverse
left---rught motor turn on
right--left motor turn on
up+left---move forward while moving left
up+right--go forward while going right
etc...
one thing id do is make sure it is when key is pressed and not when key is touched
Title: Re: Moving a Robotic Car Using Keyboard
Post by: householdutensils on November 09, 2008, 05:30:27 PM
I'm not sure I quite understand but I'll give it a shot.

The parallel port outputs from the data pins an 8 bit representation from 0 to 255, if your using the first 4 pins, you should still be aware of the last 4:

0000 0000 

Given that the far right pin is the 2nd pin on the parallel port (the 1st data pin), you should be able to use case statements to output the following

(Ie outb(decimal, portnum))

Decimal = Binary (Action)

0 = 0000 0000 (All stop)
1 = 0000 0001 (Forward)
2 = 0000 0010 (Backward)
4 = 0000 0100 (Left)
8 = 0000 1000 (right)

5 = 0000 0101 (Forward Left)
9 = 0000 1001 (Forward Right)
6 = 0000 0110 (Back Left)
10 = 0000 1010 (Back right)

If your issue is that you seem to only detect the first key press, then you need to use a keydown/keyup (You can also use a keypress event, but it will mean you have to keep tapping the key) event and a set of boolean flag in one massive loop and then check the boolean flags when your ready to write to the parallel port like this pseudo code, the issue is probably that your trying to output to the parallel port immediately after a key is pressed, but you gotta check to see wether any others have been pressed or else it won't know:


Code: [Select]
if (keydown == uparrow) {
moveup = true;
}

if (keydown == downarrow) {
movedown = true;
}

if (keydown == leftarrow) {
moveleft = true;
}

if (keydown == rightarrow) {
moveright = false;
}

if (keyup == uparrow) {
moveup = false;
}

if (keyup == downarrow) {
movedown = false;
}

if (keyup == leftarrow) {
moveleft = false;
}

if (keyup == rightarrow) {
moveright = false;
}

Then ya gotta:

if (moveup = true && moveleft == true) {
outb(5, 0x0378);
}

etc etc etc

Obviously this is just a basic idea, but you get the point.


I hope this has been at least some help and I haven't made a fool of myself xD