![]() |
Printf has just entirely failed to do anything
I started with the default camera code from Kevin Watson a few weeks ago, and I have been making my modifications happily--that is, until yesterday. First, I added two of my own files, which did all the camera calls, consolidating them into a single Camera Update function. Then, I pulled the camera update function calls out of user_routines.c and put my camera update function call into Process local IO. I had something like this working last week, but it refuses to send any bytes out the serial port now.
Things I have tried: -tested my serial link. It is good-I can send programs down + read them back with device reader. I also see IFI> when I reset the bot -tested with another RC. Same problem. -unplugged camera TTL converter. Same problem -Added printfs everywhere in my code. None of them work unless I comment out the #include for serial_ports.h (this breaks the camera functionality of course) And none of the printfs produce any output -Replaced all the files that should never have been modified (serial_ports.c/.h, terminal.c/.h, camera.c/.h are the ones I overwrote with the ones out of Kevin's code). No effect. I'm bashing my head on the wall right now.....please help! JBot PS. I will post the code tonight if you need it. I am using a school machine right now and don't have access to my code right now. |
Re: Printf has just entirely failed to do anything
Which printf are you using?
The C18 library version that requires you to add "#include <stdio.h>" everywhere printf is called, or one of the older printf_lib.c/h versions? |
Re: Printf has just entirely failed to do anything
I am using the stdio.h version where it won't compile unless I #include <stdio.h>.
It "Code error"ed out when I commented out the includes for Kevin Watson's serial port code. It worked then for about 5 seconds but it gave me a red light of death afterwards, presumably because I was bombarding it with tons of printfs. JBot |
Re: Printf has just entirely failed to do anything
I really hate to do this, but since it is slowly creeping down the portal and I really need an answer...BUMP!
I am thinking about re-writing from scratch, but that would be ugly, so please, please tell me what I might be doing wrong...:mad: JBot |
Re: Printf has just entirely failed to do anything
Sorry, we've been racing robots all night. They're having a pushing contest now.
Probably need to attach or email your whole project to look at. It's hard to guess what serial port resource conflict you might have. There are too many answers. |
Re: Printf has just entirely failed to do anything
Quote:
If you are indeed the lone programmer for your team (poor guy :yikes: ) you might want to force some code versioning on yourself. Things like CVS or SVN (check out wikipedia or google it yourself) CAN AND WILL SAVE YOUR BACON! It'll allow you to easily step back in time before you screwed something up, and will also provide an easier time of multiple people working on the project at once. This way you can try training an interested freshman without fear of him making changes you can't get rid of when your team leader asks you "is autonomous mode done yet?" :ahh: It takes some work to understand, but I promise (and every other user of some code versioning system will promise) it will be worth the effort. --Eric |
Re: Printf has just entirely failed to do anything
I had the same sort of occurrence myself this week as I was trying to program one of the 2005 units.
Since you haven't mentioned which controller you're using this may not work. If you have a 2005 CPU it's likely using a 8520 pic, which needs the following environment changes in mplab: From the Configure >> Select Device... menu choose "PIC18F8520" as the pic type In your project use the "FRC_library.lib" for the 8520 (mine is named FRC_library_8520.lib) -To keep my sanity I renamed it in the same fashion as last years revised libraries and linkers were. Also In your project use the "18F8520.lkr" for the 8520 NOW the last ingredient for success in restoring printf's (in my case anyway) Load the FRC_MASTER_V12.BIN and reload your first compiled code (before all of your changes) If you're using a pre 2006 CPU it's probably not been loaded with a FRC_MASTER_V12.BIN but an older version. I'm just guessing (since it's now gone) but ours was probably using the V11 master code as distributed in April 2005. Once the master code was updated my printf's worked fine (no more IFI> terminal freeze ups) |
Re: Printf has just entirely failed to do anything
OK, the code that is causing me problems is posted:
http://jbotalan.frih.net/07_code.zip No printfs work anywhere. I'm re-writing from the default user code. It will make for cleaner code. I would be interested in finding out why the heck this broke. I'm going to try CVS. JBot |
Re: Printf has just entirely failed to do anything
Quote:
Does anyone know if the 2005 and 2006 controllers share a master processor model? Also did you actually do the Master version update on your 2005 controller? It's a little hard to understand as you speculate the controller in question was running v11. Can someone clarify please? |
Re: Printf has just entirely failed to do anything
Quote:
Oh, I like being the lone programmer! Nobody to fight with over how the code will work! I'm trying to train a freshman, but otherwise I'm it. Thanks again. You learn something new every day. If only I learned something this cool every day... JBot |
Re: Printf has just entirely failed to do anything
Quote:
Code:
PIE1bits.TMR1IE = 0;If i understand your original post correctly, it stopped working when you moved the function calls into your abstraction files? I noticed you did not call "Initialize_Camera()" in your abstraction file (or anywhere in your project). Try adding that to user_routines.c in the User_Initialization() function. Let me know if any of these work. -Eric |
Re: Printf has just entirely failed to do anything
I'll be sure to let you know if these work. I won't be able to check until we get back (on the 4th I think). It's nice to know someone cares enough to pull down someone else's code to look at it. I wouldn't have been as generous before FIRST...
Thanks, JBot EDIT: I was under the impression that Camera_Handler() in camera.c was supposed to be calling Initialize_Camera(), and it is as far as I know. I can call it manually, but depending on the flags set in camera.c, it does get called if camera comms aren't working. Correct me if I'm wrong... |
Re: Printf has just entirely failed to do anything
Matt,
Sorry for leaving you confused. The last step for success (in my eliminating the IFI> prompt freeze up while adding in printf's for my chosen variables) WAS the loading of the MASTER_V12.BIN from the 2006 default code. You are absolutely correct when you mention that there is no explicit documentation of whether it's appropriate to try this. But where is your sense of adventure. The fact that IFI was doing FRC controller processor upgrades from ver 8520PICS to 8722PICS, and Kevin Watson was releasing all kinds of code with instructions on how to load user programs written as enhancements for the 2006 base code onto 2005 processors. Surely, if it were fatal to the processor somebody would have noticed by now that loading the MASTER_V12.BIN shouldnt be done on a 2005 controller. Anyway it works, my 2005 controller is happily running MASTER_V12.BIN and both the FRC Default code and OUR 1114-1503-1680 Common base code that were teaching our programmers with. Perhaps I should have actually read the IFI site for instructions on how to confirm which Master code we were running before I scrapped it, but I did save the bin file for posterity using device reader. The only guessing going on was if it was v 10 or v11 not whether or not I fixed the freeze up at the IFI> stage. Bruce PS Jacob, I looked at your environment (8722PIC, lib & lkr) and you don't have the same printf freeze issue I had. |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
JBot |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
Thanks for the information, I've tucked it in with my 'useful things' section of the brain. |
Re: Printf has just entirely failed to do anything
Quote:
Aside from your efforts to start from the default code, I can send you a basic environment that has a working camera without too much of our robot-specific code in it just so you can verify its not the source you're building from. Another possibility-what version of the IFI loader are you using? If you use the old version with code sizes> 32k (or whatever the max was for 2005's RC), you can get wicked crazy problems. That might explain why things stopped working as you added more functions/files. -Eric |
Re: Printf has just entirely failed to do anything
Good news & bad news...
I dropped your code as-is into one of our controllers and a printf I added to user_routines.c worked fine. Master code v12 IFI_Loader v 1.1 I ran without the camera as a first test then connected the camera. Which printf in what routine in particular were you having trouble with? P.S. In the version you posted none of the camera code is ever called from anywhere, so there won't be any "uncalled for" printf's from any of that code. I added a call to CAL_Update(); in Process_Data_From_Master_uP and uncommented the #include "camera_abstraction.h" and I'm seeing the printf's from the camera code. |
Re: Printf has just entirely failed to do anything
I'm using IFI Loader 1.1.0. I see no printfs anywhere, at all when I put this code into my rc. I've verified it's not my terminal program, serial port, or the rc itself as I loaded old code and it showed all the printfs fine. I can't test anything until somewhere around the 4th because I can't get into the shop until then. I had added printfs directly into main() because nothing else was working, and even that wasn't working. I suppose I should update the master code because I am pretty sure nobody bothered to do so last year--I think we're running v11 still.
Thanks again JBot EDIT: Is that what the new master code was released for--a fix in printf? I knew there was new code out there but I don't remember ever updating. I even have the binary on my machine right now, I just need to upload it. |
Re: Printf has just entirely failed to do anything
Quote:
The master code revisions usually are just to match changes in the field control software. v11 was released to fix a random twitch in the pwm outputs for Victors, but nothing that affects the behavior of our User code. The Master version won't affect your printf. I dumped v11 into my test controller just to eliminate that as a potential cause, and your code still works fine. Your code is small enough to fit and run on the older PIC-based controllers, so the IFI_Loader version isn't a likely issue. But if you get a Vex kit as a present you'll be able to test your code at home! I'd start with a close look at the simple solutions. When you get back to the robot after the holidays double check that you're downloading the .hex file you think you are. I notice you're putting the .hex file in a different directory than the source code (C:\old_'07_Code), so check the date on the file IFI_Loader is pointing to and verify it's new. Double check your C18 version (2.4). I'm sure you have the current version, but verify there aren't older versions or the Vex version conflicting. What's the history of the PC you're using? Has it been used for several years? Has MPLAB/C18/etc. been reinstalled around the time your troubles began? |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
Quote:
Quote:
It might work right now. I have no idea. I'll have to test it when we get back. JBot |
Re: Printf has just entirely failed to do anything
Quote:
The MPLAB version won't matter much either. It's just an editing/organizing tool. Don't sweat it until you're in a position to test again. It'll only drive you nuts. Right now what you've got looks good to me. I'll post the working hex file I compiled and you can use it to eliminate your PC/MPLAB/C18 as any kind of a suspect. Here's the hex file and the camera initialization output printfs I'm seeing. (ignore the "MLM" that's my test printf from user_routines.c) |
Re: Printf has just entirely failed to do anything
Alright, thanks. Got the file, will try it when we get back.
Some of the characters in the output are interesting, but I won't worry about it right now. Thanks You deserve a candy bar... Here you go: http://www.nadf.com/images/3musketeers_c.gif hehe...I'm going nuts already. Think of what the season is going to do...:yikes: JBot |
Re: Printf has just entirely failed to do anything
JBotAlan,
I think your problem is both obvious and simple to fix, luckily. Rearranging the Camera_Handler function etc, had nothing to do with it. Had you left the original code intact, you still would have broken the program by moving Camera_Handler() (or CAL_Update() in your program) from user_routines.c to Process_Data_From_Local_IO(). Move Camera_Handler() back where it belongs and everything will work wonderfully again. Here's my reasoning. Process_Data_From_Local_IO(), as you know, runs stupidly fast, as it runs every loop in the user PIC. As opposed to every 26.2ms for Process_Data_From_Master_uP(). Camera_Handler() is a very complicated little function, and does tons of fun stuff like disabling serial interrupts briefly and using the inherent timing of the slow loop to get the timing of its initialization correct. Basically, with Camera_Handler() in your Process_Data_From_Local_IO(), things are happening waaay too fast and piling up and generally causing the horrible broken execution and code error lights that you're seeing. To put it even more briefly, in the camera_readme.txt, Kevin Watson says you should call Camera_Handler() from Process_Data_From_Master_uP(). You really ought to listen to him unless you've initmately acquainted yourself with the operation of said function. |
Re: Printf has just entirely failed to do anything
Oh.
Maybe I should've read that readme. I figured that it shouldn't be in the slow loop because by default that doesn't even execute during auton, where we need the camera the most. I will definitely read through that function and the camera readme and see if moving the function call back to process_data_from_up helps. That would make sense if it was disabling and re-enabling serial interrupts very quickly... I never would've caught that. Thanks JBot EDIT: Just glancing through camera.c, I don't happen to see where serial interrupts are disabled/enabled, but I haven't looked at all of the function calls either. I do notice a loop_count variable; that alone warrants moving it back into the slow loop. Like I said, I need it to execute in auton. I may well modify this function so that it can safely execute in the fast loop. I don't know; I don't have time today to deal with this but thanks for the help. |
Re: Printf has just entirely failed to do anything
Kevin has a good point.
Although calling CAL_Update() from the fast loop (via Process_Data_From_Local_IO) would only prevent the camera from working properly. It wouldn't lockup the controller or disable printfs. The camera code doesn't take very long to execute. P.S. Your autonomous code should also execute in a slow loop. It doesn't help to execute faster than you can deliver instructions to the pwms. If you check the IFI default code you'll see the autonomous section in user_routines_fast.c is really a slow loop by virtue of the line: Code:
if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */I'd advise you to pull all your autonomous code out of the user_routines_fast.c file anyway. The name of that file only confuses the issue and your freshmen programmers, since it's not true for the autonomous code. |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
Quote:
JBot |
Re: Printf has just entirely failed to do anything
Quote:
You're right about the camera code executing quickly, but I think that might be where the problem lies. The initialization process fires off atleast a few packets to the camera. If Debug is on, it will also fire several long strings to the terminal. If all of this is in the fast loop... Well I just think the most likely culprit is all of these serial writes stacking up and possibly overflowing queues and generally making a mess of things. |
Re: Printf has just entirely failed to do anything
We're pretty much limited to updating the pwm outputs at the slow loop speed whether regular driver mode or autonomous. While there is the potential to update a few special pwm outputs at a faster rate, the devices attached to the pwm outputs, such as Victors, aren't designed to receive the updates very much faster than the current slow loop speed.
The Master processor enforces the playing field control overrides and filters our OI inputs as well as our pwm outputs, a la OI -> Master Proc. -> User Proc. -> Master Proc -> PWM outputs When it has us disabled the Master "neutalizes" our pwm outputs, when it has us in autonomous mode the Master "neutralizes" the OI inputs it passes to us.I conjecture that calling getdata() extra times will just return a copy of the last packet the Master prepared and I don't believe the Master does anything with extraneous putdata's until after NEW_SPI_DATA is reset to 1. You'd have to test that theory to be sure. In any case the response of the downstream systems such as the Victors, motors, and drivetrain will lag and swallow the milliseconds we might save. To work properly PID feedback control depends on regular feedback not just speed and to make correct decisions needs previous decisions to be acted upon. It'll quickly lose track of things if the outside world is ignoring 99% of it's requests for motor changes and only acting on a random 1%. Typically, use the fast loop of Process_Data_From_Local_IO to sample sensors, especially polled sensors, and collect data for use in making decisions later in the slow loop. Your decision logic based on OI inputs or resulting in pwm outputs don't need to be made any faster than we can tell the Master processor via getdata/putdata. The default code slow loop in main() is just used to kickoff the separate autonomous slow loop. The way the autonomous slow loop is coded doesn't allow anything else, including the main.c loop, to run again until the Master signals the end of autonomous mode. We eliminate the separate autonomous loop and only allow the main loop. Quote:
|
Re: Printf has just entirely failed to do anything
Quote:
Quote:
Quote:
Quote:
Quote:
Thanks JBot |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
Polling a pot on an arm usually isn't necessary, because it returns absolute position anyway. Quote:
One of the advantages of ripping the loop out of User_Autonomous_Code is that Process_Data_From_Master_uP and Process_Data_From_Local_IO continue to get called normally from main() without any extra work or duplication of effort. We add a few other improvements to main() such as initial delays to allow the systems and sensors to stabilize on powerup and automatically resetting autonomous on disable. It's nice that these changes apply to every mode and don't have to be implemented again for that autonomous loop. |
Re: Printf has just entirely failed to do anything
hmm i kind of got lost somewhere.... but ye .. if u still cant complie ur program with
#include <stdio.h> just a quick question.. have u added -nw=2066 in ur Alternate Settings in MPLAB C18? and if its already fixed then dunn wrry:) |
Re: Printf has just entirely failed to do anything
Quote:
The code compiles. There are no errors or warnings. I haven't modified the settings in MPLAB at all--I didn't know I was supposed to. It looks like the default code has that option set by default, as it is already there. Thanks for the hints, though. JBot |
Re: Printf has just entirely failed to do anything
1 Attachment(s)
OK--I just got back to the robot today (wow, Christmas break was like being locked in a small shed with no heat and snow all over the place, then getting back was like walking out of said shed into the sun). I did not try any of the old code/HEXes. I have been trying to get my new code working. It worked when I first put it on the controller, but problems showed up when I was trying to interface to a position sensor (like a pot, but has no mechanical limit; just snaps back around to 0). I was getting a good analog signal in; it ranged from about 16888 to 19000 (I think). At this point, everything was gravy. I decided to write up a quick program to watch the input, keep two static doubles, one min, one max, and check if the value coming in was out of range and adjust the according value, and printf both values every slow loop. I discovered either a compiler glitch or a printf bug, as both of my variables look like they have good data; I am getting good data back in the terminal for min, but not for max. For max, I either get 0 or -32767 (very suspicious, but I don't see where my code is overflowing and writing over one of the bits...). I put the printf on a separate line, instead of having a
Code:
printf("a is %d, b is %d\r\n",a,b);Why is printf so buggy? and does Kevin Watson have something that works a little better? Attached is the zip of my current code sans Kevin Watson's serial_ports.c/h and camera.c/h as he does not want these redistributed. Just plop them in the directory and it should work again. Thanks for trying to help. JBot |
Re: Printf has just entirely failed to do anything
I ahvent used C for a year
but arent u supposed to write Printf("a is %d",&A); Seems like you forgot the &..if im wrong tell me why.. |
Re: Printf has just entirely failed to do anything
Quote:
from http://www.sysprog.net/cpointer.html: Quote:
Thanks, JBot |
Re: Printf has just entirely failed to do anything
Values in the 18000 range seem rather large for data coming back from an analog input. Analog input values should be in the 0-1023 range as they are 10-bit data. Time to unzip your source code i suppose...
Edit starts here--- Printf's formatting identifier '%d' is actually meant for signed integers, NOT doubles (fixed-point printing of a double is %f, which back in the day was 'float', or single-precision floating point vs double-precision floating point. I digress too far in these parenthesis, sorry). Looking at your source, your min, max, and "i" variable are all doubles. You will get rather wacky results using the wrong format identifier for a given variable type. For analog inputs, stick with a regular int to store/manipulate data. PWM values can be put into a character since they are 8 bit values (0 to 255). No ampersand is needed for printf, unless what you wanted to print was the memory address of the variable. Sometimes thats useful for debugging pointers that don't seem to be in the right place :ahh: --Eric |
Re: Printf has just entirely failed to do anything
Quote:
-Kevin Edit: Whoops, looks like esquared answered your question while I was composing my posting. |
Re: Printf has just entirely failed to do anything
Quote:
Quote:
EDIT: Just reread your post, Kevin. So it's %u for an unsigned int or a char, and %f for doubles? I'll test this either tomorrow or the next meeting. I was wondering if it wasn't printf mangling what it was supposed to print... Thanks JBot |
Re: Printf has just entirely failed to do anything
Quote:
Using signed vs unsigned is somewhat a matter of preference for analog inputs. The advantage of signed is if you have calculations that have multiple steps and may temporarily take your integer value below zero. For example, you have a scaling function that has an offset in it, so that some positive value from the sensor still equates to zero after the calcs are done. Depending on how your code is written, this may not be necessary, but can make your code more readable. The disadvantage of signed is taking your value and applying it to something like a PWM output, where you're dealing with unsigned values. Even then using an int you want to be sure you're not exceeding 255 when assigning to the PWM output. --Eric |
Re: Printf has just entirely failed to do anything
Quote:
-Kevin |
Re: Printf has just entirely failed to do anything
Quote:
|
Re: Printf has just entirely failed to do anything
I would like floating point accuracy, and I know there are ways of representing a floating-point number inside an int, but I haven't really sat down and thought it out. I don't know how I want to shorthand this. Any suggestions?
I will probably keep using floating-point until it gets so slow that I get a code error. I know that this is emulated; I've seen other threads on not using floating point variables, but aside from speed, I don't see any reason to change. And I know I'm not taking anywhere near 26ms to complete a loop right now. I'll have to figure out an alternative to %f, though, and that might be the motivator to switch from floating point. Thanks for your help. JBot |
Re: Printf has just entirely failed to do anything
Quote:
|
Re: Printf has just entirely failed to do anything
First, think about what you are trying to printf to. The robot has no screen, so printf does not work. If you want to work from the command window from the IFI loader, then you must work with the concurring program.
I think that MP lab doesn't use printf anyway, I think they use something else... |
| All times are GMT -5. The time now is 20:44. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi