So, my question is, if you set the encoder value at 0 in a specific location at the beginning of autonomous, and then move on to tele-op, does the encoder retain the value for 0, or do I have to reset it. If I have to reset it, how would I go about doing so?

Thanks in advance for your help!

Thu Nov 11, 2010 1:42 am

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: Encoder Programming Question

Whenever your motors move, the encoders will register some values. So at the end of autonomous, they won't be zero any more. If you need them to be zero, you need to reset them again. To reset the encoders to zero, it is the same way as you set them to zero the first time (e.g. nMotorEncoder[motorA] = 0).

Thu Nov 11, 2010 6:01 am

Betty

Rookie

Joined: Thu Nov 11, 2010 1:35 amPosts: 3

Re: Encoder Programming Question

Can the encoders used to set the motors to a specific position, similar to servos (but with more range of motion)? This is what we're hoping to use them for. If this is completely outlandish, please let me know!

If so, if we set a zero position at the beginning of autonomous to position the motors from, can we then use the same zero position to program from without resetting it, or do we have to return to the same position and reset it at zero?

Thanks for your help!

Thu Nov 11, 2010 7:41 pm

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1523

Re: Encoder Programming Question

Yes, motors that have encoders can be used as servos with some programming. And yes you can keep the encoders going without resetting them. Depending on what you use them for. It may be acceptable not resetting them. However, in some scenarios, you may want to reset them. For example, if you use them in a situation where the gear could slip. In time, you may have a cumulative error (i.e. your "home position" is no longer home). Again depending on the situation, you could have it self calibrated (e.g. have a touch sensor at the home position so occassionally, your program will pull the motor back to "home position" until the touch sensor fires, then you can reset the encoder because that's your home position) etc...

Thu Nov 11, 2010 7:51 pm

Betty

Rookie

Joined: Thu Nov 11, 2010 1:35 amPosts: 3

Re: Encoder Programming Question

Thanks, that was helpful! I just started actually trying to program the encoders today, and I've run across a problem.

Here is my tele-op code. I was able to get the arm to move to the encoder position if I press either the right or bottom of the d-pad (tophat values 2 and 4). However, as soon as the arm moves to one of the values, every other command on the joystick stops working. For example, one of the first things I do is press the bottom of the d-pad. The arm moves, but after this nothing will respond on our robot. Did I leave out something very important?

A second question also: I know that I did part of the code wrong (the middle encoder value). I want the arm to move to the middle position from either of the other positions, but by using the shortest distance. Here's an example of what I want: I am in the bottom position (farthest from zero). I want the arm to move to the middle position. However, I want it to move backwards, so it does not have to go around almost a whole rotation. I would like to have the arm able to figure out which way (forwards or backwards) to move the motor the shortest distance. Is there a way to do this easily? I was thinking that maybe there was a way to measure the encoder values, and depending on this choose which way to move, but I did not see any way to do this.

Sorry my code is so long--I wanted to make sure I wasn't leaving anything important out!

If you can help with this, that would be great! (Let me know if I need to clarify anything)

if (abs(Left_Motor_Power) < 10) //If the value of the joysticks does not read more than 10, the motors will { //not run. This helps us to save from grinding the motors and creeping. Left_Motor_Power = 0; }

if (abs(Right_Motor_Power) < 10) { Right_Motor_Power = 0; }

if (abs(Left_Motor_Power) > 75) //If the value of the joysticks reads over 75, the motors will not run at { //top speed. They will only run at 75 speed at most. Left_Motor_Power = (Left_Motor_Power * 100) / 75; }

I spotted multiple problems with your code. First, I don't understand what the following code was tring to do:

Code:

if (abs(Left_Motor_Power) > 75) //If the value of the joysticks reads over 75, the motors will not run at { //top speed. They will only run at 75 speed at most. Left_Motor_Power = (Left_Motor_Power * 100) / 75; }

Your comment said you are trying to limit the motor power to 75 but in reality you are multiplying it with 4/3 (1.33) if it is greater than 75. Also note that joystick value has a range of -128 to 127 and the motor range is -100 to 100. So you need to scale the joystick range to the motor range proportionately. I define and use the following macros to take care of the scaling and limiting different values.

/** * These macros ignore input value (n) that is within the DEADBAND_THRESHOLD. * This is necessary because analog joysticks do not always centered at zero. * So if the joystick is at the rest position, we will consider it zero even * though the value is non-zero but within DEADBAND_THRESHOLD. */#define DEADBAND(n,t) ((abs(n) > (t))? (n): 0)#define DEADBAND_INPUT(n) DEADBAND(n, DEADBAND_INPUT_THRESHOLD)

/** * This macro limits the input value (n) to the range between -128 and 127. * This is useful when calculations on the input value may bring the result * outside of the valid range. This macro will make sure the result is within * bounds. */#define BOUND_INPUT(n) BOUND(n, -128, 127)

Secondly, I would avoid using the following code construct because if the enocder doesn't reach target for some reason, your while loop will not come back. That will explain why nothing else work if it is stuck in this while loop.

Is there a reason why you want to block other operations until the current movement is done? If there is no reason, you can take out the while loop. You only need this if you want to do an operation that depends on the completion of the previous operation.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum