View Full Version : [Question(s)] Am i limiting myself with C/C++? Python?

08-03-2016, 12:45 PM
Hi all. Long time no see. It's probably been a couple years since I last posted and was active with my hexapod robot. I've been busy with life and Robotics Engineering grad school.

I'm getting the itch to get my hexapod back up and running. It's current state is MKII hardware, Raspberry Pi 2 brain, and all my own kinematics/TG/gait/navigation code.

I got a RPi3 (integrated Bluetooth for controller and wifi will be very nice) and am looking to potentially update/improve the foundation of my code and to add more autonomy, navigation, and machine vision to it. I'd like for it to be ably to wonder around aimlessly, maybe create maps, chase red balls, something like that.

I've been pretty set on using C/C++ all this time, but Python seems to be screaming at me from all angles. From joystick drivers to OpenCV tutorials, its everywhere. I used to think it wasn't "lean" enough for doing real math, but I'm not so sure that's true.

Do you guys think I'm limiting myself by sticking to C/C++? Should I embrace a new life with Python? What are the cons to Python these days?

08-03-2016, 01:22 PM
I debated some of the same questions with myself earlier.

For me, it is hard to train an old dog new tricks :D but I do try to be at least able to read and potentially modify Python programs (ROS modules), as there are a few of them.

But I also find myself wanting to rewrite any of them I use in C/C++. As at least some of the modules I have seen running on Raspberry Pi or Odroids, like ones that simply read the IMU and generate a topic, or that maybe translate Joystick messages, they were eating up a lot more CPU than I think they should...

08-03-2016, 07:18 PM
Yeh, but you know what. Life is short, why not learn a new language?! (lol at the dorkiness)

I'm going to use OpenCV and its tutorials are 90% python, i like what i see as far as matrix math using numpy. I'm going to go for it and port all the code to python and see what happens.

08-04-2016, 07:18 PM
Python is a cool language with witch you can do a lot of stuff very quickly, and if used properly it can be acceptable in terms of perfs.
It's also a language with a lot of pitfalls when you want to go beyond the simple code structures, but as they say "we're between consenting adults".
These days Pyton and C are the pillars of what I do in any embedded setting, mixing the very efficient and controlled execution of C with the ease of dev of Python for higher level stuff.
So if you learn how to interface the two, the world is yours!

I would recommend writing stuff quickly first (in python) then only rewiriting very specific perf-critical parts in C/C++. A little bit like people used to do with c and assembly back in the days.
If you actually measure where the perf bottleneck are and only optimize those you can get the best of both worlds.

08-05-2016, 12:12 PM
Interesting, that makes sense, thanks. Off I go!

08-16-2016, 09:58 PM
Hey Dan - I'm learning Python and have been using your code as a reference. I sent you a PM - I'd really appreciate some help understanding a few key concepts in the code base. Thanks for making all your work public!