Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 44
61  Using Arduino / Programming Questions / how to check a live time span for change on: October 31, 2013, 03:51:19 pm
I hardly know how to describe what I'm needing, and maybe there's some examples already, but I haven't found any.
This code kinda shows what I need to do.  I don't know how else to word it.  The commented out part tells what I need, but I'm at a loss.
 
Code:
boolean CheckPosNeg(int Val) {
  timeRange = 1000; //within this time range
  changeCount = 3; //number of changes to trigger flag
  //if Val has changed from NEG to POS more than {changeCount}
  //times in the past {timeRange} return TRUE
}
thanks!
62  Using Arduino / Motors, Mechanics, and Power / Re: Putting my Segbot into standby mode on: October 29, 2013, 02:22:04 pm
For motorVal, I meant motor_speed.

Yes, I've figured out that the two lines mentioned will be the result of which state the machine is in.
If in standby mode:
Code:
  motor_speed = map(pitch, -maxPitch, maxPitch, -standbySpeed, standbySpeed); //standby mode
And if it's in riding mode:
Code:
  motor_speed = map(pitch, -maxPitch, maxPitch, -maxSpeed, maxSpeed); // map the angle to the sabertooth controller range 1-64 

But the logic of keeping up with when the last time motor_speed went negative, if it does it more often than once per second.  This is what I need help with.
63  Using Arduino / Motors, Mechanics, and Power / Putting my Segbot into standby mode on: October 29, 2013, 11:47:40 am
project: Segbot; using a MPU-6050 IMU, Atmega328P-AU, and a SAbertooth 2x25 controller
It's working great!  However, when no one is on it, it will self balance okay in a perfect environment, but just a little bump will start it oscillating.  The motor speed maxes out at 100% at about 30 degrees tilt, which is just about perfect for riding.  With no load (person), and I set the motor speed to be 50% at 30 degrees, it sets by itself very nicely, and can not be made to oscillate.
So I need to detect when it is not being ridden, and change the motor mapping to standbyMapping, rather than RidingMapping.
What sounds like a workable solution is this: If the motorVal goes Negative (reverse) more than once a second, put it in StandbyMode.  Longer than 1 second since the last Negative value, go back to ridingMode.  It sounds easy, but I'm struggling with it.  It's more than just reading a negative value, but reading a "change to negative from positive".   Any help would be greatly appreciated.
See lines 11 & 12 of my motor code here.  I need to do one or the other, depending on standby mode or riding mode:
Code:
void update_motor(){  // Update the motors
  static unsigned long prevTime;
  int motor1, motor2;
  if (millis() - prevTime < 30) return; //only do this every 30 ms
  prevTime = millis(); //update the time stamp
  maxPitch = 1500; //value from the MPU-6050, this makes 30 degrees the max tilt for 100% speed
  maxSpeed = 64;
  standbySpeed = 32;
  if (pitch < -3000) crash(); //we probably crashed
  if (pitch > 3000) crash(); //we probably crashed
  motor_speed = map(pitch, -maxPitch, maxPitch, -standbySpeed, standbySpeed); //standby mode
  motor_speed = map(pitch, -maxPitch, maxPitch, -maxSpeed, maxSpeed); // map the angle to the sabertooth controller range 1-64 
  if (motor_speed > 64) motor_speed = 64; //that's the maximum speed

  if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.4); //scale it to change slightly at low numbers
  if (motor_speed < 0)  motor_speed = fscale( -64,-1, -64,-1,motor_speed, 2); //scale it to change slightly at low numbers
  motor1 = motor_speed + get_Steering();  //add steering bias to motor 1
  motor2 = motor_speed - get_Steering();  //add steering bias to motor 2
  // assign final motor output values
  motor1 = 65 + motor1;                //64 is neutral for motor 1
  motor2 = 192 + motor2;               //192 is neutral for motor 2
  motor1 = constrain(motor1, 1, 127);  //constrain the value to it's min/max
  motor2 = constrain(motor2, 128, 255);//constrain the value to it's min/max
  if (!debugMode) Segway.write(motor1); //Send motor 1 speed over serial
  delay(1);  //sabertooth can only receive commands at 2000/second
  if (!debugMode) Segway.write(motor2);  //Send motor 2 speed over serial
   if (!debugMode) {
      Serial.print("Pitch: ");
      Serial.print(pitch);
      Serial.print("\tMotorSpeed1: ");
      Serial.print(motor1);
      Serial.print("\tMotorSpeed2: ");
      Serial.println(motor2);
    }
}
64  Using Arduino / Programming Questions / Re: syntax for fscale code on: September 19, 2013, 07:54:37 pm
I think I got it: 
Code:
  if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
This doesn't fit the rules:
originalMin - the minimum value of the original range - this MUST be less than origninalMax
 originalMax - the maximum value of the original range - this MUST be greater than orginalMin
 
-1 isn't lower than -64
65  Using Arduino / Programming Questions / Re: syntax for fscale code on: September 19, 2013, 07:17:08 pm
-1 to -64 is the reverse speed...
66  Using Arduino / Programming Questions / syntax for fscale code on: September 19, 2013, 05:51:57 pm
In reference to this code that changes the curve or scale of numbers:
http://playground.arduino.cc/main/fscale

I have this code that give my the desired curve on a reading that is from 1 to 64, but I can't figure out how to get the same result for the values -1 to -64
Code:
  if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.5);

I thought this would do it, but all it gives me is zeros:
Code:
  if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
67  Using Arduino / Motors, Mechanics, and Power / Changing to an OLED on: July 08, 2013, 09:53:28 pm
Well, DC42, after getting my first version board back from the fab house, I discovered a few design mistakes, so I'm going to redo it.  I couldn't get the LCD to work, but I'm pretty sure it was something more to do with the LCD, rather than the schematic.  The LCD was this tiny one like the one pictured with a FCP connector, and I'd never used one like it before.  I've recently learned about these little OLED displays like adafruit sells, and want to switch to them on my next attempt at a board. (see link).  The OLED display uses very little current, so I'm guessing I can control it's power directly from a digital pin?
Quote
The power requirements depend a little on how much of the display is lit but on average the display uses about 20mA from the 3.3V supply
  Seems I read somewhere else that with all the pixels lit one used 50ma.  I'll just be using it for text, not graphics, so I won't have anywhere near all the pixels used.
It may be a little while before I resume this project, I'll be gone a few weeks, but here a picture of the schematic I'm guessing will work for powering up/down the OLED from the Atmega328's D4 pin.  Would the I2C pull-ups get connected to D4 as well?
http://learn.adafruit.com/monochrome-oled-breakouts/overview

Thanks for taking a look at this.
68  Using Arduino / General Electronics / Re: Washable crystal on: July 08, 2013, 01:50:12 pm
Thanks for all the feedback. I like the denatured ethanol idea and might give it a try. With a good drying from an old hair dryer.
69  Using Arduino / General Electronics / Re: Washable crystal on: July 07, 2013, 11:04:41 pm
I use hot water and soap. I used to use household alcohol, but it seemed to 'dull' the board --take away the nice shine. I use a flux that is 'water soluable'. I could see parts like the atmega328P-AU, 0803 CAps & Resistors, being unaffected by dipping in hot water but it seemed to me the crystal package would seep liquid into it?  Maybe not??
De-ionized water- will that clean the flux off good?  No soap?  Is that the same as distilled water or is it hard to come by?
70  Using Arduino / General Electronics / Washable crystal on: July 07, 2013, 07:50:16 pm
Is there such a thing as a washable crystal?  I like to give my board a good hot soapy bath after soldering all the washable components on, and would like to use more components that are washable. I've always assumed SMD crystals are not washable. I use this one:
http://www.digikey.com/product-detail/en/ECS-160-20-3X-TR/XC1776CT-ND/2676640
The data sheet says nothing about washable. Anyone know much about crystals and/or of a washable type?
71  Using Arduino / General Electronics / Re: adding LED's to Rx/Tx lines of 328 TFQP SMD to show uploading action on: July 06, 2013, 09:47:37 am
But then when I unplug the FTDI cable, the pins will be low, and the LED's will be on all the time won't they?
72  Using Arduino / Programming Questions / Re: Millis() rover over handling on: July 06, 2013, 09:28:07 am
Oh, I see what you're saying. 
If DoorError() is called, it shuts the whole system down ending with an endless while{} statement, waiting for the user to fix the problem.
73  Using Arduino / Programming Questions / Re: Millis() rover over handling on: July 06, 2013, 09:11:50 am
Code:
There is no problem with rollover, however I can see DoorError being called every 10 mS.
why?  I don't see it.
74  Using Arduino / General Electronics / Re: adding LED's to Rx/Tx lines of 328 TFQP SMD to show uploading action on: July 06, 2013, 09:08:13 am
I think the LEDs referred to are connected to the uC Rx & x lines as added indicaters, not pins 22 & 23 of the FTDI chip.
Correct.
I tested this FTDI cable I use from Sparkfun, and both the Rx/Tx lines are high when I have it plugged in my USB port.
So I may need to just skip the indicator LEDs.  They were just to give a visual on loading sketches.
75  Using Arduino / General Electronics / Re: adding LED's to Rx/Tx lines of 328 TFQP SMD to show uploading action on: July 05, 2013, 11:30:48 pm
I went with the 5K resistors.  Got my first board back for the fab shop with this setup, but they don't work right.  When I plug my FTDI cable into my board, the LEDs are lit up all the time.  I can see them flashing when I load a sketch.  Are the Rx/Tx lines of the FTDI cable normally high?
Here's the schematic of the LED's I added to the Rx/Tx lines.
Pages: 1 ... 3 4 [5] 6 7 ... 44