Show Posts
Pages: 1 2 [3] 4 5 ... 29
31  Using Arduino / Programming Questions / Re: how do you perform math on a function in an array? on: April 23, 2012, 10:42:33 pm
I would tackle it this way:

(1) Isolate and evaluate the whole part as an int value
(2) Isolate and evaluate the numerator as an int value
(3) Isolate and evaluate the denominator as an int value
(4) multiply denominator times whole part and add numerator to produce the numerator of a (possibly improper) fraction
(5) add one-half of the denominator to this numerator for rounding, if desired
(6) divide this numerator (cast to float) by the denominator (also cast to float)
(7) the quotient is the value you're after.
32  Using Arduino / Programming Questions / Re: Least Squares Approximation on: April 23, 2012, 03:51:51 pm
It should be effective for closed-loop control as well. I'm applying heat to bring a Ni/H reaction to the ignition point and, since there isn't any historical data to work from (and because significant overheating could be hazardous), I'd like the control program to be able to use the actual dT/dt as the basis for determining how aggressively energy is being pumped into the reactor as it is heated to a target (test) temperature.

I've shown 200˚C as my target temperature for the plots, in which the vertical axis is the duty cycle of the heater and the horizontal axis is the current temperature. The degree of "aggression" is controlled by a one byte value that's adjusted dynamically to speed up or slow down the heating process.

I finally got around to plotting the "family" of curves for parameter values of 1, 2, 4, 8. and 16 (convenient doing division by shifting). I'll attach the plot.
33  Using Arduino / Programming Questions / Re: Least Squares Approximation on: April 23, 2012, 07:05:29 am
I think that the most effective strategy might be to first use the Arduino as a data acquisition front-end for a more capable machine for the least squares analysis to discover the specifics of the relationships, then make use of that relationship in the production Arduino software.

When that strategy can be adopted, the need to maintain a statistically-significant collection of data can be much reduced.

I did a bit of that myself this past weekend to come up with a formula for the amount of power to be applied to the ignition heater of a small LENR reactor. I wanted a formula that my controller code could adjust as it "learned" about the quirks of each particular reactor so which it might be connected. I'll attach some plots so you can see what I'm talking about and, perhaps, find the technique useful in your own project.   smiley-mr-green
34  Using Arduino / Programming Questions / Re: An easy-to-use code flow diagramming tool? on: April 23, 2012, 12:03:56 am
Ken - Sample attached (It'd have been better if I could have figured out how to label the decision choices.  smiley-mr-green)
35  Using Arduino / Programming Questions / Re: An easy-to-use code flow diagramming tool? on: April 22, 2012, 10:57:52 pm
Represent the function call with a "pre-defined process" flowchart symbol.

You can flowchart the called function just like any other program.
36  Using Arduino / Programming Questions / Re: An easy-to-use code flow diagramming tool? on: April 22, 2012, 04:30:49 pm
Was lurking...

I downloaded both packages for the Mac and gave them a quick try. For flowcharting (only) yEd looks pretty good - and for flowcharting plus a lot of other flavors of diagramming, Dia looks like a winner (although it uses up a sizable amount of file space).

I decided that for the time being I'd keep yEd for flowcharts, and see how much I actually need the capabilities of Dia. If it turns out that I don't need all that capability, I'll un-install Dia.

I think I'll retire my old green plastic template.   smiley-mr-green
37  Using Arduino / Programming Questions / Re: How to determine trending of values.. on: April 21, 2012, 08:50:36 am
The home-brew machine is a 3½-axis (spindle can be locked anywhere from vertical to horizontal) with a 1/4800" step size. My only images are stills I took during the build/test stage. I've posted three of the stills in the thread at http://arduino.cc/forum/index.php/topic,88204.0.html (Bar Sport, where stuff like this is topical).

More topical: If you have difficulty converting data points to a function, do a forum search on "least squares" - a while back I posted C source for a program (FABLS.c) that fits linear and a number of non-linear functions. It may help.
38  Using Arduino / Programming Questions / Re: How to determine trending of values.. on: April 20, 2012, 06:28:59 pm
If you're reduced to fishing, it's time to step back from the task at hand and learn more about the more general nature of programming in the Arduino environment.

If the problem has your head spinning, then it's time to take a break from the implementing of a solution and think about what you have to work with and what, in general, you want to use it to achieve.

When you're more relaxed with the endeavor, try writing a complete functional specification as though you were were going to spend your own hard-earned money to have someone else (paid by the hour!) build your device for you.

(BTW, I'm a ShopBot owner - and I also have designed and built my own CNC router. I like the looks of your Stinger.)
39  Using Arduino / Programming Questions / Re: How to determine trending of values.. on: April 20, 2012, 04:47:43 pm
Another approach might be to acquire stepper position and voltage readings at both ends of the pot's range. Since it's linear, you can then interpolate to make an accurate estimate of desired stepper position, move the stepper to that position, take a voltage reading and fine tune (probably just a step or two in either direction) if needed.
40  Using Arduino / Programming Questions / Re: How to determine trending of values.. on: April 20, 2012, 03:36:05 pm
1. What is the expected minimum and maximum time between events?

2. If the analog values were plotted against time, do you expect a linear or non-linear graph? (If non-linear, what type of relationship are you expecting?)

3. Are you aware that there will be (in computer time) a significant delay between the time you acquire an analog reading and the time the stepper completes the indicated movement? One of the possibilities is to incorporate heuristic and/or predictive processing - but the (apparent) downside is that that kind of help can't be provided by "blindfolded" people...
41  Using Arduino / Programming Questions / Re: send two data from sensor into serial communication. on: April 20, 2012, 01:30:33 am
@Amy - I did a quick and dirty re-write of your code (based on the assumption that your ping and load cell logic is correct). I removed the averaging from the load cell readings, and you can put that back yourself after you have verified that the code is working correctly.

I did the re-write not to hand you a completed solution for your project, but rather to show how program structure can either complicate or simplify coding. I don't have your hardware to test with and so haven't compiled or tested what I'm showing.

You will need to set your serial monitor to 115200 baud to test - there shouldn't be any need to slow communication down to 9600 baud.
Code:
#define LOAD 0
#define PING 7
#define WAIT 200
/*----------------------------------------------------------------------------*/
/* Load cell calibration values                                               */
/*----------------------------------------------------------------------------*/
const float loadA = 0;        // kg
const float analogvalA = 22;  // analog reading taken with load A on load cell
const float loadB = 20;       // kg
const float analogvalB = 176; // analog reading taken with load B on load cell
/*----------------------------------------------------------------------------*/
/* Program variables                                                          */
/*----------------------------------------------------------------------------*/
unsigned d;                // Distance in cm
float    m;                // Mass in kg
unsigned long cur,prv=0;   // Current, previous time (msec)
/*----------------------------------------------------------------------------*/
/* The speed of sound is 340 m/s or 29 microseconds per centimeter. The wave  */
/* goes and returns, so we take half the distance travelled. (32767 cm max)   */
/*----------------------------------------------------------------------------*/
unsigned dist(void)
{  pinMode(PING,OUTPUT);
   digitalWrite(PING,LOW);
   delayMicroseconds(2);
   digitalWrite(PING,HIGH);
   delayMicroseconds(5);
   digitalWrite(PING,LOW);
   pinMode(PING,INPUT);
   return (unsigned)pulseIn(PING,HIGH) / 58;
}
/*----------------------------------------------------------------------------*/
/* mapfloat() - Custom float map function                                     */
/*----------------------------------------------------------------------------*/
float mapfloat(float x,float in_min,float in_max,float out_min,float out_max)
{  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
/*----------------------------------------------------------------------------*/
/* mass() - Return mapped load cell reading                                   */
/*----------------------------------------------------------------------------*/
float mass(void)
{  return mapfloat(analogRead(LOAD),analogvalA,analogvalB,loadA,loadB);
}
/*----------------------------------------------------------------------------*/
/* setup() - Arduino initialization                                           */
/*----------------------------------------------------------------------------*/
void setup(void)
{  Serial.begin(115200);
   prv = millis();
}
/*----------------------------------------------------------------------------*/
/* loop() - Arduino cycle mechanism                                           */
/*----------------------------------------------------------------------------*/
void loop(void)
{  cur = millis();
   if (cur - prv >= WAIT)
   {  prv += WAIT;
      d = dist();
      m = mass();
      Serial.print("m=");
      Serial.print(m);
      Serial.print("kg, d=");
      Serial.print(d);
      Serial.println("cm");
   }
 }
/*----------------------------------------------------------------------------*/
42  Using Arduino / Programming Questions / Re: Ultrasonic range sensor not working correctly with Nano on: April 19, 2012, 06:05:23 pm
Could it be a voltage/power issue?
43  Using Arduino / Programming Questions / Re: Neeeewbie might be over his head. on: April 18, 2012, 09:29:31 pm
(1) All of the led pin definitions should have the form

#define  <identifier> <output pin number>

The compiler is complaining because the definition of led22 is incomplete.

(2) The first line comment needs to begin with /*

and (3) you'll need to add two closing braces following the code that you've shown - one to complete the final if statement, and one to complete the loop() function.

In the code I suggested, the LED identifiers ended with two digits: the first digit identified what you had called the set, and the second digit was intended to uniquely identify the LED within the set. You, of course, are free to label them however you choose, but please choose identifiers that will make sense six months from today.

Two strong suggestions:

(1) when you post code, click on the "#" button and paste your code between the pair of bracketed code and /code tags, click the "Preview" button, and check the preview before clicking on "Post".

(2) Notice that C and C++ are "case sensitive", meaning that uppercase letters are not interchangable with the same letter in lowercase.

Since you didn't describe the behavior you wanted for the third set of lights, I didn't provide any code. In order for the red and blue lights to do anything, you'll need to learn enough to write that tiny bit of code...
44  Using Arduino / Programming Questions / Re: serial parametric strings on: April 18, 2012, 11:09:37 am
I just posted this code for someone else. Customized just for you:
Code:
int xtract(char *s,int n)
{  int v = 0;
   while (n--) v = 10 * v + *s++ - '0';
   return v;
}

char *input = "11222333";

int v1 = xtract(input,2);
int v2 = xtract(input+2,3);
int v3 = xtract(input+5,3);
Please let me know if you find a faster way.   smiley-mr-green
45  Using Arduino / Programming Questions / Re: Neeeewbie might be over his head. on: April 17, 2012, 11:49:16 pm
Graynomad beat me to it (I'm a slow typist), but I'll post what I roughed out anyway. You'll need to replace question marks with appropriate numbers, but I don't think you'll have difficulty getting started.
Code:
#define LED11 ?
#define LED12 ?
#define LED21 ?
#define LED22 ?
#define LED31 ?
#define LED32 ?
#define LED33 ?
#define LED34 ?
#define LED41 ?
#define LED42 ?

#define T1 300
#define T2 100
#define T3 ?

unsigned long cur,prv1=0,prv2=0,prv3=0;
int s1=0,s2=0,s3=0;

void setup(void)
{  pinMode(LED11,OUTPUT); /* 1st set (wig-wag) */
   pinMode(LED12,OUTPUT);

   pinMode(LED21,OUTPUT); /* 2nd set (flashing yellow) */
   pinMode(LED22,OUTPUT);

   pinMode(LED31,OUTPUT); /* 3rd set (2 x blue,red) */
   pinMode(LED32,OUTPUT);
   pinMode(LED33,OUTPUT);
   pinMode(LED34,OUTPUT);

   pinMode(LED41,OUTPUT); /* 4th set (headlights) */
   pinMode(LED42,OUTPUT);

   digitalWrite(LED41,HIGH); /* Turn on headlights */
   digitalWrite(LED42,HIGH);
}
void loop(void)
{  cur = millis();
   if (cur - prv1 > T1) /* Set 1 - wig-wag */
   {  prv1 = cur;
      s1 = !s1;
      digitalWrite(LED11,s1);
      digitalWrite(LED12,!s1);
   }
   if (cur - prv2 > T2) /* Set 2 - flash together */
   {  prv2 = cur;
      s2 = !s2;
      digitalWrite(LED21,s2);
      digitalWrite(LED22,s2);
   }
   if (cur - prv3 > T3) /* Set 3 - (TBD) */
   {  prv3 = cur;
      s3 = !s3;
      /* Whatever you want set 3 to do */
   }
}
Pages: 1 2 [3] 4 5 ... 29