Show Posts
Pages: [1] 2 3
1  Using Arduino / Project Guidance / Re: Cheap optics w laser on: November 25, 2012, 09:23:44 am
Is your laser on top of the camera(or atleast behind the field of view) while the actual red dot is being projected out into the fov of the camera? Also, is just the laser moving back and forth across the fov, or are the camera and the laser both moving where the dot stays in the middle of the view?

if your looking for whether or not the dot was seen compared to one where it isn't, wouldn't an image from the dark and no dot just be 0, while a dot in the image would be greater than 0? Depends on how many other light sources it catches I guess. There should at least be a check-sum of sort that would change, instead of looking through the entire image, right? Just an Idea, I don't know how exactly how an image is put together in jpeg format.

And just as an expirement, I created two images, one just black, and one with a red dot. Interestingly the one with out the red dot is 6.98kb, while the one with the dot is 7.21kb. So maybe the size difference could work as well? Maybe just check each new frame with the last frame and see if the size has changed a certain amount since you last checked it.

Just a couple ideas. Have a good one, Good luck!
2  Using Arduino / Project Guidance / Re: Is this project possible with Arduino? on: November 25, 2012, 12:12:42 am
Check these out:
http://www.imagesco.com/sensors/force-sensors.html

I was a little curious about force sensors myself today. These guys have different sizes up to 100lbs (44 newtons?) and they are apparently read as a resistor with a range between 5M and 5k. Soooo, divide the max rating by the difference in impedance, and you get a resolution of around 0.0000088 newtons per ohm. But since the Arduino has a 10-12 bit adc, the resolution does get brought down. If the change is 4995000 ohms, then it would take a change of 4877 ohms to register on an Uno. So you'd be looking at 0.0429 newtons per byte, which is kinda close... but the smaller ones may get better resolution, and a chip with a 12 bit adc can get you up to 0.0107. Just a couple ideas! Good Luck!
3  Using Arduino / Project Guidance / Re: Using pwm instead of high/low in Stepper library. on: November 24, 2012, 08:37:12 pm
Turns out it was a little better than just a good idea (Thanks by the way  smiley-grin), it works great! It wasn't very hard either, I added a condition for when there is no step to basically step in place, but in the process check the delay and switch over to pwm if time has gone over.

The delay to switch over to pwm is twice the delay to wait for the next step which is determined by setSpeed. It seems to work better this way, rather than waiting only as long as the original step delay. Since setSpeed determines the delay, the higher the rpm results in less of a delay. My initial experiments show that 60rpm works fine, and that 50%(127) modulation is pretty cool, while 25%(63) still operates but may stall at times.

I do get a hum from the motor, but it stayed nice and cool  smiley-cool

I attached what I've done in a rar file if any one may be so curious. Just drop it in your libraries folder and load the example.

Thanks again!
4  Using Arduino / Project Guidance / Re: Using pwm instead of high/low in Stepper library. on: November 24, 2012, 02:15:37 pm
That makes sense. Basically I'd have to tune it if I went with PWM. I'm thinking of using both now. The stepper library has a delay based off the setSpeed variable. I'm thinking if I can get a hold of it I can let it step with a digitalWrite, then after the delay, switch to an analogWrite just for holding. This way it can make a solid rotation, but pulse when it needs to sit still. I'm just wondering what kind of noise I'd get from it pulsing like that.
5  Using Arduino / Project Guidance / Re: Using pwm instead of high/low in Stepper library. on: November 24, 2012, 01:03:00 pm
You can use PWM to make a stepper go faster or run cooler at a higher voltage,
but it is not as simple as a chopper drive chip.

Heheh, well the STK675-050 ~ $20/pc, where the Atmega8 is ~ $1/pc. I don't know of any other chopper chips besides the STK, but I had tried the Stepgenie ~ $12/pc, which are not choppers either, and those ran hot too. Why is a chopper driver simpler? Just because you don't have to program it? Thanks!
6  Using Arduino / Project Guidance / Using pwm instead of high/low in Stepper library. on: November 24, 2012, 11:20:11 am
The x and Y motors I'm using to run my CNC are chopper motors, I believe. They came out of a set up where they were each driven by an stk675-050, and possibly driven with 24v. There isn't a voltage marking, only a 0.8, and a 1.8deg. The rest are numbers that I haven't quite found the answer for. The 0.8 is the impedance, which I have verified, and  the 1.8deg is the degree per step. The "TYPE" is "23KM-K224-P2", the "No" is "T 202-01", and the "DWG NO" is "AXC501S7C", all by Minebea Co., LTD, and made in Thailand. All three of the motors very slightly from one another, but eh impedance and step are the same.

Since their impedance is only 0.8 ohms, which at 5 volts is 6.25 amps. So when the motor is just sitting in one place long enough, two coils are going to dissipate a constant 31.25 watts. This is apparently enough to get them pretty hot after just running through the first example that loads in LinuxCNC.

So the main question is, will the pwm from the arduino be a good frequency that won't bother operation at say 50%-75% pulse width? Instead of running on pins 2, 3, 4, 5, use pwm pins 5, 6, 9, and 10, and set the library to analogWrite instead of digitalWrite. Or should I look into a lower supply voltage for these motors?
7  Using Arduino / Project Guidance / Re: A simple approach to a stepper controller, which got a little complicated. on: November 21, 2012, 02:36:30 pm
Well, I'm just going to use three different microcontrollers for now. I messed with the sestSpeed and was able to keep the loop between 28 and 124 microseconds. They were however still glitchy. I'm not sure why the code can only run one motor, but for now I have come up with several different ways to run one motor on one controller very well ha ha. I'm off to buy another bread board, Thanks for the help. If you think of anything, let me know.
8  Using Arduino / Project Guidance / Re: A simple approach to a stepper controller, which got a little complicated. on: November 21, 2012, 11:00:30 am
0.5ms on, 0.5ms off. I can set either any where from 1-500000 nano seconds. The default is 5000ns. I'm running LinuxCNC if that helps. Are you thinking maybe a shorter pulse width? Using setSpeed does effect the delay inside of the library... So I'm going to play with that as well today.

I changed up the code a bit last night, trying to simplify it with arithmetic instead of conditional statements. Buut still no dice. I still get the same exact results. Is this easier on the controller than the nested conditions?


Code:
//Make sure this is in your library
//It probably is, but this program won't run without it.
#include <Stepper.h>

//Stepper pin setup
Stepper stX(200, 2,3,4,5);
Stepper stY(200, 6,7,8,9);

//input pins
const int stXstppin = A0;
const int stXdirpin = A1;

const int stYstppin = A2;
const int stYdirpin = A3;


//pin state variables
int stXstate = 0;
int stXLstate = 0;
int stXdirstate = 0;
int stXstep = 0;

int stYstate = 0;
int stYLstate = 0;
int stYdirstate = 0;
int stYstep = 0;


//--------------------------------------

void setup() {
  //Set up input pins.
  pinMode(stXstppin, INPUT);
  pinMode(stXdirpin, INPUT);
  pinMode(stYstppin, INPUT);
  pinMode(stYdirpin, INPUT);
  stX.setSpeed (200);
  stY.setSpeed (200);
}

//--------------------------------------

void loop() {

  stXstate = digitalRead(stXstppin);
  stXdirstate = digitalRead(stXdirpin);
  stYstate = digitalRead(stYstppin);
  stYdirstate = digitalRead(stYdirpin);

//      0(0-(0*2)) = 0
//      0(0-(1*2)) = 0
//      1(1-(0*2)) = 1
//      1(1-(1*2)) = -1

  if (stXstate > stXLstate){
      stXstep = stXstate * (stXstate - (stXdirstate * 2));
  }
  stX.step(stXstep);
  stXstep = 0;
 
  if (stYstate > stYLstate){
      stYstep = stYstate * (stYstate - (stYdirstate * 2));
  }
  stY.step(stYstep);
  stYstep = 0;

  stXLstate = stXstate;
  stYLstate = stYstate;

}
9  Using Arduino / Project Guidance / Re: A simple approach to a stepper controller, which got a little complicated. on: November 20, 2012, 10:49:10 pm
That's still only allowing 1ms for the motor to complete a step. If you can't get your link to run any slower than that then I'd say it was time to take the link out of the equation and just run a hard-coded sequence of both motors so you can establish whether the problem is reading your interface, or moving the motors on command.

Well I thought about that, but that would mean that the stepper library is super heavy. 4 conditions, then a function call per loop doesn't sound like a lot as far as my code goes. Also only running one motor has proven to work from the lowest timing up to the default 8khz. So doubling the number of motors doesn't seem like it should reduce my time by an 1/8.

I also get the same exact result without the switch case:
Code:
//Make sure this is in your library
//It probably is, but this program won't run without it.
#include <Stepper.h>

//Stepper pin setup
Stepper stX(200, 2,3,4,5);
Stepper stY(200, 6,7,8,9);

//input pins
int stXstppin = A0;
int stXdirpin = A1;

int stYstppin = A2;
int stYdirpin = A3;


//pin state variables
int stXstate = 0;
int stXlstate = 0;
int stXdirstate = 0;
boolean stXstp = false;

int stYstate = 0;
int stYlstate = 0;
int stYdirstate = 0;
boolean stYstp = false;

//--------------------------------------

void setup() {
  //Set up input pins.
  pinMode(stXstppin, INPUT);
  pinMode(stXdirpin, INPUT);
  pinMode(stYstppin, INPUT);
  pinMode(stYdirpin, INPUT);
  stX.setSpeed(150);
  stY.setSpeed(150);

}

//--------------------------------------

void loop() {

  //check for state of stepper 1 step pin and set wether or not to step
  //steps on rising edge
    stXstate = digitalRead(stXstppin);
    if (stXstate != stXlstate){
      if (stXstate == HIGH){
        stXdirstate = digitalRead(stXdirpin);
        if(stXdirstate == HIGH) {
          stX.step(-1); 
        }
        else{
          stX.step(1); 
        }
      }
    }
    stXlstate = stXstate;

    stYstate = digitalRead(stYstppin);
    if (stYstate != stYlstate){
      if (stYstate == HIGH){
        stYdirstate = digitalRead(stYdirpin);
        if(stYdirstate == HIGH) {
          stY.step(-1); 
        }
        else{
          stY.step(1); 
        }
      }
    }
    stYlstate = stYstate;
}
10  Using Arduino / Project Guidance / Re: A simple approach to a stepper controller, which got a little complicated. on: November 20, 2012, 10:00:34 pm
//Make sure this is in your library
//It probably is, but this program won't run without it.
#include <Stepper.h>

Code:
//Stepper pin setup
Stepper stX(200, 2,3,4,5);
Stepper stY(200, 6,7,8,9);

//--------------------------------------

void setup() {

  stX.setSpeed(100);
  stY.setSpeed(100);

}
void loop() {
  
  stX.step(100);
  stY.step(100);
  delay(100);
  stX.step(-100);
  stY.step(-100);
  delay(100);  
  
}
This works just fine, they each take a turn moving 100 steps in one direction wait, then take turns going back 100 steps. No problems.

Code:
//Make sure this is in your library
//It probably is, but this program won't run without it.
#include <Stepper.h>

//Stepper pin setup
Stepper stX(200, 2,3,4,5);
Stepper stY(200, 6,7,8,9);

//--------------------------------------

void setup() {

  stX.setSpeed(100);
  stY.setSpeed(100);

}
void loop() {
  for (int i = 0; i < 100; i++){
  stX.step(1);
  stY.step(1);
  }
  delay(100);
  for (int i2 = 0; i2 < 100; i2++){
  stX.step(-1);
  stY.step(-1);
  }
  delay(100);  
  
}
This works just as well. Both motors run 100 steps in each direction at virtually the same time with no hangup.

Must be my code at this point ha ha.
11  Using Arduino / Project Guidance / Re: A simple approach to a stepper controller, which got a little complicated. on: November 20, 2012, 08:41:54 pm
Quote
Do both steppers behave the same i.e. if you move stX first then stY do you get the same behaviour as when you move stY first and then stX?
Exactly. After a reset, whichever motor I move first works fine until I step the other motor. After that, stepping one motor makes it rotate real hard and loud, like the timing is off, while the other motor jitters around back and fourth.

I Haven't had a go at hard coding the two motors in the same program yet. I was thinkng I'd hear that the Stepper Library doesn't do multiple motors ha ha. I'll work it out and see what happens.

The timing is set down as low as possible at 970hz. No change from 8Khz, I still get the same result.

Thanks!
12  Using Arduino / Project Guidance / A simple approach to a stepper controller, which got a little complicated. on: November 20, 2012, 12:21:29 pm
 Here's the story, I'm working on a cnc machine with simple circuitry and software. I'm at the home stretch really. It's built out of an old scanner(most of which is gone except the base of the body, and the 3 motors it had). The machine isn't quite finished but the motor driver is right at the edge of being done as a prototype. Basically the arduino takes input from the lpt port and moves the motor according to step and direction pulses. Currently the code works great for one motor. However, as soon as I step a second motor in the main loop, both motors will start glitching out when you step them. If I reset the Arduino, I can start with the second motor just fine. I can move it back forth, wait a second, then move it some more, but as soon as I step the first motor again, they both glitch out whenever I step one or the other. I'm using the stepper library that came with the arduino, simply because it is simple, and works astonishingly well with one motor. So I'm wondering then if the library is at fault for not being able to handle more than one stepper motor, or is it the micro-controller not being able to keep up. I do have three atmega8s that I can use, which are cheaper than some controllers I've seen, but I'm also wondering if there is a way to keep all three motors on one chip, since there are enough pins for both input and output, with out sacrificing the serial port for programming.

At any rate here is the code, any Ideas?
Code:
//Make sure this is in your library
//It probably is, but I'm just suggesting.
#include <Stepper.h>

//Stepper pin setup
Stepper stX(200, 2,3,4,5);
Stepper stY(200, 6,7,8,9);

//input pins
int stXstppin = A0;
int stXdirpin = A1;

int stYstppin = A2;
int stYdirpin = A3;


//pin state variables
int stXstate = 0;
int stXlstate = 0;
int stXdirstate = 0;
boolean stXstp = false;

int stYstate = 0;
int stYlstate = 0;
int stYdirstate = 0;
boolean stYstp = false;

// Switch case Variable
int stTurn = 1;

//--------------------------------------

void setup() {
  //Set up input pins.
  pinMode(stXstppin, INPUT);
  pinMode(stXdirpin, INPUT);
  pinMode(stYstppin, INPUT);
  pinMode(stYdirpin, INPUT);
  stX.setSpeed(150);
  stY.setSpeed(150);

}

//--------------------------------------

void loop() {
  // Switch between the x and y stepper every loop.

  switch (stTurn) {
  case 1:
  //check for state of stepper 1 step pin and set wether or not to step
  //steps on rising edge
    stXstate = digitalRead(stXstppin);
    if (stXstate != stXlstate){
      if (stXstate == HIGH){
        stXdirstate = digitalRead(stXdirpin);
        if(stXdirstate == HIGH) {
          stX.step(-1); 
        }
        else{
          stX.step(1); 
        }
      }
    }
    stXlstate = stXstate;
    //comment out the next line to just use the x stepper
    //uncomment so the loop switches between both, but this
    //will glitch it out.
  //  stTurn = 2;
    break;

  case 2:
    stYstate = digitalRead(stYstppin);
    if (stYstate != stYlstate){
      if (stYstate == HIGH){
        stYdirstate = digitalRead(stYdirpin);
        if(stYdirstate == HIGH) {
          stY.step(-1); 
        }
        else{
          stY.step(1); 
        }
      }
    }
    stYlstate = stYstate;
    stTurn = 1;
    break;
  }
}
13  Using Arduino / Programming Questions / Re: Attaching interrupt kills main loop on: October 08, 2012, 09:11:28 pm
Quote from: tuxduino
Leaving out-of-bound array indexes around is a recipe for disaster.

True, It's just a bit confusing once I changed it around. 2 is the libraries default though, so I'll just stick with that. I really have no excuse for my naming conventions ha ha, I'll work on it.

 
Quote from: ckiick
The reason you have to press a key to make progress in the main loop is that kbd.read is a blocking call: it will wait until there is data available from the keyboard.  The mouse works the same way, but there is always data available from the mouse.

In order for this to work the way you want, the keyboard read function must be modified to be non-blocking. 

That is where I'm at now. Seems the way to catch it should be through an interrupt, but the library isn't set up to handle it that way. I'm trying to get some more info on the actual patterns right now, I understand what the library does, and I think the trick is to have the clock on the interrupt, and listen for the clock to fall. Next pass the first bit of data, just wait for hi clock, then low clock. Once it's low take in data1, then wait for hi clock,and low clock again. Do this 7 more times for data2-8. The last thing to do is waste time on the last two clock cycles, report, reset and go back to listening for the interrupt again. Hopefully I'll figure it out, thanks guys!
14  Using Arduino / Programming Questions / Re: Attaching interrupt kills main loop on: October 03, 2012, 02:00:08 am
Well, I thought I had it going. I'm going to have to mess with the keyboard library in order to get this going though. Thanks for the help guys, at least I got the interrupt stuff down.

Quote
Can you point to the documentation for mouse.report()?
Sorry I don't remember where I got the library from. C is a funny language.
15  Using Arduino / Programming Questions / Re: Attaching interrupt kills main loop on: October 02, 2012, 05:28:19 pm

Quote
Index 2 is not valid. You have two elements, 0 and 1.

index 2 still comes up with the right numbers, but for good measure I tried a couple of things out.

First
Code:
int data[3];
  mouse.report(data);

...

  if (data[2] > 0 )
Works just as before after setting this up, as I expected.

So, just to check something
Code:
int data[2];
  mouse.report(data);

...

Serial.print(data[3]);
This did not throw an error at compile. It wouldn't show the right number, but it didn't crash. So I'm guessing this is just a difference between explicit and implicit declarations? I've left it with the int data[3]; though just to make sure. Regardless this hasn't solved the issue, and I had ditched turning the interrupts off and on. Thanks for the help.
Pages: [1] 2 3