Programming Language

I've written most of the mechanical aspects of my robot in C++ (native to Arduino DUE) and am moving on to the brains, which is a Raspberry Pi 2.

I'd like to write this in a higher level language than C or C++. I am annoyed at the hoops I have to jump through to deal with strings and for that matter arrays.

I see two main choices, Python, and there is a Python 2.7 and a Python 3.4, and Node.js. What I have at the moment is OpenCV with Python 3 bindings, pocketsphinx, and eSpeak.

My thoughts of the moment is to run OpenCV on Python 3 since that is set up.

For the speaking / listening end, I am unsure. I like that Node.js can run asynchronous, I also have a fair knowledge of javascript. I haven't worked with Python, but it looks like it is not hard.

Much depends on what already works, and of that I have little knowledge. 

Who can shed some light here?

I have some real doubts about running both on the same PI, although neither has to run continuously. Putting the audio on something like a BeagleBone Black might make sense. And that brings up ROS (Robot Operating System), that is not hard to run a Pi2, but frankly I don't understand it. What docs I have seen on it leave me more confused. Who has a good pointer on just how ROS works? Or a brief explanation...

On another note, I'm taking my quadruped cat out to be painted today. I have a friend that makes a living painting aliens and robots, so LMR might get to see this ridiculous project I have been working on. I think it is a bit of a stretch here though...


 

For the Due, do you program
For the Due, do you program it using the Arduino IDE in their language? That is not exactly c++, but it is close.

C++ has a lot of different ways to do strings. I like the low-level ways of string handling that c has if you use the proper functions to handle the strings. There should be even less problems with the c++ string objects.

Python can be nice if you’re used to it. If not, it can be a PITA. There may be a multithreaded version, but I don’t know.

If you’re only taking about the asynchronous io functions, I believe Python and c/c++ has these also. They can be easily created.

I would do the brain in C++ or in Java. However there is a lot of work in c++ because you can get a lot of work done quickly.

In the end it comes down to what you’re used to.

DT

Due and languages

I’m using the Arduino IDE, I find it fairly seamless getting the DUE programmed. I’m aware that it’s not quite C++.I haven’t tried the DUE with a different IDE such as the Eclipse.

My experience is with interpretted languages. I can pretty much do what I want with perl,php and javascript, and anything else web related. I’ve been at  it for  a while, in fact, I want to move on.

I’m new to C++, native string handling on the Arduino is miserable of what I’ve seen. When you do web stuff there is a lot of string handling, arrays too. I’ve figured out the Arduino C++ well enough to write fair enough looking classes and efficient enough code to process the necessary data. There is a bunch of math that I didn’t even know existed a few months ago, like barycentric coordinates and quaternion space. Still, in C++, much stilll lies undiscovered, unfigured out.

I am at this point more interested in the language than the visual. I see  that as searching arrays and string handling. I hadn’t considered java but looking at this:

http://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html

I can work with that.

How does real C++ compare?

Python is supposed to be the go to language on the Pi, but in looking into Pi java performance, I see that Java runs well on the Pi, in fact much much faster than Python, at least on Pi 1, Pi 2 benchmarks I haven’t found yet, but I suspect shows the same spread.

Since, I haven’t written a line of code in either Java or Python… I think I would prefer Java.

I know that whenever you pick up a new language that there is a couple of weeks where you aren’t productive, and a few months before you are at ease. I don’t mind picking up something new if it will make life easier or more entertaining later. Although, I do want to get this robot done.

Various

I hadn’t seen the CCSR, and I thought I had looked at everything. I like it.

Not quite the direction I want, but I like it, it is good work.

I’m thinking of a robot that asks questions rather than just answers them. Social and perhaps a little naive. Something fun.

I’ve seen the sample code in Python and it is a powerfull push in that direction, it’s not so easy if you have to start with nothing!

First, string handling on
First, string handling on any microcontroller with small memory spaces, such as the Arduino, is going to be bad. The Due has a lot more memory and is a much more useful machine. Object oriented programming was made for processors with a lot of memory, because a lot of memory is allocated and deallocated “behind the curtain”. This is especially true in Java, because without visible pointers the system has to handle all that.

My favorite language is Java. I’m getting into C++ because I’m working with projects that are written in C++ such as OpenCog and OpenCV. Unfortunately I haven’t programmed a byte for almost a year now because I was first in the middle of a divorce, and then my wife died, which caused a lot more paperwork. So I’m in the middle of packing up my stuff so I can get rid of the stuff and the house and move to an RV. If anybody wants to live in State College, PA, US, I would be glad to sell this house, including a couple tons of books, plus furniture, plus optionally one parrot for a very reasonable price. :slight_smile:

If you know what you’re doing, C++ can be very efficient, and so can Java. I would look at what other software you use, and see what SDKs they have. If something you need to use requires code written in Python, you might want to write everything in Python. And python really isn’t that bad.

The Pi is, despite what people thing, a fairly plain Linux box. It can be programmed in whatever you want to program it in. I’ve written small programs in C++, C, and Python. I even tried Java on it, and it wasn’t bad. So program in it in whatever languages you like. The only thing you need to be careful of is what libraries are needed to support the pins and the serial ports and such.

Good luck!

OpenCog

Sell the house, go build a robot and have fun exploring.

I’m struck by OpenCog which I hadn’t heard of. In particular the section on hypergraphs. I’ve been looking at AI as something similar to that. I’ll look some more, I like it. 

As far as the DUE, I’m satisfied with the memory and speed. It’s cheaper, faster and larger than a Mega. Funny thing is that I now have all these extra I/O’s and PWMs and I’m running most everything off the i2c bus! Arduinos are great for such stuff, I had looked at the i2c bus on the Pi and it did not seem to be as developed. I see your point on this.

What the Pi 2 is great at, aside from being small and cheap, is that it has this huge community behind it that has gotten all this difficult software to compile to actually run. It seems to be just fast enough to run OpenCV and , rather or, a Kinect. I’m convinced that  for indoor navigation a Kinect is the way to go (if you can lug it around), worth throwing a dedicated Pi2 on it.


>I am annoyed at the hoops I

>I am annoyed at the hoops I have to jump through to deal with strings and for that matter arrays.

Can I ask what you think is difficult with strings with c and c++?
What about arrays?

I love Python.

I love Python.

I built a similar project a while back (OpenCV face recognition, and speech recognition/conversational skills) and used Python for this, I found having the audio and video sections of the project running on different processes worked very well, and using pipes for communicating between the two. This was running on a raspberry pi 2 and had no problems whatsoever with speed (it was also running a nice GUI!)

 

If you find you have to do any large calculations (which you might want to do for data normalisation) then you can always output the heavy lifting to C++ using a Python packaged called c-types.

Good luck with the project! 

Python

  This is the direction I have decided on and am writing my first bits of Python to connect audio (pyttsx) with a MySQL database. The pi2 seems to be a lot faster than the first pi, so far…

I’m not really at home with IDLE yet, can you suggest a different IDE? I usually just write in a text editor, but for a language I don’t know yet, a helpfull IDE seems like the right direction.

 

Geany

I used Geany (I think it’s already installed on Raspbian) and it was pretty good!

Color codes everything nicely, can stop/step over code, really helpful


IDLE struggled with running programs with multiple processes, I don’t really like IDLE either…
 
 

Well, that was easy.

Less than 2 minutes later I have Geany up and running with a blank template.

I’m in Atlanta and it’s too early (not yet 5AM) to do anything more!

Thanks.

No problem, enjoy your new

No problem, enjoy your new IDE!

I’m a programmer too

I am a C# developer and learning Python was not hard at all.

I think that when you got a programmer thinking, switching language is trivial. Also, if you buy components, all sample are in Python so there’s a nice bonus there.

My own project use Python on the Raspberry PI and I’m quite happy with the result.

It’s not autonomous yet but I still have a couple of file of code. 

I’m thinking about uploading my code to github so you might what to “collect” my project to check it out when it’s released.

Python is ze best

As someone that writes robot software for a living, knowing both Python and C++ is the way to go. Mainly because the major robotics software tools you’ll find are written in either (or both) of these. For example ROS uses both. I do everything I can in Python because it is faster to develop with, and use C++ for things that are computationally intensive and need to run fast.

Node.js is good for making webpages from what I understand, but I haven’t came across many people using it for robots.

To learn ROS, start with the tutorials. At least do the beginners tutorials. If you run into any questions you have, ROS has an awesome community sitting and waiting to help you out. You can ask questions here

Productivity

I see what you are saying and it seems right to me, I’ve written some python by now and have some understanding. 

I’m keeping all the intensive math in C++. I’m hacking my way through espeak and pocket sphinx and I know I would not wish to do that in C++!!! A lot less to worry about with python.

Thanks.

Cyber just an FYI that might

Cyber just an FYI that might save you a load of time.

If this project is for non-commercial use and will have access to an internet connection, may I suggest using the following python package: https://pypi.python.org/pypi/SpeechRecognition/

It uses the google speech recognition engine which is (arguably) the best recognition engine around, and beats the hell out of sphinx. its also a lot less of a ball ache to set up.

It has changed a little since I last used it, but I can only imagine its gotten better, it used PyAudio to capture the sound.

Also if you want your project to sound a little better than epseak when performing TTS I would suggest the amazon inova voices. There is again a nice API for uploading text and downloading an mp3/ogg file for you to play back.

The way I had this working was to download several of these mp3 files for standard responses (i.e “Okay”, “Yes/No”, “Hello” etc) and then for speech you want generated on the fly just keep one “in use” mp3 file, and keep overwriting it with new content wheever you pull down an mp3 from the API.

 

Hope this all makes sense and I look forward to seeing your project in action!

Options

I could not find the amazon inova, I’d like to try it. eSpeak is pretty strange sounding and I am just working my way through Mbrola:

http://espeak.sourceforge.net/mbrola.html

Along the same lines, pyttsx.

I’m not adverse to offloading both speech and speech recognition to Google but I know that a WiFi connection to the web won’t always be there. I do have a WiFi module on the way:

http://www.ebay.com/itm/301723479605

I’ve just gotten the catbot reassembled after the paint job and am still adjusting. I got a few simple moves programmed in (just in time) and took him to the first Halloween Party (and arguably the best) of the season. Much work to be done. For a while it was broken and I kept adding Serial.print to trace to no avail, then I discovered that the problem was that all the Serial.println’s were eating up all the clock cycles! A new learning experience every day.

Thanks for your suggestions!

Sorry typo, its called

Sorry typo, its called Ivona, heres a link:

http://developer.ivona.com/en/speechcloud/introduction.html

 

There are certain paid for versions I think, howver if you look there should be a free version for use (I think it had a limited number of sync requests, however if its just one robot that will be fine)

I find the UK voice - Brian to be my personal favorite, sounds very JARVIS style.

ivona

I’ve been looking at this and it seems like the way to go.

I am apparently out of the loop and hadn’t heard Jarvis, so I Googled it. I like it.

I’ve looked a bit at words and sentences, Toki Pona, is a language that has just 120 words. For regular English, subsets of some 800 or so words covers a lot of ground. People use the same handful of sentences over and over… So the language for a cat bot does not need to be extensive.

It seems to me that a database of what Amazon sends back could be made. Store the words or sentence in one field and a path to the mp3 file in another, and any ssml in a third. After a while, you can just use the local “proxy”. Unless I am missing something, this seems pretty simple. That database could be accessed later in Python.

Looks like I’ll have to learn some Java, a language I’ve never used. I looked at the example code and found that I had no trouble understanding it, how about that?

Cheers,

Jeff

 

 

Use “proper” C++, not C

I’m a professional C++ developer, so please allow me to say that if handling strings and arrays in C++ is hard, you’re doing it wrong. 

The Arduino is a very limited platform with no memory management at all, so you can’t use the C++ Standard Library at all. You can use some C++ language features (classes, constructors, references etc) that make life a little bit easier, but you are stuck with “char*” as strings and bare C-style arrays. 

On the Raspberry Pi you can use a proper compiler (I’d recommend Clang in the newest version) and you can thus use all the tools C++ gives you. No more char* but std::string, no more C-style int[]'s but std::vector<int> etc. No malloc, no free, no new and no delete. If you use these, you’re doing it wrong, too :-) 

Look at isocpp.org for links to some Modern C++ tutorials. Also make yourself familiar with the boost libraries

You get the best of both worlds. Simple things are simple again (like they certainly aren’t in C-style C++) and advanced things are possible. Complex data structures, the error-checking capabilities that a real compiler gives you, efficient algorithms in the C++ libraries etc. 

Regards
Sebastian