Show Posts
Pages: 1 ... 42 43 [44] 45 46 ... 57
646  Using Arduino / Networking, Protocols, and Devices / Re: Thermal printer isn't Printing Images on: February 12, 2013, 05:37:58 am
I *think* the first mode is just defining a space in buffer for the image, not the actual image. 
647  Using Arduino / Networking, Protocols, and Devices / Re: Thermal printer isn't Printing Images on: February 12, 2013, 05:35:11 am
Your code looks like it should work, except this part when it starts the GS mode.

Thermal.write(29);
  Thermal.write(47);
  Thermal.write(1);
  Thermal.println("Image ...");

"This command is ignored if a downloaded bit image has not been defined."

"GS * n1 n2 d1…dk     Define downloaded bit image"

I think you may be using different kinds of modes. There are a few different ones. The GS /n mode requires you to have defined the image, but that is not what you have done yet.

"GS v 0 p wL wH hL hH Print raster bit image" I think this is the one you want to print a raw Bitmap.

I am not positive that I am right. The datasheet is a bit confusing and have several modes. Unfortunately since I cannot experiment with it, you must. smiley
648  Using Arduino / Networking, Protocols, and Devices / Re: Thermal printer isn't Printing Images on: February 12, 2013, 04:56:54 am
I will need to look over the library some more. I haven't had the time, unfortunately. The datasheet is not really great at explaining the various modes, etc... but I am not sure that you are accessing the modes properly.

BTW, you can change the adafruit library directly. It has the main structure that you want, you just have to modify the parts that are different.
649  Using Arduino / Networking, Protocols, and Devices / Re: Thermal printer isn't Printing Images on: February 12, 2013, 04:48:19 am
What he is saying is "==" is not the same as "=". The double equal signs means "is it equal to?" and the single equal signs means it IS equal to. So, if you only use a single =, i will always equal 200. It will not count.
650  Using Arduino / Project Guidance / Re: Can't write multiple pins HIGH why? on: February 11, 2013, 08:39:34 pm
Ahhh... lol. Yeah, you can't do that. Just put each one on it's own line without any delays in between. It will happen so fast, that it will appear to all turn on at once. The human eye couldn't capture it.

Also, if they are all using the 8 bits (you have 8 letters) of one port, you could just do this:

PORTn = 0xFF and that would turn on all bits at once. n = whatever port they are on. PORTD is pins 0-7. But you will lose your serial port. If you aren't using it, no big deal. It's the only full 8-bit port available.

However, my first suggestion would happen so fast, the results will look the same.
651  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 08:37:40 pm
Thanks to both of you. I will take another crack at it tomorrow and read that article.

With the little bit of understanding I have, I was trying high values for P thinking it would do exactly as you describe compared to D. Usually a ratio of 1/4 to 1/8th. Even at 255P, it still oscillated like crazy.

Am I right in thinking this way:

P is the amount of force applied to the motor in proportion to the error
I is the a function of time (not 100% sure beyond that)
D is rate change/time which helps determine when it is getting closer to closing the position and allows me to stop

If I can truly wrap my head around these concepts, I know I can come up with a custom PID that uses these components and gives me exactly what I want. It doesn't help that the majority of articles I am reading have to do with chemical processes and don't seem analogous to what I am trying to do. Also, it doesn't seem that I have true linear control over the motors. I am really surprised... this is something I figured would be so common that I could find all kinds of examples and information.

Trust me, I have been reading hundreds and hundreds of pages. I am an electrical engineer so the math is not above my head. It just seems like they are all explaining it to someone that already knows it trying to be too academic.

Arrrgh!!
652  Using Arduino / Project Guidance / Re: Can't write multiple pins HIGH why? on: February 11, 2013, 08:08:55 pm
Unless there is a typo I am missing, your code should run fine. I agree though, your delays are really long. lol.

Did you really intend it to take 30 seconds to cycle through one loop?
653  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 08:02:29 pm
I just think I am trying too hard to make something fit that isn't going to fit and isn't what I really need in the first place.
654  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 07:58:53 pm
I can't really visualise the mechanical side of your setup.

What is it you're moving?
What range of angles are you moving through and how precisely are you trying to position it?

Taking account of whatever gearing you have, how precisely are you trying to position it in terms of motor revolutions?

Is there any significant mechanical inertia or friction in the system?

Once it's achieved the target position, does it need any sustained output from the motor to stay in position?

I attached a picture of the two different styles of motors that represent what I am working with. Currently I am experimenting with the smaller one which uses a potentiometer for position feedback. The pot is a continuous turn type. I have it connected to the A0 pin of the arduino and I am scaling that down to 0-255 for position.

The motor is being controlled through it's original H-Bridge, which is a 6 transistor H-Bridge (Mark Tilden Style). It has two inputs, FORWARD and REVERSE. A high on either will move it in that direction. The supply for the motors are 9v. There are resistors limiting the current that can go through the H-bridges.


As for precision, I would be happy with just 32 positions, in multiples of 8. That would match the original application. It does not have to land exactly on the setpoint, though future applications of the same code may need more precision. We aren't doing CNC style stuff, just moving facial parts.

I do not know the gear ratio. I'm sure it will be different for the different motors. Range of motion for this one appears to be around 90 degrees before the pot goes out of limit.

I don't know if I would consider it significant. I think the H-Bridge is really the limitation here.

No, it does not need to hold it's position once it reaches it. Not at all. The mechanisms have enough leverage that they do not move once they are in position. Two of the motors do have spring returns, so moving those would move them from a center position and they would spring back once you remove power. They were designed that way.

The main problem seems to be that the PWM cannot accurately control the H-Bridges. I really don't need "PWM" proper. Just something that will slow the motors down as it reaches position so it can stop semi-accurately.

In early experiments I used proportional control. I used delays to move the move the motors, paused, checked position and compared, and continued to move if they didn't match. I actually had decent results with that, but the delays are a problem and the motors had a stepper feel to them. It was not smooth as you can imagine.

What I really think I need is a control system that determines the magnitude and sign of the error, determines how long to just run the motor before it checks it again, and starts throttling it down as it reaches the position. But not so much that the motor just whines instead of going the last little bit. And something that when it reaches zero (or a +- range of error) that it simply stops and moves on.

In real application, all of the motors will be refreshed about once every 20ms, so if they didn't make it to their position yet, they will just continue on the next refresh or if a new position was given in that time, it will just move towards that. I don't need something constantly adjusting the motors to hold them. That is why PID in it's normal form doesn't seem like what I need. But I cannot find anything about other types of control schemes at all.

Some motors may take up to 800ms to complete a movement from one extreme to the other. The majority will be very small movements that only take a few ms to complete.

I attached a picture of what I am trying to control.
655  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 06:42:16 pm
I just don't think this is going to work unless I figure out to control it exactly the same way it was controlled in the original.
656  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 06:41:12 pm
This code mostly works. It is modified from the DIY-Servo code (unfortunately I forget the author):

Quote
int PWMPin = 5;
int PWMPin2 = 6;
int potPin = A0;

float KP = 2;             // PID: position multiplier (gain) was 2 Adjust to get more aggressive or conservative control
float KI = 0;              // PID: Intergral multiplier (gain) was .05 set about the same as your manual response time Seconds/4
float KD = 1;              // PID: Derivative multiplier (gain) http://www.expertune.com/tutor.html

int lastError = 0;
int sumError = 0;

//int iMax = 1;
//int iMin = 0;

int setPos = 0;
int dutyMax = 254;

void setup() {   

  pinMode(PWMPin, OUTPUT);
  pinMode(PWMPin2, OUTPUT);
  setPwmFrequency(PWMPin, 255);
  Serial.begin(9600);

}

void loop() {
 
  int val = analogRead(potPin);
  val = map(val,0,1023,0,255);

  checkInput();
 
  int error = val - setPos;

  int ms = KP * error + KD * (error - lastError) + KI * (sumError);


  lastError = error;
  sumError += error;

//  if(sumError > iMax){
//    sumError = iMax;
//  }
//  else if(sumError < iMin){
//    sumError = iMin;
//  }


  // BACKWARD DIRECTION
  if(ms > 0){                                     
    int motorSpeed = ms;
    if(motorSpeed > dutyMax){                         
      motorSpeed = dutyMax;
    }
    PWMPin = 5;                                 
    PWMPin2 = 6;

    analogWrite(PWMPin2, 0);
    analogWrite(PWMPin, motorSpeed);
  }


  // FORWARD DIRECTION
  if(ms < 0){                                     
    ms = -1 * ms;
    int motorSpeed = ms;
    if(motorSpeed > dutyMax){                   
      motorSpeed = dutyMax;
    }

    PWMPin = 6;                                   
    PWMPin2 = 5;

    analogWrite(PWMPin2, 0);
    analogWrite(PWMPin, motorSpeed);
  }

}

void checkInput(){
  if(Serial.available()){
    byte ch = Serial.read();

    if (ch == '+'){
      setPos = setPos+5;
    }
    if (ch == '-'){
      setPos = setPos-5;
    }
    if(ch == 's'){
      analogWrite(PWMPin,0);

    }

  }

  setPos=constrain(setPos,0,255);

}


void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if(pin == 5 || pin == 6 || pin == 9 || pin == 10) { // Timer0 or Timer1
    switch(divisor) {
    case 1:
      mode = 0x01;
      break;
    case 8:
      mode = 0x02;
      break;
    case 64:
      mode = 0x03;
      break;
    case 256:
      mode = 0x04;
      break;
    case 1024:
      mode = 0x05;
      break;
    default:
      return;
    }
  }
  else if(pin == 3 || pin == 11) {
    switch(divisor) {
    case 1:
      mode = 0x01;
      break;
    case 8:
      mode = 0x02;
      break;
    case 32:
      mode = 0x03;
      break;
    case 64:
      mode = 0x04;
      break;
    case 128:
      mode = 0x05;
      break;
    case 256:
      mode = 0x06;
      break;
    case 1024:
      mode = 0x7;
      break;
    default:
      return;
    }
    TCCR2B = TCCR2B & 0b11111000 | mode; // Timer2
  }
}



But it makes a ton of noise, even at idle. And the difference between setpos and currpos needs to be very large before the motor will even move. However, it will fairly accurately move to that position and "stop." Well, I say stop, but more like it sits there and whines. It does undershoot a little, but I think that is because it is setting the pwm so low that the motor stops turning and can't make it that last bit.
657  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 04:46:54 pm
I've now got it "sorta" working. I switched over to the lower frequency PWM pins (10 and 11), removed the integral (caused WILD oscillations) and I have been trying to follow along with various tutorials on PID tuning and it still oscillates. I've got it oscillating less... but still crazy amounts.

The problem, I think is that the potentiometer changes value very quickly. I am dealing with a very small range of motion here. Just kicking the motor a little can way overshoot. I am so close to giving up on PD control (remember, I zeroed the Integral).

Raising the integral even to 1 caused the motor to go absolutely nuts. A P of 2 and a D of 1 seems to be working the best.

This is what I think I understand:

P = How much force to move towards zero position
D = Pre-act (predicting what the output will be over time)

I am just not positive that this is right for me. What I am getting out of right now is no different than my simple If currpos > pos, then move left etc... routine I was using. In fact, even that actually got it right ocassionally!
658  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 02:34:21 pm
I could add an offset to the error output to scale it up to a minimum, but not sure how I will deal with zero then. I am going to play around with gains some more tonight. I read some more today and I *think* that playing with the integral gains might help. However, the fact that it is not linear (meaning once it is moving, it can take a lower PWM than if it is still) is going to pose some issues, I think.

I think the original application got around this by using a slower PWM frequency. 1ms (12.5% duty cycle) is the minimum pulse width used. At 9V, that would mean the motor would see an average voltage of 1.125V. I doubt the motors really move at that low of a voltage... but it only uses that voltage as it approaches zero error, so it was moving to being with. From the signals I looked at, it seems to always start out at full speed and only adjusts as it is reaching the setpoint.

A 12.5% duty cycle with the analogWrite values is 31. The motor does not move at an analogWrite value of 31. I imagine that has to do with the responsiveness of the H-Bridge. Using the default PWM frequency (490hz on pins 3,9,10,11), the motor output is high only for 250us at 12.5%. At 50% duty cycle, I get 1ms which is the lowest the original PWM uses. I assume that this is why it begins to turn on around that point. The highest it would ever be is 2ms for 100% duty cycle. The original application goes up to 8ms.


You can change the PWM frequency, but it will affect the timers used by other functions. BTW, pins 5 and 6 are twice as fast at 980hz.

In the end, I think I am going to just have to come up with a software PWM method.
659  Using Arduino / Project Guidance / Re: Controlling an animatronics bust on: February 11, 2013, 10:18:36 am
While waiting for my shift registers to arrive, I have started working on getting just one motor working reliably using the PID library and PWM. What I have learned is that the H-Bridges just do not respond well to PWM at all. They will not move at all until you reach a PWM of around 60. But this is not linear. Once they are moving, you can decrease the PWM down to about 38 before they stop running again. The speed changes very rapidly above 60, but then very very slowly towards 255.

I think this is why I cannot seem to get the PID library to work. It cannot control the speed as it approaches zero error. However, it seems to just quit trying and leaves the motor position far off the mark. (the motors will whine if a PWM above 0 is commanded to it) The motors do not whine. They act as if they have reached their position.

Unfortunately, I think I am going to have to devise a completely custom system. I will continue to focus on one motor to develop a solution that works before worrying about integrating all 10 motors at the same time.
660  Using Arduino / Project Guidance / Re: Toilettes door wireless indicators on: February 11, 2013, 10:08:13 am
Well, you are in luck. It looks like these use exactly the encoder that I was recommending (PT-2262).

You do not need to modify anything in the sensors. There is no code in them.

What you need is an Arduino running the RC-Switch library with a 315 or 433MHz receiver module attached to it. Those door sensors have a jumper selecting the device address, so you would set each one as unique.

Using the Arduino and RCSwitch library, you create a base station that listens for the sensors and updates the status when something changes.

For reference look for and read the datasheet for the PT2262 and search the forum about the RC-Switch library.

What you do with the received singals after they reach the Arduino is entirely up to you and how complicated you want to make it.

You only need these door sensors, not the base station. Your Arduino becomes the base station.
Pages: 1 ... 42 43 [44] 45 46 ... 57