Should I use C++ classes with Teensy 3.6 for a motor controller.

Status
Not open for further replies.

irakandji

Member
I am back to building my robot with Teensy 3.6 as the core.

I will have a minimum of 4 motor controllers. Pololu VNH5019

From a software point of view it makes sense to me to write a class for this controller/motor and just create an instance for each motor.

I keep reading in various sources not to use classes in the Arduino IDE, but I an not knowledgeable enough to decide what course of action to take. I would prefer not to have to rework because of a wrong decision early on.

Advice would be appreciated or any pointers to a good source to educate myself on the why's and wherefores of C++ classes on Teensy.

Thanks in advance
 
I'm not sure why you wouldn't use classes. I use them all the time and it works the same as C++ classes elsewhere. Most, if not all, of the Arduino libraries are C++ classes.
 
I know others may have different takes on this, but...

There is no reason not to use classes with Arduino... In fact it is used in lots of places in the core code. Things like Stream class, Print, HardwareSerial, Wire...

What many people avoid with Arduino is using lots of dynamic object creation and destruction in the code. That is there are some people who avoid new and malloc in their code at all cost.

I personally am more in the center where I think it is fine to use malloc or new as part of my initialization code, but that is about it.

However I do try to avoid things like Multiple Inheritance, Dynamic Casting, ... As these can really bloat the code quickly.

By the way there may already be one or more Arduino classes setup for this controller already, like: https://github.com/pololu/dual-vnh5019-motor-shield
 
Thank you. I agree but keep seeing folks in other forums saying use "c" only. I could not follow thier reasoning and thought I was missing something.
 
Thank you KurtE, lol I am using the single motor version of the vnh5019 and the pololu site doesn't point to that git for the single motor board.

You just saved me a tonne of work.:eek:
 
Status
Not open for further replies.
Back
Top