autoAB_prj
Rsadeika
Posts: 3,837
Since the other thread is getting a little long, I decided to start its own thread. Basically this is to see how close to autonomy the ActivityBot can get. The basic program below has, what I think, are the minimal support libs that will be necessary. And this is the first big hurdle: Code Size 27,052 bytes(31,044 Total). A brief observation follows.
Of course, so far the biggest use of RAM is the SD support code, I am starting to get the feeling that it may not be able to get any smaller, and I do not see a different solution at hand.
ABdrive, in order to work correctly, has to be run in its own cog, therefore limiting the possible use of XMMC mode. Maybe there is a way to code it so it does not prohibit XMMC mode use, I do not know.
I added <sys/rtc.h>, because the bot has to have a sense of time while it is operating, especially for any kind of data logging, and that would be a major operation or part of the autonomy. I also added the serial support libs, because a feature that I had in mind would be for the bot to contact the base station to get the "real time and date" to start its own internal clock.
I decided to go with a very small IR_remote segment, I think that is the most sensible way of starting the robot, and if the robot gets super smart, you can always press a button on the remote to start a return home procedure.
So, it sort of looks like this is doomed from the start, but some people might have some suggestions as to how to get around some of the problems I observed.
Ray
Of course, so far the biggest use of RAM is the SD support code, I am starting to get the feeling that it may not be able to get any smaller, and I do not see a different solution at hand.
ABdrive, in order to work correctly, has to be run in its own cog, therefore limiting the possible use of XMMC mode. Maybe there is a way to code it so it does not prohibit XMMC mode use, I do not know.
I added <sys/rtc.h>, because the bot has to have a sense of time while it is operating, especially for any kind of data logging, and that would be a major operation or part of the autonomy. I also added the serial support libs, because a feature that I had in mind would be for the bot to contact the base station to get the "real time and date" to start its own internal clock.
I decided to go with a very small IR_remote segment, I think that is the most sensible way of starting the robot, and if the robot gets super smart, you can always press a button on the remote to start a return home procedure.
So, it sort of looks like this is doomed from the start, but some people might have some suggestions as to how to get around some of the problems I observed.
Ray
Comments
Next, I would step through your code and make sure that you're not using redundant libraries. The most common is with serial. I'd make sure that you have only one serial section, and it's used wherever you need it. No printf for sure. I see from your main autoAB_prj.c file that you're using a number of different serial drivers. You'll need to pick one and stick with it. Printf is nice and handy (especially with the %s type modifiers), but it's pretty big. It should go. You'll need to make sure that none of the libraries use printf either, otherwise that will pull it in.
For a rough comparison, I have a project that uses SD, I2C, and serial that is ~24KB. It's all about trimming the fat: finding redundancies and unused code, and cutting it out.
The first point I want to make, I tried to set up the program in simple view, just like some of the new people are being instructed at the Learn site. This is probably an exercise in, what exactly can you do while using simple view, along with the simple libraries.
The one thing that SRLM noticed was that I used printf(), the reason that I used it was that if I use, the normally used print(), in this case, I get a compile error - "...hub overflow." This is the first time that I have seen that error, I guess that means that it has exceeded the 32K limit, but I thought that I would see that with the use of printf(). So, I am not sure if that is a bug, or just something weird that is occurring.
Doing some more thinking about what is to be accomplished, maybe this exercise should start by not using any libraries at all, and developing specific functions to accomplish what would be necessary to achieve the outlined program. Having said that, maybe the Learn site should get into teaching how to create drivers, starting with the servos and how to keep the two wheels functional at all times during a call during the program. Maybe then approach a good understanding and use of the encoders, then move on to the other things like serial I/O, the ping, the remote, other things on the Activity Board, ..., etc. I know "Hello, World" is a good first glance of C, but we are using this to work with the Activity Board.
Now back to my outlined program, if I strip out all of the header files, what exactly could I accomplish?
Ray
* And recreating code is just throwing away all the development effort that has been put into what you have already. It's helpful if you want to learn how to write a particular object, but otherwise think carefully before you write it yourself.
On a particular note about printf: I've noticed a large decrease in size if you don't use the % modifiers.
At this point I am not sure what else you could remove, short of possible redundant code in the actual libraries themselves. If you are going to do that, isn't that basically starting from scratch? Am I missing something completely obvious to everybody else?
Ray
And even if you have to modify the library to fit your needs it's still much less work then "starting from scratch".
#define printf print
I did notice that another large code grabber is the <sys/rtc.h> itself, maybe I should look into some kind of function that would act like small clock, but do not know how well the date part would work. This still looks to me like you have to grab the smallest code segments of these different functions like rtc, SD, and others. Not so sure that this is going to work out like I was hoping.
Ray
Wouldn't that only work for the current compilation unit? I'd think that you would need to use -D on the compile line to get it "global".
Ray,
One of the big hogs when using SD or other filesystem support is fprintf ... which is just like printf.
Replace fprintf with sprint(buffer, "something %d", number); and fwrite(buffer ...) more or less.
BTW, regardless of fprintf in SD stuff, the SD Card drivers in CMM will eat about 8KB of memory.
Converting SD card spin to C is not much better and you lose functionality.
What kind of an RTC do you have?
I think that the beginning of this thread is going to be used as, documenting the real limits of the ActivityBot functionality, in other words, what do have to work with. The key item, as I see it is the SD, so I might as well just deal with the fact that there is only 22K of actual code space to work in, I averaged up because that functionality will probably grow in code size, slightly I hope. Some key items that are missing, a compass, a horn, fancy bracket for the ping, and a real RTC. Not only do we have code restraints, we also have to deal with the breadboard, that also has a fixed space limit.
The horn is not to much of a problem, there is now a bracket that can be used for attaching it to the frame, no breadboard incursion, same goes for the ping bracket. The horn would become very useful as a locating device, there might be a time when it gets under your bed and it is not moving. For the ping in its current state, a fixed position it really puts some limits on the full potential of ping.
The compass is essential because it would add another bit of important data to the navigation aspect, a sense of real direction. This could add to resolving the issue of the stall pattern, the bot wheels are turning but the bot is not moving. I will have to look into the compass, in terms of communication, is it I2C or serial, or something else.
The RTC has a similar concern, I2C or ... The other concern is where does it get located on the breadboard, very limited space. A big concern could be if it is I2C, there is no buss, so you have to give up a couple of pins for that purpose, plus some support electronics.
Now I have to look into how to resolve the issues just described, but I think the bot autonomy could be achieved, in a very limited way.
Ray
It shouldn't be too hard to make a simple library that does things like getHours(time), etc.... Want to help define that?
Today I was looking at the global_Roam() function to see how that will be changed to be the core or central method for doing the mapping(navigation). I am still missing a key component, how do I get or figure out distance traveled as input from the encoder? The way that I am seeing this is, once the global_Roam starts, it will probably check to see if the SD card has a folder for the day, if not create one. Then it will create a file with a time stamp(161113_0.log) which will data log the movements for a particular run. The log file would probably contain a ping reading, a compass heading, a time stamp for start of bot movement, a time stamp for any derivation from the true course, or straight line, and of course a time stamp if the bot stops or pauses.
This is just an overview of a concept, probably I am missing something. I know that somewhere along the line the bot will have to make decisions based on comparison of data that has already been obtained, so the contents of the files will have to make some sort of comparison sense, I think, or is this overly ambitious for the ActivityBot?
Ray
There must be a way to convert encoder ticks to distance. Nikos mentioned something about using the encoder as an odometer in another thread.
As far as RTC goes, I was thinking of using get/set for date-time attributes, and get/set time for fake RTC updates.
Functions get/set for seconds, minutes, hours, ampm, month, monthday, yearday, year could be used to set seconds since the computing epoch.
The actual fake RTC is already implemented in propeller-gcc. We may need rtc_open/close or start/stop functions to simplify things.
Since I am not making any headway on the encoder part, I think I will try to implement some thing on this auto load of the time/date. Not sure if I will just do a simple Python script or try to add the functionality to the existing pyGUI program that I have. Maybe at the same time have a limited use of the global_Roam function to create some files on the SD and log the time/date. This might give me an idea as to how much code would be necessary for this small job.
Ray
The actual goal of init_td() function will be, convert an incoming data variable, via XBee, which will be in the form of, now.strftime(" %m-%d-%y %H:%M:%S\n") , so the function can set the clock.
Anybody have any insight as to what I got wrong here?
Ray
You should try this:
Edit: See jazzed's answer below.
I recommend breaking the comma habit even if you've been doing it for 30 years because some intern could come along and mess it up by adding ', ampm = "AM";'.
If you must use it, it would be this.
Below is the preferred method for many reasons including, easy to get right, and less source control conflicts. Using const forces not using the variables as storage which could otherwise cause problems.
There's a good discussion of this on SO: http://stackoverflow.com/questions/2704167/type-declaration-pointer-asterisk-position