short wrote:Whoah you wrote the rover in QT? Haha I figured at most it had a C compiler. That's awesome.
Haha, naaaah. It wasn't quite that hardcore. It was pretty much a weak-ass PC. It even ran Ubuntu as its OS... hardly embedded. Definitely limited resources, but I did use QT for the software framework running on it.
short wrote:Makes complete sense, well almost. The following:
Fortunately, there's a pretty easy ass solution. Just make sure it's not INSTANTIATED until after your QApp/QCoreApp:
Code: Select all
class StaticClass {
private:
static QString *str1;
static QString *str2;
public:
static void StaticConstructor();
};
Then initialize the static QObject POINTERS as such:
Code: Select all
QString *StaticClass::str1 = NULL;
QString *StaticClass::str2 = NULL;
And define yourself a simple little static constructor as:
Code: Select all
void StaticClass::StaticConstructor() {
str1 = new QString("Text1");
str2 = new QString("Text2");
}
Now simply call your static constructor from main or your main window constructor AFTER QApp/QCoreApp has been initialized and before you actually use the static QObjects.
If in my main function I call my newly created static constructor, I can access each string elsewhere in my code via:
Code: Select all
other code...
qDebug() << StaticClass::str1 << endl
Yep, 'cept you have to dereference the pointer:
Code: Select all
qDebug() << *StaticClass::str1 << endl;
short wrote:That makes sense, and I would assume (no time to confirm) that this way would be faster then the inline function call that happens every time with my method. Thanks! I learned something cool today, c++ static classes are shaky for me.
Yeah. Since you weren't returning by reference or pointer, it was a copy construct to return by value on the stack like that.
short wrote:I do have a question though,
Then initialize the static QObject POINTERS as such:
Code: Select all
QString *StaticClass::str1 = NULL;
QString *StaticClass::str2 = NULL;
What is this statements purpose? I'm almost certain that I would do this before the static constructor call in my main (after the QApplication is initialized, of course) but I am unsure why it is needed. str1 and str2 are declared in the class definition, instantiated with the constructor, is it necessary to set them to NULL explicitly?
Nah, this would actually go in your .cpp file corresponding to the static class, or anywhere else at GLOBAL scope. This is just the way static member variables work. Since they're not associated with any particular class, they're internally allocated as global memory. By doing this in your class:
Code: Select all
class StaticClass {
static QString *ptr;
};
You have simply
declared the variable. There is no memory reserved for it. It's essentially the same thing as declaring an extern global variable or using a forward declaration, since the compiler cannot reserve room for a static in the header file (it would be reallocated in every file including it, and your linker would give you a duplicate symbol error).
So along with "declaring" it in your header file, somewhere in your program, at global scope, you must actually allocate/initialize it. This is a simple allocation:
Which works (internally) the exact same way as declaring a global:
C/++ also allows for the initialization of globals upon construction, so we might as well initialize it to NULL like good little programmers:
short wrote:On another note how does being done with senior design make you feel? I get to show mine off this Friday at our engineering expo, and I feel come Friday a HUGE weight will be off my shoulders. I saw on Facebook awhile back you were working your ass to have yours done on time. I bet your glad its over, I'm curious if you enjoyed yours. I personally have HATED mine. My group-mates didn't do jack shit all year, it kinda brought my motivation down being I was the only one writing code. Literally one of my group members wrote 0 lines of code all year. I'm still debating whether or not to try and fail them. I really liked learning Qt though, I am definitely going to keep using it.
It feels soooooo fucking good to be done with that shit. I'm in the same boat as you were. I was super stoked to start the project, because we were using the Elysian Shadows Toolkit/Engine for a bunch of things (you'll see it in the dev video), and I had never done anything robotics-related in my life.
I was (just like you) the only person really doing any coding in the team. I had to rely on one team-mate who committed to handling the image-processing algorithms in OpenCV. And it turns out that he wound up fucking all of us over by failing to mention that he never bothered to test his code on the rover before a huge competition (because he knew it wouldn't work).
Our project was pretty impressive (if I do say so myself), and we were one of my teacher's favorites. I tried to push us to enter competitions and expos (that we won) for more publicity... while my uncertain team-mates who were not confident enough in their own abilities or experienced enough to keep up really kind of brought it down. In the end, I got to present my software suite with a rover fully ready to be autonomous... except for wait.... the cameras can't fucking detect a single obstacle or are continually false positive... so autonomy was a complete failure...
I took way too many classes... even a graduate class as an elective. I had to spend so much fucking time on just senior design that my other classes suffered, and the fact that my team-mates were clearly not able to keep up really started to bring me down. The pressure mounted so high that I nearly became depressed by the project at the end of the semester... I will never fucking do that to myself again. In the end, I secured an A+, had something really impressive for my resume, and got both me and Kendall (even though she wasn't in my team, haha) interviews with some pretty nice companies... So I guess it all paid off.
But yeah, that's my emo story of the semester and why you haven't seen AiGD18. I'm definitely going to be showing off the Rover in it, though, since it directly ties into ES, and I spent so much time on it...