Author |
Message |
heinst
Rookie
Joined: Tue Feb 26, 2013 12:54 am Posts: 5
|
 Encoder Help
I have this code below: What its supposed to do is, if it finds an object it opens the claw, goes towards it for two seconds, then closes the claw. What it does is, it opens the claw fine and goes towards it ok. When it closes the claw it acts like the encoder is set too high and lifts the robot up. I dont know why it does this, because the encoder targets are the same numbers, just that the motor A is reversed in one and not the other. Anyone have any ideas as to why this is occurring? Ill attach my full code. Maybe the problem stems from some other area of my code.
|
Tue Feb 26, 2013 1:04 am |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
You can only set positive values with the encoder target variable. you will nedd to reverse the A motor in the gap in the two blocks of code and again after that code has executed, at the end of the if statement. I forget how to reverse a motor, it is like bmotorreversed = true or something like that.
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Tue Feb 26, 2013 11:45 am |
|
 |
heinst
Rookie
Joined: Tue Feb 26, 2013 12:54 am Posts: 5
|
 Re: Encoder Help
To my understanding, the motor power is set to negative 40 power, but the encoder is still positive. Is that true?
|
Tue Feb 26, 2013 2:06 pm |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
If you flip the motor, to our eyes it will go backwards but the encoder and power will be positive.
*EDIT*
I misunderstood you. In your first commands, you set the target to 50 and than go backwards, never reaching the target. Flip the motor, set the target to 50 still, and set the speed to +40. Afterwards, reflip the motor. I think that should help.
The encoder can be positive or negative, but the target's sign does not mean the same thing. look at the motor section of the wiki to see what I mean.
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Tue Feb 26, 2013 3:14 pm |
|
 |
heinst
Rookie
Joined: Tue Feb 26, 2013 12:54 am Posts: 5
|
 Re: Encoder Help
|
Tue Feb 26, 2013 6:18 pm |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
HaHa no sorry, I meant reverse the motor using the bmotorflipped variable, not actually switch the commands.
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Tue Feb 26, 2013 7:14 pm |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Tue Feb 26, 2013 7:25 pm |
|
 |
heinst
Rookie
Joined: Tue Feb 26, 2013 12:54 am Posts: 5
|
 Re: Encoder Help
I tried that and the same thing happened...any other ideas? Do you think it will stem from somewhere else?
|
Wed Feb 27, 2013 1:38 pm |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
By the same thing do you mean claw close sudden sorry have to go
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Wed Feb 27, 2013 6:07 pm |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
Sorry, I had to leave, and I had no time to check my grammar. What I meant is this: what is the " same thing" that happened? Also, what is the robot like? Could you send a picture of it? I think we are close to finding the answer. I noticed a problem with a different area of your code. The code inside the if(time1[T2] > 1500) statement does not really do anything because the motor B is constantly being set from -75 to 75. Try changing that as well.
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Wed Feb 27, 2013 9:48 pm |
|
 |
heinst
Rookie
Joined: Tue Feb 26, 2013 12:54 am Posts: 5
|
 Re: Encoder Help
I figured it out: In case anyone else had the problem....thanks for the help. What is wrong with the if statement? I mean it works like i intended it too so good enough for me Now the next problem.....how would I spin until a light source is found....i attached some updated code. Thanks for the help again.
|
Thu Feb 28, 2013 1:56 am |
|
 |
Coder A
Moderator
Joined: Thu Jan 03, 2013 5:10 pm Posts: 207 Location: The plateau north of the Ohio River Valley, also known as Cave Country.
|
 Re: Encoder Help
I'm glad you got it working. As for what I thought is wrong with the if statement, it's because once time1[T2] > 1500, the statement works as it should. It's just the loop it's in causes motor B to be set back to -75, so I thougt that that line should only run when time is less than 1500, like this: But if it already works, then that's fine. What's wrong with the light part of the program?
_________________ I'm not a robot! I'm british! ~ quote from an asparagus I am not a robot! I am a unicorn! ~ quote from a robot
|
Thu Feb 28, 2013 5:45 pm |
|
|