PDA

View Full Version : [Question(s)] Best robotics Language?



trevben1
05-07-2009, 09:46 AM
hey all,
I was wondering which programming language you think is best for robotics. I'm a complete beginner in the research stage of building a robotic foosball player and I already know how to program in matlab and C+ but from what I can tell C# is the best. I want to make sure before I put in the effort to learn it though lol.

DresnerRobotics
05-07-2009, 10:03 AM
There really isn't one.

It is entirely a matter of personal preference and what works best for you. With today's technology pretty much any language that can talk to a comm port can be used for robotics.

trevben1
05-07-2009, 10:08 AM
Great! I like Matlab and find it really intuitive and since the a physical model will be fairly straight forward to program I think I'd love to use it. The one thing I wouldnt know how to do would be communicating with the comm port or usb whichever I end up using. I've had classes in both C+ and matlab but neither of them covered recieving any external inputs or delivering outputs.

lnxfergy
05-07-2009, 10:14 AM
As tybs said, varies based what you want to do.

Most vision software will be C/C++ because it is fast. Same goes for any lower level code.

C# probably isn't too much slower than C/C++, but, it is somewhat proprietary.

Quite a few people around here like Python, for it ease of use, but I would have a hard time telling you to do visual processing in Python.

If at any point you need to use a microcontroller to interface with the outside world, you'll probably have to program that in C.

-Fergs

darkback2
05-07-2009, 10:16 AM
A better question might be...what robotics platforms work with matlab...The dynamixel USB (http://www.trossenrobotics.com/robotis-bioloid-usb2dynamixel.aspx)thingy does, and can control dynamixel servos. I think the lego mindstorms NXT does also.

Hope this helps.

DB

trevben1
05-07-2009, 10:22 AM
At this point I really want to stay away from any sort of video tracking. I have some general knowledge of sensors and sensory technology but even that is sparse so I'd like to try to keep things in their simplest form. Using sensors will be fairly straightforward other than trying to track the ball.

Although this is a bit out of the scope of this conversation how would you bring input information into your program using C?

trevben1
05-07-2009, 10:25 AM
To darkback:
So that plugs into your comp and then gets connected to your I/0 board? (when I say complete beginner I mean it in the purest sense of the word lol)

lnxfergy
05-07-2009, 11:06 AM
At this point I really want to stay away from any sort of video tracking. I have some general knowledge of sensors and sensory technology but even that is sparse so I'd like to try to keep things in their simplest form. Using sensors will be fairly straightforward other than trying to track the ball.

Although this is a bit out of the scope of this conversation how would you bring input information into your program using C?

Note my post in your project thread.

All a PC has for interfacing with the world is ports: such as serial, parallel and USB. Note that serial and parallel ports (aka legacy ports) aren't found on many computers today, so you are stuck with USB->serial converters. You'll need an interface between outside electronics and your computer. Typically this is a microcontroller-based board that incorporates analog/digital input and output, pulse width modulation, etc. It then has some protocal that it can speak with your pc. Here's an example of communicating with an Arduino:
http://forums.trossenrobotics.com/showthread.php?t=2096

-Fergs

trevben1
05-07-2009, 02:28 PM
Thanks. i'll have to look into starting to re-learning C, most of the gameplay programming shouldn't be difficult but it will take some time to figure out passing algorithms and ball control. I'll probably just start with the goalie to get the blocking code down, shouldn't be to bad. And it looks like I can just tweak the code from the tutorial that you posted Inxfergy to communicate with the electronics.

darkback2
05-07-2009, 03:01 PM
That thing plus into the port on your computer, and connects directly to actuators (servo motors and such) which makes your computer the brains of your robot. That way you can use a language you already know.

cnobile
06-19-2009, 04:34 PM
I have been developing software for over 20 years and I can tell you that you want to use a language that you can develop quickly in. Languages are broken up into basically two types. C and it's derivatives like C++, Java, C#, etc are typed languages. The other type is fairly new (less than 10 years old or so) and are called dynamic (no typing) languages such as Python, Perl, Ruby, etc. For example you can develop in Python about 20 times faster than you could in Java. (Google this and you will see many comparisons.) The execution time on Python will be slower than Java and much slower than C, but you can get something working in hours instead of weeks. These days with the fast CPU that are around speed is not really a consideration anymore.

My preference is Python it is also very easy to learn especially if you already know another language. Within two weeks to a month you'll wonder why you never learned Python sooner. Perl and Ruby are also somewhat dynamic, but will be slower to learn.

For those that don't know what 'typing' is in a language it's the definition of the data type such as char, int, float, etc. Typed languages requires you to declare a type for everything whereas dynamic languages often require no typing at all like Python or minimal typing as in Perl or Ruby. Not having to worry about typing will increase your code output tremendously.

ScuD
06-19-2009, 05:05 PM
I don't have much experience with high-level languages (i'm more of an embedded coder) but I do agree on the point you state about Python.

The last project I finished at work required a GUI for Mac OSx, which is an OS I had never even seen(!), yet I wrote the entire thing in three 40h workweeks.
Take into account the fact that I wasted about a week getting the correct dependencies before figuring out I needed an OS update, that frankly astounded me.

The fact that no typecasting is necessary is indeed handy, yet confusing if you're used to working with 8-bit variables, especially when you're trying to average arrays ( well lists in this case) with variables lengths.

All in all I'd say it's a very handy scripting language and recommend it as well.

Adrenalynn
06-19-2009, 05:10 PM
I'm not anti-python by any means, but I think it's a stretch to declare that removing strict typing will increase code output THAT much. And then we need to talk about debugging time when the compiler does the wrong thing because the variable wasn't explicitly cast. (shobley's LCD problem that I helped him debug comes immediately to mind)

I think languages that are tooo loose are major contributors to a lot of maintenance nightmares down the road... That said, it can get silly-strict in the opposite direction too...

Welcome to the forum, btw!

mannyr7
06-19-2009, 07:23 PM
Note my post in your project thread.

All a PC has for interfacing with the world is ports: such as serial, parallel and USB. Note that serial and parallel ports (aka legacy ports) aren't found on many computers today, so you are stuck with USB->serial converters. You'll need an interface between outside electronics and your computer. Typically this is a microcontroller-based board that incorporates analog/digital input and output, pulse width modulation, etc. It then has some protocal that it can speak with your pc. Here's an example of communicating with an Arduino:
http://forums.trossenrobotics.com/showthread.php?t=2096

-Fergs

When I try to click on this link, it says I don't have sufficient privilages to access this page. Same thing when I try to click on some of the tutorial pages on the left pane. Tried cut and pasting the link into a new browser window, no luck either. ???

Adrenalynn
06-19-2009, 08:16 PM
Moderator has insufficient privs too. I'll note this to Alex.

lnxfergy
06-19-2009, 08:28 PM
I'm thinking its a page that disappeared when the new tutorial system was launched. Here's the Link I think: http://forums.trossenrobotics.com/tutorials/introduction-129/arduinocomputer-controlled-robot-2096/

-Fergs

mannyr7
06-20-2009, 01:31 AM
I'm thinking its a page that disappeared when the new tutorial system was launched. Here's the Link I think: http://forums.trossenrobotics.com/tutorials/introduction-129/arduinocomputer-controlled-robot-2096/

-Fergs

You could be right. This link works for me. Excellent tutorial!! Think I might try out Python over the next year and plan to order a Arduino Duemilanove which would share duties on a small tracked vehicle as well. This sound like a good start for Clyde v2?

cnobile
06-21-2009, 12:58 AM
Actually it's not a stretch. When you have strict typing in a language it affects almost everything you do in your code. You need to think about when you need or not need to cast variables, classes, methods, etc. But it's not just the typing issue that makes coding in python so fast. It's also the ease of determining scope (indentation), you don't need to type all those brackets or BEGIN and/or END statement like in Pascal or Ruby. Yes this may seem like a small thing, but it's all the small things in Python that together make Python so easy to code in and an extremely fast language to develop with.

In general debugging Python is quite easy, because you can test things very easily on the python CLI. I use ipython myself. Python is an interpreted language there is no compiler so there is never an error in a variables interpretation. I'm not saying you could confuse yourself by using a variable, lest say, as a list then later thinking it's a dictinary (hash map), but these problems are usually brought about by bad or inexperienced programming anyway. Writing good OO code in any language realy takes experience and having personal integrity about what you write.

I develop in C, Java, JavaScript, Perl, and Python, so I have experienced the worst of the issues with these languages. No languages is perfect or people wouldn't keep developing new ones.

If you want to continue this train of thought it might be best to email me directly as I don't want this to turn into something it shouldn't and it's really irrelevant to the topic.


I'm not anti-python by any means, but I think it's a stretch to declare that removing strict typing will increase code output THAT much. And then we need to talk about debugging time when the compiler does the wrong thing because the variable wasn't explicitly cast. (shobley's LCD problem that I helped him debug comes immediately to mind)

I think languages that are tooo loose are major contributors to a lot of maintenance nightmares down the road... That said, it can get silly-strict in the opposite direction too...

Welcome to the forum, btw!

Adrenalynn
06-21-2009, 01:45 AM
"bad or inexperienced" - or 96hrs on /4 off?

Non-conventional scope - I've fired people for much less... Makes future maintenance into a nightmare.



The upshot is that this is a religious question. You're wrong. I'm wrong. We're all wrong. Because there is no right answer...

Let's compare the deep image processing and neural networking performance between python and hand-optimized assembler... Guess which one loses there? So we could just as easily decide that hand-optimized assember is the "best robotics language". Of course, you could mention python making external calls and loading said optimized assembler, but now we`re just getting silly 'cause I can do that in just about any modern language...

There is no best tool in the toolbox. Your bestest hammer makes a crummy hex wrench and your favoritest hex wrench won't drive phillips screws to save its life.

robologist
06-21-2009, 02:37 AM
Interesting discussion, many things that I can't really understand the significance of. I was curious though, what is the general opinion of Forth? I've been somewhat involved with it in the past, and was fascinating about this particular interpreted flavor I used. It allowed you to write a short code word, then execute it, or even run a small program of words, while continuing to be "in contact" with the terminal to add more words, stop execution, start other words. The people working in it felt it offered a high degree of speed in development too. I, not being a programmer, could stand by and nod, but not really grasp some of the reasons they gave for this. Any thoughts, opinions?

cnobile
06-22-2009, 10:13 AM
Forth is a very old and not a very well supported language as opposed to C which is also old, but is very well supported. I'm not saying Forth is unusable, but not too many people use it except in university. In this respect it's like Pascal, which is not used very much in the real world either. People to help you with it may be hard to find, though most experienced programmers could help some.

My opinion here is to stick with a language that has a large used base especially if you're new to programming.

Shevek
06-22-2009, 11:06 AM
Also, on this topic, what is the opinion of Java? I've noticed that every time someone mentions it, the language is shouted down rather quickly, but for some reason it is just about all that is taught in most high schools anymore. The AP Computer Science test is in Java, and even entry level programming classes in college are always in Java. I'm therefore a mostly Java developer, and although I hated learning it, I kind of like the language now. What are the cons of this language that people seem to feel strongly about?

lnxfergy
06-22-2009, 11:16 AM
Also, on this topic, what is the opinion of Java? I've noticed that every time someone mentions it, the language is shouted down rather quickly, but for some reason it is just about all that is taught in most high schools anymore. The AP Computer Science test is in Java, and even entry level programming classes in college are always in Java. I'm therefore a mostly Java developer, and although I hated learning it, I kind of like the language now. What are the cons of this language that people seem to feel strongly about?

Java is interpreted, and is quite bloated, so runs not so fast. The language forces you into OO-design. Java programming typically ends up be resolved to a process of learning how to use "lots of little black boxes". It's cross-platform compatibility is a major myth, because many of these black boxes need to be implemented for each system... and all implementations don't work the same way.

Why is it taught in universities? Free cross-platform development tools and a wide-enough industry adoption to allow it to be a feasible language to teach. What happens when you teach intro to CS in Java? You end up with programmers who know how to use black boxes... and have no understanding of memory management among many other things. I have yet to find someone who really learned "programming and program design" in a CS1 course.. especially one taught in Java.

-Fergs

cnobile
06-23-2009, 08:49 AM
I agree, in general, with the previous poster, however, I don't out and out hate Java. Java and Python were my primary languages for about 10 years. Now I only do Python and some C.

All languages have issues bar none. Java is not an interpreted language however, it is compiled into a binary language that is cross platform complaint. This binary language runs in a virtual machine which is usually written in C for each platform Java runs on. Plus there is also a JIT (Just In Time) compiler which speeds it up tremendously. (There are JITs on the drawing table for Python now also.)

When I went to school in the 70s they were teaching languages that were about 30 years behind the real world. Now they are about 10 to 15 years behind, but are still behind.

Java does confine you to an OOP (Object Oriented Programming) style, but this is not all that bad. I develop almost everything in OOP. What I don't like about his is that they don't give you a choice. There are other issues in Java also like having raw data types which don't interface well with there Object types. C# has solved this issue as well as Python. You cannot do multiple inheritance in Java which is a very basic OOP concept. And no, interfaces are not the same thing as some Java enthusiasts would try to tell you.

The issues with Java are really advanced programming issues, so I'd never say Java was a bad choice, but in robotics you also need to know if there is a JVM (Java Virtual Machine) available for the micro controller of choice if you want to put a computer in your robot. Python is available for many small CPU boards. I really don't know about Java, but Java takes a lot more memory than Python will so I doubt it.

I tend to write a book every time I'm on here, sorry.

MikeG
06-23-2009, 08:53 AM
Let’s remember the subject of this post “Best language robotic language”. I feel the answer was presented in the very first response by Tyberius.

There really isn't one.

In my opinion, a new programmer should pick a language that they are familiar with or a language readily available. Those with absolutely no programming experience should pick up a well documented embedded system (Parallax has excellent educational docs). An embedded system provides practical robotics experience by tinkering with programming and electronics. It’s not the language but the amount of time dedicated to learning standard programming practices.

After few years the now experienced programmer can weigh in on this evangelical discussion.

ronaldbe
08-14-2009, 01:02 PM
OK, to set some people straight on the speed issue, this has been argued and argued over and over again. Python/Ruby are not slower than C because they are written in C. The general rule of thumb is that 1 line of Python is 10 lines of C and 1 line of C is 10 lines of Assembler. cnobile, hate to break it to you but Java is interpreted, hence the need for JVM. It is byte-compiled (just like Python, hence the .pyc files after you run it!!), which translates it into a more efficient form for the interpreter to um... interpret. If you don't believe me, check wikipedia then proceed to explain to me about how to get a standalone executable out of javac.

When deciding a language it's important to understand your final platform. A lot of people tend to use the Microsoft products since they already run Windows and are comfortable with their languages. That's great if you have the money to pay for the licensing of Windows Embedded and for Visual Studio ($1000+ if memory serves). Personally I run a Mac and Linux. I use C when I absolutely need speed and Python for rapid prototyping. LISP will be used when I start into AI. Since I've chosen standardized languages, I don't have to worry about switching platform. Since I'm 1000&#37; anti-Microsoft I'm biased and suggest anything other than Visual <Insert Language Name Here>.Net

Adrenalynn
08-14-2009, 01:05 PM
Interpreted = Slower. Compiled = Faster. If the _______ is compiled into machine code, it's faster than if a byte-code interpreter has to interpret it, even if it's compiled into byte-code. It's still a virtual machine executing the code.

Microsoft tools are free for personal use. If you're doing it commercially, you HAVE the thousandish dollars to spend. If you're not, you don't have to.

Welcome to the forum!

ronaldbe
08-14-2009, 02:02 PM
Thanks for the welcome and sorry if I seemed a bit snappy earlier, just woke up. At any rate, you said exactly what I said. Compiled code runs faster and since the Python interpreter is coded in C it has the ability to run just as quick. Without starting a heated discussion, you'd be surprised how fast a Python interpreter can be with a proper coded set of modules in C. Also, that's not entirely true about the purchase of Visual Studio. But at any rate I'm getting off topic again. Once again, my personal recommendation would be C and Python as it will run on any platform and should be able to meet just about any needs most hobbyists will have.

Adrenalynn
08-14-2009, 02:16 PM
If it's interpreted, it's not going to be as fast as native machine code. It's another layer that requires cycles. That's like saying "if I write a java interpreter in C it's going to be as fast as C".

No - Python does not run on "any platform", I'm afraid. That requires native code. Until someone shows me a python interpreter for my motorola phone, my blackberry phone, my Dynabyte, and my Vic20 - C is still more cross-platform...

Shevek
08-15-2009, 10:10 PM
Personally, I've been learning Scheme the past few weeks/months, and that's what I'm going to be using in my AI course this fall. I have to say, I love it. It's more fun to program in than any language I've previously worked with including C, C++, Java, and Python. I'm sure it has it's strengths and weaknesses, but for me, Scheme is just a lot of fun :)

cnobile
08-16-2009, 09:42 AM
Although I prefer Python to Java, Java is faster than Python at this time because Java has a standardized JIT (Just In Time) compiler. Python has Psyco, but the last I heard it only worked on 32bit processors. There is also a project called PyPy which aims to do much of the same thing. Since both Python and Java are eventually compiled to a platform independent byte code which is then put through a platform dependent interpreter which converts it to the machine language for the underlying processor, both will naturally be slower than C which itself is compiled to machine language. The layer issue as somebody else mentioned above. Yes executing both Java and Python will eventually be running machine code, but will run varying amounts of machine code for the same exact functionality. The one that executes more code to do the same thing will be slower, as of now Python is slower than Java. The question these days with fast and multi-core processors is not how fast a language is, but if it is fast enough to do what you need done. In the last 10 years of writing Python there has only been one time when Python was not fast enough, so I wrote that part in C and wrapped it in Python.

Now for robotics, nothing in this thread really makes any difference, just use the language that you feel most comfortable with and which has the support you need. As somebody else said if the language you want to use can access USB, serial, or anyother port you will need, then the language will work for robotics.

Lets not do any name calling here please, it only gets people pissed and doesn't contribuate anything to the discussion. I have over 35 years a software engineering experience that I can lend to this group if people want it. I've been in the business long enough to know that us engineers have the largest of all egos. Lets keep them in check okay?

lnxfergy
08-16-2009, 12:31 PM
The question these days with fast and multi-core processors is not how fast a language is, but if it is fast enough to do what you need done.

.... just use the language that you feel most comfortable with and which has the support you need.

Exactly!

-Fergs

Macro Man
09-23-2009, 12:01 PM
Well if this is for a foosball controller then it needs to be FAST at runtime. Fast sensors, fast actuators and to me that's crying out for low level C (maybe some assembler) optimised for the microcontroller hardware.

Adam
11-02-2009, 04:13 PM
An important point that I think was missed is that you need to consider the language together with the microcontroller and robotic hardware you plan to integrate with and whether or not your logic will be completely onboard or slave to a PC. In the latter scenario you may end up with two completely different development platforms - one on the robot and one on the PC.

Depending on what you're doing, you'll probably want to use libraries written by other people to integrate with your hardware. Do you know what hardware you want to use? Has someone already written the low-level code that you can re-use? If so, what platform did they use? Are you willing use a particular platform even if it means you have to reinvent the wheel? Given that you've satisfied all the above, will the platform be powerful enough to meet the lofty goals that you will inevitably set?

If you want an interesting bot that actually works vs a pile of parts and a frustrated programmer (aka YOU), then you need to think about these things. There are a lot of choices, but I would put all the hardware and software pieces together from a high-level design perspective before committing to a platform.

lnxfergy
11-02-2009, 04:44 PM
... you may end up with two completely different development platforms - one on the robot and one on the PC.

I think this almost a given. Choice of high-level language on the micro is going to be limited almost exclusively to either C or BASIC. Depending on application, many applications automatically rule out BASIC-based "microcontrollers".

Most people I know, would rather learn a second, easier to use language, for their PC-based development, than use C on the PC all the time (it also majorly lacks cross-platform portability). (and if we want to talk about BASIC, what you find on your PC most likely won't even resemble what you found on your micro, so it's like learning second language).

-Fergs

Chench
11-14-2009, 08:31 AM
Hi, I see form this thread that there are a lot of people with serious programming experience. I'm just a beginner in robotics. I started with a Picaxe microcontroller, which is very easy to program yet is also limiting. I would like to learn a language which I could use on my Windows Mobile 6.5 phone. It has more sensors built in then any of the robots I've built so far, along with internet connectivity and so on, so I'd like to integrate it into a robot where it would make up the sensors and 'brain', something like Wimo (http://www.wimobot.com/). It would communicate movement commands via bluetooth to a microcontroller with Bluesmirf module.
So far I've considered C++, which I think is the native language of the device and so is probably very capable, and Python. Is C++ overkill for accessing the sensor data, making decisions and outputting serial commands over bluetooth? And is Python capable of doing this.
Thanks
Sam

Adrenalynn
11-14-2009, 12:49 PM
Hi there, welcome to the forum!

When you say it has "more sensors" - really? Which ones? It has an IR range finder, an Ultrasonic range finder, a laser range finder, pressure sensors, analog inputs, ...?

You didn't mention which Windows Mobile it was, but I haven't seen one with all that - I'd love to know so I could run out and grab one!

Chench
11-15-2009, 12:34 PM
Hi, thanks.
Its a Samsung Omnia II. Some features which seem to be obviously useful are
- a three axes accelerometer
- GPS
- a compass
- a light level sensor
However there is also
- a 'proximity sensor' - presumably IR
- two cameras
- a touchscreen, possibly useful for bump sensors
I've also seen an application which allowed some kind of sonic ranging using the built in speaker and microphone.
I suppose other sensors could be linked to the microcontroller and readings reported back to the phone over Bluetooth.
Sam