To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 27108
  circular pointer
 
Some time ago some of you offered to help out if I (and I suppose anyone else) had any questions about programming.... well, here goes I'm reading "Building Robots with Lego Mindstorms" and in Chapter 12, there is some code to create a circular (...) (17 years ago, 12-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
(...) The line above is the line that cycles the array - each time through the loop it increments i and resets it to zero if it's >= SIZE (% is modulus operator). But I would agree with you about the v[i]=0 line - seems to me it would make the (...) (17 years ago, 12-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
I've added my comments to the code you posted (they start with **). I've also added some indenting.: #define SIZE 3 int v[SIZE],i,sum,ave; // initialize the array and some other variables sum = 0; for (i=0;i<SIZE-1;i++) { //I think this means set (...) (17 years ago, 13-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
I've inserted some comments, not all are questions, some are simply 'thinking aloud'. (...) So by defining SIZE here I can easily change the size of the macro without having to alter anything else in the code. Nice! (...) Right you are, I should (...) (17 years ago, 13-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
In lugnet.robotics, linmix <linmix@gmail.com> wrote: [snip] (...) [snip] I would say defining SIZE changes the size of the array and thus the period of the moving average. I'm not sure how you mean "macro" in this context. [snip] (...) Yes, both (...) (17 years ago, 13-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
(...) I should have written: 'array' (...) OK, undefined is not the same as zero, that makes sense (in a way). I looked up how to initialise an array and according to Dave Baum's NQC Guide "The initial values for an array's elements cannot be (...) (17 years ago, 14-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
(...) Another way to accomplish the same result with less code and less memory is to use exponential smoothing. (see Wikipedia) The method uses coefficients between 0 and 1, but if you want to use integers you can always use the integer numerator (...) (17 years ago, 16-May-07, to lugnet.robotics)
 
  Re: circular pointer
 
(...) There's something about that too in the same book. If I have some time this weekend I'll try to figure that one out. (thanks for the pointer, I'd forgotten about it) linmix (17 years ago, 17-May-07, to lugnet.robotics)

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR