Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Re: Use of load cell for monitoring specific gravity of liquid over time/arduino uno on: June 06, 2014, 05:02:05 pm
Bubbling up (pun intended) smiley
OP, how is the progress on your project? I thought of this thread after seeing this:http://www.thebeerbug.com/

2  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 05, 2014, 03:05:05 pm
@wildbill, I could kiss you ... well if you weren't a dude with a big bushy beard or handlebar mustache  smiley-evil

Why is that an obstacle?  smiley

...R
It's more that he's a guy... But the beardiness would be an extra obstacle smiley-razz
3  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 05, 2014, 02:51:50 pm
@wildbill, I could kiss you ... well if you weren't a dude with a big bushy beard or handlebar mustache  smiley-evil
Anyway, your suggestion was spot on.

Here's my updated program, sans SM.
Code:
String steps[] = {
  "Strike", "Mash1", "Mash2", "Boil"};
float temps[] = {
  152,150,160,212  };
float times[]={
  .5,1,1,1};
boolean needsUserInput [] = {
  true, false, true, false};
int numSteps = (sizeof(steps)/sizeof(String));//number of steps
int count = 0;
float Setpoint;
//unsigned long time;
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;
unsigned long stepTime = 0;
String currentStep = "";
boolean inputRequired = false;
boolean timesUP = false;
boolean inputReceived = false;
unsigned long stopstep;
unsigned long startstep;
boolean timercalculated;
int avgTemp1 = 160; //manual faking of temperature


void setup(){
  Serial.begin(9600);
}

void loop(){
  getStepInfo();
  timesUpCheck();
  nextStep();
  //inputReceivedCheck();
  delay(1000);
}

void getStepInfo(){
  // boolean gotoNextStep = false;
  //while (!gotoNextStep) {//necessary?
  currentStep = steps[count];
  Setpoint = temps[count];
  stepTime = (times[count] * 60000);
  inputRequired = needsUserInput[count];

  Serial.print("step=");
  Serial.print(currentStep);
  Serial.print(" temp=");
  Serial.print(Setpoint);
  Serial.print(" times=");
  Serial.print(stepTime);
  Serial.print(" user input to go to next step? ");
  Serial.print(inputRequired);
  Serial.print(" time up=");
  Serial.print(timesUP);
  Serial.print(" input received=");
  Serial.println(inputReceived);
  // }
  //count++; //does that go here or in next step
}
int nextStep(){
  if (timesUP && (avgTemp1 >= (Setpoint -5)) && inputRequired && !inputReceived){
    soundAlarm();
    inputReceivedCheck();
  }
  else if (timesUP && (avgTemp1 >= (Setpoint -5)) && inputRequired && inputReceived){
    count++;
    timesUP = false;
    inputReceived = false;
  }
  else if (timesUP && (avgTemp1 >= (Setpoint -5)) && !inputRequired){
    count++;
    timesUP = false;
  }
  else {
  }

}

boolean timesUpCheck(){
  Serial.println(timercalculated);
  Serial.println(startstep);
  if (timercalculated == false) {
    startstep = millis(); // start step clock, reads milliseconds from this moment
    stopstep = startstep + stepTime; // calculate the end of step from the configuired time "hltpumpruntime"
    timercalculated = true; // don't do again whilst in this step
  }
  Serial.println(timercalculated);
  Serial.println(startstep);
  Serial.println(stopstep);
  Serial.println(millis());

  if (millis()>=stopstep) { // time has finished
    timesUP = true;
    timercalculated=false; // next step's timer not yet calculated
  }
  return timesUP;
}

void inputReceivedCheck(){
  String str = ""; 
  while (Serial.available()>0) {
    str = Serial.readStringUntil('\n');
  }
  if ( str == "next"){ 
    inputReceived = true;
  }
  //return inputReceived;
}

void soundAlarm(){
  Serial.println("beep beep beep");
}




Any thoughts on improvements, etc?
4  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 05:45:31 pm
It appears that you could reduce this to fewer states (or none). All the recipe needs is a list of temperatures and how long each needs to be maintained. Perhaps additionally a flag to tell the system whether it needs to signal you to take action before moving  on to the next temperature. Perhaps a name for the operation it's carrying out.

No need for XML therefore - you can just send a comma separated string, copy it into a buffer and parse it as you need to get the next step.
I like where you're going WildBill. I tried this, but don't really know how to pull it off. The XML can be parsed in Python and sent over the wire as a list of CSVs. I was thinking that would go into 3 arrays - names, temps, and times. I suppose I could use a 4th for "needs user input".  And if "needs user input[X] = 'yes' then that state can wait until the user input is satisfied.
If you take a look at my code, I was thinking in this direction, but as I said, I'm not sure how to pull it off. I may take another crack at it tonight. The array of "needs user input" may be the piece I was missing.  smiley-cool

Thanks,
JR
5  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 04:49:40 pm
Quote
I understand from your post that my state machine Hold0 is in a loop in loop() so serial.available() is able to keep being .... available... Probably what I need to do then is move EXEC(Hold0) out of the loop() and into setup(), but give it its own loop to read characters. What is the best way to do that? giving it a loop to allow reading multiple characters from serial?

No, you misunderstood me. The EXEC(Hold0) is not that wrong in the loop() but having only that state machine being called in the loop you must never call it's Finish() method. EXEC() is not being called once and then the state machine runs "itself" but it's designed to be called repeatedly, it's the working horse of the state machine. I got the impression from your code that you thought that you call EXEC(Strike) and then that state machine is running in a kind of "background" task/process, so you can end the Hold0 state machine. This is not the case. An Arduino doesn't have an operating system that is taking care of processes and background tasks. It does run through our program, the only exception are the interrupts but that's more a hardware thing.
Each of your state machines have only one state and that's where I think is your conceptional error.

Maybe you should describe what your whole program is expected to do.

Pylon,
If I don't finish the SM Hold0, then I can never use the serial string "next" anywhere else. That's not 100% horrible, but does limit my ability to change how I go through my states (see above response to Zoomkat) .

I was hoping to avoid being a double poster, but I can see that you need a bit more context.
I'm building a home brewing system, this system will be unique because of 4 key features:
  • Propane heated, using a servo to control propane flow (as opposed to electric or on/off control of gas)
  • Brew In A Bag, not 3 vessel
  • Support multiple mash steps
  • Read data from BeerXML files
The first one is unique in the world of home brewing as far as I can tell. Others have taken the idea and run with it - my friend tob77 made a version in Python for RasPi, http://www.homebrewtalk.com/f235/raspberry-pi-brew-controller-451059/
But I'm a bit unsure if Arduino can support the sheer number of 'if' statements that he's using to get his states.

If you don't know about beer brewing (and BIAB particularly) what you need to know is that beer is made  by soaking grain in hot water of around 150F for some period of time. This has the effect of converting the starches in the malted grain into sugars and extracting those sugars from the grain. The enzyme activity that does this conversion is controlled by the temperature of the water. Too cold, no enzyme activity, too hot, you denature the enzymes. There is a sweet spot where you can convert the starches using alpha and beta amylase, but each of those works better at a specific temperature. Beta amylase works best at 130-150, and Alpha works best at  150-160.
http://www.howtobrew.com/section3/chapter14-5.html

So, to best control the profile of the beer, I want to control the mash profile - how many steps, what temperature, and for how long.  That's what brings me to the state machine, because I want to have multiple mash states that aren't always going to be used. tob77's solution is to have a "beta rest" whether or not he uses that step. I don't want to have the step if not necessary.

Some steps in brewing will always be there, though. There is always a strike (initial water heating) step and there will always be a boil step.

I've got my arduino program working pretty well, except getting the recipe information out of beerXML and into some format that will change Setpoint and control time for each of the steps. Also, there need to be some alarms  and steps that have nothing going on for time to add the grain to the strike water.

Attached is my full sketch for the automated BIAB, but it's missing the getRecipes() section, and that's what I want the state machine for. Of course, if it works well there, I could do the whole thing in state machines, then I don't need delay(), huzzah!

I hope that's clear. Let  me know if not and I can clarify.

Thanks,
JR
6  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 01:34:52 pm
Quote
Then he should have said "hey dummy, I don't know about that library and you didn't provide a link for me to learn more".
And I would've said "D'oh! You're right!".

I agree.

Quote
Instead, he complained about my formatting, which isn't helpful. In fact, it probably wasted everyone's time while I went off and checked my \t in the file. If the bar for getting help on this forum is that we have perfectly formatted code that complies to convention perfectly, then nobody will be able to get help on this forum and nobody who's on the forum will actually need the help.

Sometimes I see horribly formatted code which misleads the interpretation, then I also complain about the formatting. Although your code is not an example of how one should format code, it's readable doesn't mislead in my opinion, so I agree also that PaulS' complains were a bit "picky". Nevertheless, if you read the sticky post at the top of the forum you would have linked the library in your first post and Paul could have seen that it's more or less the library example. If he then would have written the same post, it would have been a complete overreaction.

Back to your problem to calm down.

You didn't understand the state machine concept (at least not the own of that library). EXEC() does run one loop of the state machine. In your loop your calling state machine Hold0 and in that body function you finish the state machine. From that moment EXEC(Hold0) will return immediately and you end in an endless loop, doing nothing.

Thanks, now that I'm not feeling quite so cranky ....
I understand from your post that my state machine Hold0 is in a loop in loop() so serial.available() is able to keep being .... available... Probably what I need to do then is move EXEC(Hold0) out of the loop() and into setup(), but give it its own loop to read characters. What is the best way to do that? giving it a loop to allow reading multiple characters from serial?


Quote
Basically, don't be Nick Burns, the company computer guy:

Well, you started out with some "state machine" mumbo jumbo instead of stating specifically what you want the arduino to do in your project.  Probably best to start back with the basics of what you want to do. That being said, there are members of the forum that in my opinion have personality issues that become apparent in the way they think they are being "helpful". Anyhow there have been previous brewing projects discussed in the past and studying those previous post may provide some useful information.

https://www.google.com/search?as_q=brew&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fforum.arduino.cc%2Findex&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=

Zoomkat, I posted another thread in the Project Guidance forum (which you posted on B)
http://forum.arduino.cc/index.php?topic=229539.msg1657014#msg1657014
I didn't want to double post though, since I thought this was a relatively small issue. Now that I see what the problem was (not that serial just wasn't reading, but that the while loop went by impossibly fast), I see that it's a larger issue with using  State Machines and my implementation particularly.

I've looked at the code for BrewTroller and HABS, but both are using if statements. So.Many. Ifs. I'm trying to avoid that, and I'm also trying to create a program that allows for multiple mashes to create a mash profile that isn't a single mash time/mash temp.

Thanks,
JR
7  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 12:38:06 pm
Quote
but found that it doesn't like the switch being based on long strings coming thorough serial. Seems Switch can deal with bytes and integers.

SWITCH can deal with anything you throw at it. It is just another form of IF. Getting long strings through the serial connection is a little more complicated. If the strings are just for the purpose of choosing between CASE options then it makes sense to keep them short as - single characters if possible. Remember that "pleaseLetTheElephantsHaveWater" doesn't convey any more information to a computer than "E" or "W".

...R

OK, I gotcha. What I'm not certain about is how I want to send signals regarding multiple Mash states. Do I want to have a single mash state that I want to call repeatedly, with different values for Setpoint and Time? Should I create multiple mash states that each get called sequentially? Or perhaps multiple  mash states that can be called (or not called) in any order. That changes how I'd want to send the signal to the program, in the first and second options I can just send "next", or more simply "n". If I want to call mash states out of sequence, then I would need to be able to say Mash1, Mash2, or at least M2. So, I've been defaulting to the longer string signal coming from serial.

Can I have multiple cases running at once in switch(case)? I don't need to have the convenience features of SM for timers, I can write a if milliseconds - targetMilliseconds(30000) for each case.  Having multiple machines running at once could be very useful though.

Thanks!
8  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 12:05:57 pm
Quote
At any rate, I'm merely following the examples set up in the SM library .

At least PaulS got you to provide a link to the SM library you're using. It's you who have to provide that information. You should not waste our time by expecting all of us to search for it on Google just to find out that you may have used a different version.

Then he should have said "hey dummy, I don't know about that library and you didn't provide a link for me to learn more".
And I would've said "D'oh! You're right!".

Instead, he complained about my formatting, which isn't helpful. In fact, it probably wasted everyone's time while I went off and checked my \t in the file. If the bar for getting help on this forum is that we have perfectly formatted code that complies to convention perfectly, then nobody will be able to get help on this forum and nobody who's on the forum will actually need the help.

Basically, don't be Nick Burns, the company computer guy:
9  Using Arduino / Programming Questions / Re: Controlling an Electronic Throttle Body using a PID controller on: April 04, 2014, 11:57:58 am
Trust me, I was against the idea of an electronic throttle body from the start (and I'm an EE!), especially because we have a cable operated throttle already.  The ME's of the group insisted on using the electronic throttle body because they thought it would be easier than fabricating a throttle position sensor to a normal pedal that we can use to send to the motor controller.  This way a commercial  throttle pedal will control both the ICE and the motor.   

At this point I don't have much of a choice other than to get it to work.  If I shouldn't use a PID, then what should I use? 

The throttle body doesn't have any control circuitry in it, just direct connection to the motor and two potentiometers that work inversely from each other.  The throttle pedal has two potentiometers in it as well, but one of them has an extra resistor in series with it and instead of working inversely the difference of the two signals is supposed to be taken.  I can't seem to find any documentation online about the system we have.  All I have to go off of is this training manual we have. https://drive.google.com/file/d/0B7_wYqRQ2P5pT3l3RWhYRWpnaTA/edit?usp=sharing

In the manual there are no specific values listed, but a few plots of what the signals should look like and the pins we should use.  Unfortunately though, it looks as if the ECU is supposed to do all the calculating.  So I basically have to simulate that portion of the ECU with an Arduino.

With all the being said, do you have any suggestions as to how to control this in a better way?

Thank you!

I'm glad to hear you're suspicious of drive-by-wire. That could be one of the worst pieces of technology foisted upon mankind in recent years. smiley

Quote
The throttle body doesn't have any control circuitry in it, just direct connection to the motor and two potentiometers that work inversely from each other
So what you're saying is that you don't have a servo controlling the t-body. That makes a difference, so you want the the PID algo on the Arduino to turn your motor+TPS into a servo. I gotcha now smiley

PID are fairly slow algorithms by nature, they are designed for systems where there is lots of lag and overshoot, noise, or ripples.

I don't think that's at all accurate. PID is designed for controlling linear dynamic systems. A PID controller can be as fast or as slow as you want, and they are absolutely the right way to control something like a throttle where you want maximum responsiveness and yet avoid oscillations and overshoots.

It's not that it's not accurate per se, it's that it's a gross oversimplification. PID controls are good at controlling the rates of change. Servos use them to go fast to get near position X, then as they get close, they slow down. Once at the desired position they stop. If you manually turn the servo horn, the servo will apply more and more force from the motor to try to hold position.

Given that he isn't using a servo to control the T-body, using PID might make some sense. I'm concerned that running it through the arduino may be too slow, and since there's not really much disturbance or overshoot in a throttle system, may be unnecessary. The throttle just has to go to the position described and stay there, so a 1:1 mapping might be just as good. 
Basically, what you are doing is like the Knob sketch except that you need to get the position yourself, reading one or both of your TPS.

I'd start with a simple read one throttle Pot, move the motor, read the TPS pot. Then get more complicated so you are using both throttle pots and both TPS pots. You could even do that with a separate pot, motor, pot to simulate your pedal, throttle, and tps.
Maybe something like this (pseudocode):
newThrottle = analogRead(pedal)
actualThrottle= analogRead(TPS)

if actualThrottle < newThrottle {motor ++}
if actualThrottle > newThrottle {motor --}

Alternatively, you could hack the Throttle Body with a servo instead of a motor,
10  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 11:30:29 am
Code:
void loop(){
  EXEC(Hold0);
}
First, all upper case names are reserved, by convention, for constants that are #defined into existence. That is certainly not the case here.

Second, the name tells us NOTHING about what the function does.

Third, it is pointless to have a function that does nothing but call another function. One of them is redundant. It isn't loop().

Fourth, the indenting in the rest of your code sucks. Use Tools + Auto Format BEFORE posting any more code.

Why not throw in "and your mother wears combat boots!" while you are at it, PaulS?

At any rate, I'm merely following the examples set up in the SM library .  My apologies that the library's use of EXEC and single functions within loop() offend you. I made the assumption that since a more experienced programmer made the library, I should just follow his/her lead. Merely pointing out defects in my usage without providing possible solutions is not particularly helpful though.

Regarding my indentations, I did an autoformat and found all of 4 diffs between the two files.
Here's the autoformatted output:
Code:
#include <SM.h> //Simple State Machine Library
//State Machine names go here MachineName(headstate,bodystate)
SM Hold0(H0h,H0b);
SM Strike(S1);
SM Hold1(H1b);
SM Mash(M1);
//SM Hold2(H2) ;
//SM Boil(B1) ;

/**** global variables *****/
double Setpoint;
//String str;

void setup(){
  Serial.begin(9600);
}

void loop(){
  EXEC(Hold0);
}

State H0h(){
  Serial.println("hello");
}

State H0b(){
  while (Serial.available()>0) {
    String str = Serial.readStringUntil('\n');
    if(str == "next"){
      Serial.println("going to Strike");
      EXEC(Strike);
      Hold0.Finish();
    }
  }
}

State S1(){
  Serial.println("S1");
  Setpoint = 155;
  int temp = 150; //manual faking of temperature
  while (temp < Setpoint){
    temp++;
    Serial.print(Strike.Statetime());
    Serial.print(" setpoint= ");
    Serial.print(Setpoint);
    Serial.print(" temp= ");
    Serial.println(temp);
  }
  Serial.println("going to Hold1");
  EXEC(Hold1);
  Strike.Finish();

}

/*State H1h(){
 Serial.println("H1");
 //Hold1.Set(H1b);
 }*/

State H1b(){
  while ((Hold1.Statetime() - 5000000)){
    while (Serial.available()>0) {
      String foo = Serial.readStringUntil('\n');
      if(foo == "foo"){
        Serial.println("going to Mash");
        EXEC(Mash);
        Hold1.Finish();
      }
      else if(foo !="foo"){
        Serial.println("HUH?");
      }
    }
  }
  Serial.println("h1b");
}

State M1(){
  Serial.println("Mash");
}


You are correct that my functions have very little description to them -
Hold just means that the code shouldn't do anything until I send an input. This is to give time for adding ingredients or removing ingredients. Strike is the initial heating of the water.
Mash is the conversion of starches to sugars within the grains.
They are different states because the inputs/transitions for each state is different. 
Hold just waits for a user's input, in this case the string "next" to come over the serial pipe.
Strike is just looking for temperature to hit its target.
Mash (isn't yet, but will soon) look for temperature to be near target and wait for some period of time.


Robin2,
The reason I chose the SM library is it seemed like an easy way to implement the state machine with some extra timing functions thrown in. Being able to have multiple "machines" running with separate Timeout() functions seems like it would be great if I want to scale up to a 3 pot system (currently, this is for a single pot, Brew-In-A-Bag).  I will dig into your thread a bit more though, seems like you understand state machines quite well. I did try switch(case), but found that it doesn't like the switch being based on long strings coming thorough serial. Seems Switch can deal with bytes and integers. If statements seem to produce a lot of code, so I was trying to avoid them, particularly since there may be a variable number of states (Mash steps could be between 1  and 4, usually 1 or 2 steps).

Thanks,
JR

11  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 04, 2014, 12:02:35 am
Okay! the answer came to me after typing my response below, but brings up a new question

What's happening is the While loop goes by too fast, so delay paused it, if I put it inside another while loop, I can make it stick around

Code:
#include <SM.h> //Simple State Machine Library
//State Machine names go here MachineName(headstate,bodystate)
SM Hold0(H0h,H0b);
SM Strike(S1);
SM Hold1(H1b);
SM Mash(M1);
//SM Hold2(H2) ;
//SM Boil(B1) ;

/**** global variables *****/
double Setpoint;
//String str;

void setup(){
  Serial.begin(9600);
}

void loop(){
  EXEC(Hold0);
}

State H0h(){
Serial.println("hello");
}

State H0b(){
  while (Serial.available()>0) {
    String str = Serial.readStringUntil('\n');
    if(str == "next"){
      Serial.println("going to Strike");
      EXEC(Strike);
      Hold0.Finish();
    }
  }
}

State S1(){
  Serial.println("S1");
  Setpoint = 155;
  int temp = 150; //manual faking of temperature
  while (temp < Setpoint){
    temp++;
    Serial.print(Strike.Statetime());
    Serial.print(" setpoint= ");
    Serial.print(Setpoint);
    Serial.print(" temp= ");
    Serial.println(temp);
  }
  Serial.println("going to Hold1");
  EXEC(Hold1);
  Strike.Finish();
 
}

/*State H1h(){
  Serial.println("H1");
  //Hold1.Set(H1b);
}*/

State H1b(){
  while ((Hold1.Statetime() - 5000000)){
  while (Serial.available()>0) {
    String foo = Serial.readStringUntil('\n');
    if(foo == "foo"){
      Serial.println("going to Mash");
      EXEC(Mash);
      Hold1.Finish();
    }
    else if(foo !="foo"){
      Serial.println("HUH?");
    }
  }
  }
Serial.println("h1b");
}

State M1(){
  Serial.println("Mash");
}
 

But now it sticks around so long that if I type "foo" after the Hold1 state should have finished, I still get the output "going to Mash".
So, now I'm not quite understanding what "State.Finish()" really means. Seems like Finish() should make the state stop.

Anyway, michinyon if there is some less complicated way to do this, I'm all ears. I've looked at Switch(case), but that gets more complicated in a hurry when trying to handle timers, sensor inputs, and serial inputs all at once. I was hoping SM would be the more elegant solution, but maybe not ?
12  Using Arduino / Programming Questions / Re: Why does serial.read stop working? on: April 03, 2014, 11:53:22 pm
That seems to be a gratuitously complicated method of implementing a "state machine".

Perhaps your problem is related to using Strings.

The other part of the code that looks dodgy,   is where you attempt to read the string from the serial.     What do you expect the readStringUntil()  function to do,  exactly ?   Is the other end of your serial communication sending the newline character that you expect ?   You might have fallen into some version of the  CR  vs  CR-LF  problem.

Thanks for the reply Michinyon, the readstringUntil('\n') works fine in the upper section, so it shouldn't be that. I'm just using that to simulate sending some info through serial by using serial monitor.

What I did find - after another glass of wine and some more debugging - is that the serial is still working, and the while loop isn't being skipped, it just goes by too fast. I added a delay(4000) to the code and was able to get to the next state, but why does it jump like that, when it doesn't in the Hold0 state?

The idea is that the Hold states should just sit there until I enter a command, then go to the next state. This is to give me time to add/remove grains, etc.

13  Using Arduino / Programming Questions / Re: Troubles with Serial Monitor on: April 03, 2014, 11:17:17 pm
Try setting
Code:
  Serial.begin(115200);

to
Code:
  Serial.begin(9600);

I always get weird characters out of serial monitor if I have the baud rate on something weird. YMMV
14  Using Arduino / Programming Questions / Re: Controlling an Electronic Throttle Body using a PID controller on: April 03, 2014, 11:13:52 pm
Why in the heck would you want to use a PID for controlling a throttle body? I know a fair bit about cars, and bit about PID algos, but I fail to see how a PID helps you. PID are fairly slow algorithms by nature, they are designed for systems where there is lots of lag and overshoot, noise, or ripples. Furthermore, your servo will have a PID algo built into its controller for the purpose of maintaining a set position against any disturbances. Finally, what you want out of a throttle control is speed and a direct, linear relationship to the loud pedal. Don't muck it up more than you absolutely have to.

The reason that carmakers these days use electronic throttle bodies is because it gives them the ability to "get in the way" of the driver for the purpose of fuel economy and safety (traction control). Since you're in FSAE hybrid, the former is probably your concern. What I'd suggest is a "race" map for the Autocross portion - with a 1:1 mapping of throttle pot to throttle body - and an economy map for the efficiency portions of the test - using some damping factor.

You should have a well-trained driver in the cockpit, so don't make the throttle body the brains of the operation.
15  Using Arduino / Programming Questions / Why does serial.read stop working? on: April 03, 2014, 10:55:27 pm
So, I've been playing with the Simple State Machine Library, for the purpose of automating a home brewery. State machines seem like the way to go given the finite, sequential states for brewing beer. I've started small, with a sketch just focusing on the state machine itself, but I'm having a problem - serial reads stop working! I'm using serial.reads to fake a button press on the computer - eventually I want to run  a program on the PC that talks to the arduino for uploading recipes, logging, and managing state transitions.

Here's my sketch thus far:
Code:
#include <SM.h> //Simple State Machine Library
//State Machine names go here MachineName(headstate,bodystate)
SM Hold0(H0h,H0b);
SM Strike(S1);
SM Hold1(H1b);
SM Mash(M1);
//SM Hold2(H2) ;
//SM Boil(B1) ;

/**** global variables *****/
double Setpoint;
//String str;

void setup(){
  Serial.begin(9600);
}

void loop(){
  EXEC(Hold0);
}

State H0h(){
Serial.println("hello");
}

State H0b(){
  while (Serial.available()>0) {
    String str = Serial.readStringUntil('\n');
    if(str == "next"){
      Serial.println("going to Strike");
      EXEC(Strike);
      Hold0.Finish();
    }
  }
}

State S1(){
  Serial.println("S1");
  Setpoint = 155;
  int temp = 150; //manual faking of temperature
  while (temp < Setpoint){
    temp++;
    Serial.print(Strike.Statetime());
    Serial.print(" setpoint= ");
    Serial.print(Setpoint);
    Serial.print(" temp= ");
    Serial.println(temp);
  }
  Serial.println("going to Hold1");
  Strike.Finish();
  EXEC(Hold1);
}

/*State H1h(){
  Serial.println("H1");
  //Hold1.Set(H1b);
}*/

State H1b(){
  Serial.println("h1b");
  while (Serial.available()>0) {
    String foo = Serial.readStringUntil('\n');
    if(foo == "next"){
      Serial.println("going to Mash");
      EXEC(Mash);
      Hold1.Finish();
    }
    else if(foo !="next"){
      Serial.println("HUH?");
    }
  }
}

State M1(){
  Serial.println("Mash");
}
 

The problem is that the sketch gets stuck at the entry to Hold1 - it won't accept any more input. I'm looking for "next" to come across the serial, but when I enter that in serial monitor, I get nothing. Here's the output that I do get:
Code:
hello (here I enter "next")
going to Strike
S1
0 setpoint= 155.00 temp= 151
1 setpoint= 155.00 temp= 152
16 setpoint= 155.00 temp= 153
49 setpoint= 155.00 temp= 154
81 setpoint= 155.00 temp= 155
going to Hold1 (here I enter "next" but nothing happens)

Any help would be appreciated. I'm new to the idea of state machines, but it seems like everything is flowing properly.... until it doesn't smiley-sad

thanks,
JR
Pages: [1] 2