Question:
How do I control a robot through a keyboard? JQUERY?
Singer925
2014-03-11 14:36:57 UTC
I am basically asking for some direction in terms of coding and programming.... I'm not sure what type of programming language or interface to use in this situation, and ANY help/advice would be VERY much appreciated.

The goal of the program is to use a constant input stream from a keyboard and take those signals (i.e. up arrow, space bar, whatever), and use those signals to control the servos and motors (i.e. rotate the servo, power the motor). So my main question is:

***What language/interface do I use to accomplish this? Where do I start? ***

I am in desperate need of some concrete direction and a place to start on this. Thank you.

BACKGROUND INFORMATION (not sure if this information is applicable/useful, but here it is anyway):
~controlled by a computer outside of the pool connected by a cable
~We are using a teensy 3.1 (Arduino) and beaglebone.
~The program is going to be used to control the four servos and
motors on the robot
~I have thorough experience in java, and am familiar with javascript.
Three answers:
2014-03-11 15:02:29 UTC
If you've got some programming skills then its a lot simpler than you think.



(Though it's not exactly a 'constant' stream. Commands go out as they're entered at the kbd or from whatever other programmed source.)



From the PC side you can send serial strings using literally any language that can talk to the serial port.



You find out what port to use by looking at Device Manger. Or some languages have facility to look that up automagically.



At arduino.cc look in the Refernce tab for Serial functions. There are examples in the ~/examples/##.Basics subdirectory of your Arduino installation. Those will tell you how to configure the bot to listen for commands, and when it receives one executes it.



You'll still need to use the conventional Arduino GUI to create the script (sketch) that downloads to the bot. On that side you'll tell the Arduino, for example, to turn 10 deg left when it receives a left-arrow ASCII character, or you can send it 10 left-arrow chars and the bot will turn 90 deg.



You can write this all yourself, or you can look for prepackaged Arduino bot languages. I've never looked at one myself but I know they're out there.



You might also want to look into Finite State Machine so all the different servos and motors and such in the bot can all work all at the same time and not just sequentially.
Ecko
2014-03-14 01:49:18 UTC
There are a number of steps to achieve this. Assuming the Arduino is in the robot, it would be programmed to receive ASCII characters (text strings) via the serial port. You would invent some sort of protocol, for example the Arduino sends a prompt when ready to receive commands, (i.e after receiving a command) and the commands are sent as one or more characters followed by a terminator (carriage return as "enter"). These can be whatever you decide. The Arduino receives this string, places it in a variable, and parses it to extract the meaning of the command. There could be a few rules in the protocol designed to reject false or garbled commands. These can be "it must be the expected characters, perhaps always proceeded by a preamble like a $ sign". The command from a keyboard could be automatically assembled into a packet with checksum and length for example, before it is transmitted. This allows a false command (due to noisy communications) to be detected if that is an issue.



This can be tested initially using a PC and a program called a terminal emulator, that just sends whatever you type out of the serial port as an ASCII character, and displays whatever is received. The connection at this stage is a serial RS232 connection, using a serial port from the PC and wires. If it has no serial port, use a USB to serial (RS232) converter. Also you could write your own software for the PC, which could assemble packets etc.



The communication connection has to be considered. If this is under water, (you sid the pool) radio can only be used by trailing an antenna on a float, with a cable connecting this to the underwater device. Radio does not work under water except in special (and impractical for you) cases. If it is a boat on the surface, you have an antenna as high as possible (on the mast).



What radio to use? There are all sorts of radio modules around, but you prefer one that sends ascii characters. In other words it has a serial port. One idea is to get a Bluetooth to RS232 dongle for each end. It simply connects to the RS232 line at each end. The computer end (a PC) could use a USB to Bluetooth dongle. Some laptops may already have a Bluetooth port. Here is an example of stand alone add-ons which work with any serial RS232 limk to replace the cable:

http://www.sena.com/products/industrial_bluetooth/

These may need some understanding of the serial port handshake wires too. The antenna is inside these dongles, so you might mount the whole thing (less the shell) on the mast. It needs to be in a waterproof case. You can buy what are called OEM modules, these have no case or serial connector. Search for such things.
Kaydell
2014-03-11 15:33:46 UTC
JavaScript is mostly used to program inside of web pages on the client side, running inside of a web browser.



Java seems like a better choice than JavaScript to me. Java has the advantage of being cross-platform compatible. For example, your Java applications would likely run on Mac, Windows, and Linux without modification. A disadvantage of Java is that it is a layer that separates you from the underlying operating system (OS) and has the external dependency of requiring the Java Virtual Machine (JVM) being present.



If you are developing a graphical user-interface (GUI) for Microsoft Windows, you may want to consider using C++. With C++, you're more tied to the particular OS that you are working with, but you are also talking more directly to the OS which could be a good thing. C++ programs are more self-contained in that they don't require something external to run (such as Java's JVM).



All in all, I would say that if you are only running in Windows, that you should consider C++. You may want to consider using Java since it's something that you know better than C++.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...