:.
:0
Couldnt delete the forum so i had to do this, IMMENCE Gratitude for everyone who replied, apprently I wasnt supposed to post deatils of my project online, school rules :-\ , Sorry and Thank You again!!!
:.
:0
Couldnt delete the forum so i had to do this, IMMENCE Gratitude for everyone who replied, apprently I wasnt supposed to post deatils of my project online, school rules :-\ , Sorry and Thank You again!!!
motorSpeed = map(motorSpeed, -255, 255, 0, 255);
if (motorSpeed >= 0)
...
}
else
{
How is this supposed to evaluate false if you map all your values to be zero or greater? get rid of the map() and it should work.
Ok, there's some stuff I didn't catch at first glance.//the driver is weird as -255 turns the motor slowly and -1 turns it at fullspeed
That's because analogWrite takes an unsigned 8 bit integer and you're shoving a negative number into it. Change the analogWrite in these parts
if(motorSpeed >= 0)
{
...
}
else
{
...
analogWrite(pwmPin, motorSpeed);
to analogWrite(pwmPin, abs(motorSpeed));
Your main problem is likely caused by this while statement while (encoderTicks >=500 && timer > 3000)
Once your motor moves 12 ticks back from desiredPosition1 (512) , this loop will exit. Try replacing that while statement with this
while (timer < 3000){}//delay 3s
while (encoderTicks > desiredPosition2)
{
...
Also, it won't hurt to constrain motorSpeed for the second movement in the same way you constrained it for the first movement. Plop it in where the old map() used to be.
Appreciate the feedback, but using
while (timer < 3000){}//delay 3s
Would not allow the control system to run as it would delay 3 second regrdless encoderTicks reaching desiredposition1
I too think, that section of code is the culprit. How do you think I can delay the system without affecting the PID?
yeah, your loop is set up strangely. Just put each movement in its own while(1) loop and break out of it whem the motor is at the right position (encoderTicks == desiredPosition). Ideally you would make some sort of moveMotor() function that takes the desired position as an argument.
I really dont know how to use the break fucntion, its really confusing. And I didnt get you, while(1) where?
If the motor only rotates 45 deg., then maybe just use a pot to determine the position as a servo does.
Using an encoder is a must, sadly!
eyasfazul:
Using an encoder is a must, sadly!
Just looking at the motor gizmo, how are you going to establish a zero start position and calibrate the encoder to the start position? Does the motor setup have a rotation hard stop?