C stdout to OpenMV ide serial port?

Discussion related to "under the hood" OpenMV topics.
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

C stdout to OpenMV ide serial port?

Postby airborne » Sat Jul 01, 2017 12:34 pm

Sorry to disturb you again.
Is there a way to send C stdout to the screen? I'm trying to debug some of the code I've written on the c side and the only way I currently know of accessing intermediate variables is through defining them in on the python side then outputting them there, which takes a while.

Thanks!
User avatar
kwagyeman
Posts: 3142
Joined: Sun May 24, 2015 2:10 pm

Re: C stdout to OpenMV ide serial port?

Postby kwagyeman » Sat Jul 01, 2017 2:52 pm

#include "stdio.h"

Then put printf anywhere in your code. This get printed out the same serial port regular messages go - as in they will show up in the IDE.

Also, make sure to add \n to the end of the string.
Nyamekye,
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Sat Jul 01, 2017 8:08 pm

Dumb mistake,, I didn't have "stdio.h" in my code yet.
Still though it's not printing out to the screen. My IDE is just the generic one installed from the .run, would that affect this?
User avatar
kwagyeman
Posts: 3142
Joined: Sun May 24, 2015 2:10 pm

Re: C stdout to OpenMV ide serial port?

Postby kwagyeman » Sat Jul 01, 2017 8:54 pm

That one should work. The print statements go to the serial terminal in the IDE.
Nyamekye,
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Sat Jul 01, 2017 9:25 pm

I was looking in the terminal but must not have been actually executing the part of the code with the print in it. I was trying to call it in apriltag.c in a place I thought got executed.
As a test I switched back to master branch, added #include "stdio.h" and printf("in fast_roundf\n"); to fmath.c, line 57 (in the fast_roundf function). Recompiled, re-flashed the firmware to my OpenMV M7, and it would print out to the serial terminal so much it actually would slow down the IDE to the point it wouldn't really work.
So back to find out why that part of the code isn't executing (which also explains the bug I'm trying to fix!)
Thanks!
User avatar
kwagyeman
Posts: 3142
Joined: Sun May 24, 2015 2:10 pm

Re: C stdout to OpenMV ide serial port?

Postby kwagyeman » Sun Jul 02, 2017 12:41 pm

Yeah, don't put print statements in loops :).
Nyamekye,
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Wed Jul 05, 2017 8:58 am

OK this took me way longer than it should have and I still don't quite understand, but I can now print from apriltag.c.
I was correct initially about the printf statements I added being executed in apriltag.c, but no printing was happening.
The problem was about line 220 in apriltag.c: #define printf(format,...)
Removing that #define statement I tried on day 1, but it caused a bunch of errors with implicit conversions which I wasn't able to fix elegantly.
I eventually "fixed" it by commenting out any of the printf's where problems occured (the two main ones being in printing matd's).
User avatar
kwagyeman
Posts: 3142
Joined: Sun May 24, 2015 2:10 pm

Re: C stdout to OpenMV ide serial port?

Postby kwagyeman » Wed Jul 05, 2017 11:31 am

That's some lovely code right? Only took a week to port to the OpenMV Cam.
Nyamekye,
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Wed Jul 05, 2017 3:24 pm

It was the first OpenMV cam code I looked at - terrified me, and to some extent still does.
I give up for now. No matter what I seem to do, I can't use apriltag.c to print values from my matrix (I'm trying to implement a pseudo-inverse). It always gives me that same double conversion error (which should really just be a warning).
Anyways I've tried typecasting, I've tried just declaring a float or double variable and even things as easy as passing:
float dummy = 10.0;
printf("%f", dummy);

or
double dummy = 10.0;
printf("%f", dummy);

Still gives me that error. It's baffled me. I can only assume something in one of the #include statements is messing with printf. For now I'll just multiply my values by 10000 and use them as "int"s
User avatar
iabdalkader
Posts: 885
Joined: Sun May 24, 2015 3:53 pm

Re: C stdout to OpenMV ide serial port?

Postby iabdalkader » Wed Jul 05, 2017 4:09 pm

airborne wrote:
Wed Jul 05, 2017 3:24 pm
inverse). It always gives me that same double conversion error (which should really just be a warning).
Hi, the float gets converted to double implicitly when calling printf, you just need to convert to double explicitly (Cast):

Code: Select all

printf("%f", (double) dummy);
User avatar
iabdalkader
Posts: 885
Joined: Sun May 24, 2015 3:53 pm

Re: C stdout to OpenMV ide serial port?

Postby iabdalkader » Wed Jul 05, 2017 4:22 pm

Okay I see the problem:

Code: Select all

#define double float
Don't comment that.
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Wed Jul 05, 2017 11:02 pm

Thanks iabdalkader, I should have seen that. That gave a large number of errors for conversion types. Fixed those by typecasting to doubles.
It's now giving 520 errors about undefined references to "__aeabi_dadd", "__aeabi_dsub", etc. From online help, looks like we're not using the libgcc.a file, which I guess should be a part of the gcc-arm-none-eabi package?
I think we've pushed this one about as far as it needs to go, this isn't a high priority. Still, if you care to look at those errors, I pushed my changes to a branch on my git fork: https://github.com/jkairborne/openmv/tr ... riltag_fix

Best
airborne
Posts: 18
Joined: Mon Jun 12, 2017 8:54 pm

Re: C stdout to OpenMV ide serial port?

Postby airborne » Wed Jul 05, 2017 11:06 pm

Sorry, the
#define double float

line was never commented out in my code. I commented out the
#define printf(format, ...)
line but that was it. In my post from a few minutes ago I commented out the printf and the "double float' defines.
Anyways like I said, this should be very low on the priority list. By multiplying out to an integer I'm able to print out the values from my matrix I need.
User avatar
iabdalkader
Posts: 885
Joined: Sun May 24, 2015 3:53 pm

Re: C stdout to OpenMV ide serial port?

Postby iabdalkader » Thu Jul 06, 2017 7:48 am

airborne wrote:
Wed Jul 05, 2017 11:06 pm
Sorry, the
#define double float

line was never commented out in my code. I commented out the
#define printf(format, ...)
line but that was it. In my post from a few minutes ago I commented out the printf and the "double float' defines.
Yes I understand. I meant this line is the main problem:

Code: Select all

#define double float
This replaces every double with float, so even if you cast to double printf expands to:

Code: Select all

printf("%f", (float) dummy);
That's why you still get errors. There's no easy fix for now.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests