Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Servo Radnomizer with easing issues on: July 25, 2010, 10:39:15 am
What I want to servo to do is move from random position to random position with easing leading to the stop point. Then I want a new value and the servo to chase that value, etc.

  I got random numbers for the servo to work, but the movement was too fast. It was borderline violent. So I tried some delay, but it just moved fast, then delay, fast, delay, etc. It didn't look right. So I thought a random number generator would be a good option. I also considered an array of numbers to draw from for the positions, but I haven't gone down that road yet.

  What the program currently does is intialize and returns a constant stream of zeros for the values. I have tried some constants instead of random numbers, and got the same result. So I am not sure where the problem is yet.

  Again, thanks for the input. I really appreciate your time. I will implement the things you said and see what I come up with.

  Peace,
  Gumby
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Servo Radnomizer with easing issues on: July 25, 2010, 08:41:31 am
Thank you for that input. I removed the print statements for ease of viewing on the forum. (They are all there).

  First off, is there a way to get the current poition, and not the last position? I'm also confused why reading it's current position is not necessary. How do I do the math without knowing the current value for the angle of the servo?

  I tried a few different types of variables and thought even if some were integers, this may be a good way to default to the heavy math and after the script was working prune the values I didn't need.

  I have been thinking about the values for ran, and I know it is a pseudo-random generator, so I was wondering if there was a way to read say the system clock to generate a random seed for the number so it was more of a true "random" number.

  Like I said I would have been happy to see it get through a single iteration where the the program eased into position, but no luck yet. I will look at the suggestions you made and see if that was the issue.

  Lastly, I know about the oddness of having more than one call for the value of the position for the servo, but those were more of my attempts to troubleshoot the program, I thought maybe the value wasn't being passed from one set of curly braces to the next.

  Sigh... I hope this starts to make sense soon...

  Thanks for the input. I appreciate it. (More to follow)

  Peace,
  Gumby
3  Forum 2005-2010 (read only) / Syntax & Programs / Servo Radnomizer with easing issues on: July 25, 2010, 07:53:09 am
Hello everyone.

  I am very new to programming and I am doing my best here, so forgive me if this is sub-standard work. Here is my issue. I am trying to set a random value for a servo, then use an ease function to chase the random value with the servo position. When the servo position value is reached, set a new random position, and lather, rinse, repeat. I have tried about four thousand variations of this and keep getting the serial port reporting lots of zeros. Does anyone see what I am doing wrong? I suspect that I will need to eventually define a zone as being close enough to the number to be seen as that number so the division doesn't go on infinitely, but I would be happy right now seeing some of the values change as they get closer to the servo position asked for by the random number.

  Here is the code.
Code:
#include <Servo.h>


Servo servo1;
float spd = 2;
float ran = random(0,180);
float ease;
float current;
float noopos;


void setup()
{
servo1.attach(2);
Serial.begin(9600);
}

void loop()
{
if (servo1.read() != ran)
{
  ease=(ran/spd);
  current = servo1.read();
  noopos = (ease - current);
  servo1.write(noopos);
  delay(10);
}

else
{
    ran = random(0,180);
}
}

  Hopefully someone will have some insight. I tried using the delay function to reduce the speed of the servo, but it was choppy and ugly, so I am hoping this is a better way to get the results I am looking for. Thanks in advance for any information/insight on this problem.

  Peace,

  Gumby
4  Forum 2005-2010 (read only) / Troubleshooting / Servo Randomizer with ease problems... on: July 24, 2010, 12:40:43 pm
Hello everyone.

  I am very new to programming and I am doing my best here, so forgive me if this is sub-standard work. Here is my issue. I am trying to set a random value for a servo, then use an ease function to chase the random value with the servo position. When the servo position value is reached, set a new random position, and lather, rinse, repeat. I have tried about four thousand variations of this and keep getting the serial port reporting lots of zeros. Does anyone see what I am doing wrong? I suspect that I will need to eventually define a zone as being close enough to the number to be seen as that number so the division doesn't go on infinitely, but I would be happy right now seeing some of the values change as they get closer to the servo position asked for by the random number.

  Here is the code.
Code:
#include <Servo.h>


Servo servo1;
float spd = 2;
float ran = random(0,180);
float ease;
float current;
float noopos;


void setup()
{
servo1.attach(2);
Serial.begin(9600);
}

void loop()
{
if (servo1.read() != ran)
{
  ease=(ran/spd);
  current = servo1.read();
  noopos = (ease - current);
  servo1.write(noopos);
  delay(10);
}

else
{
    ran = random(0,180);
}
}

  Hopefully someone will have some insight. I tried using the delay function to reduce the speed of the servo, but it was choppy and ugly, so I am hoping this is a better way to get the results I am looking for. Thanks in advance for any information/insight on this problem.

  Peace,

  Gumby
Pages: [1]