View unanswered posts | View active topics It is currently Wed Oct 01, 2014 9:54 pm






Reply to topic  [ 12 posts ] 
Encoder Help 
Author Message
Rookie

Joined: Tue Feb 26, 2013 12:54 am
Posts: 5
Post Encoder Help
I have this code below:
Code:
   if(SensorValue[sonarSensor] < 10 )
      {
            nMotorEncoder[motorA] = 0;
            nMotorEncoderTarget[motorA] = 50;
            motor[motorA] = -40;
            motor[motorB] = 20;
            motor[motorC] = 20;
            wait1Msec(2000);

            nMotorEncoder[motorA] = 0;
            nMotorEncoderTarget[motorA] = 50;
            motor[motorA] = 40;
            motor[motorB] = 40;
            motor[motorC] = 40;
}

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.


Attachments:
File comment: full code from which the snippet was pulled from
CompetitionCode.c [3.54 KiB]
Downloaded 181 times
Tue Feb 26, 2013 1:04 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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
Profile
Rookie

Joined: Tue Feb 26, 2013 12:54 am
Posts: 5
Post Re: Encoder Help
Coder A wrote:
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.


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
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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
Profile
Rookie

Joined: Tue Feb 26, 2013 12:54 am
Posts: 5
Post Re: Encoder Help
Code:
if(SensorValue[sonarSensor] < 10 )
      {
            nMotorEncoder[motorA] = 0;
            motor[motorA] = -40;
            nMotorEncoderTarget[motorA] = 50;
            motor[motorB] = 20;
            motor[motorC] = 20;

            wait1Msec(2000);

            nMotorEncoder[motorA] = 0;
            motor[motorA] = 40;
            nMotorEncoderTarget[motorA] = 50;
            motor[motorB] = 40;
            motor[motorC] = 40;
}


Is that what you mean?


Tue Feb 26, 2013 6:18 pm
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Encoder Help
Like this:


Code:
if(SensorValue[sonarSensor] < 10 )
{
  nMotorEncoder[motorA] = 0;
  bMotorReflected[motorA] = true;
  nMotorEncoderTarget[motorA] = 50;
  motor[motorA] = 40;
  motor[motorB] = 20;
  motor[motorC] = 20;
  wait1Msec(2000);
  bMotorReflected[motorA] = false;

  nMotorEncoder[motorA] = 0;
  nMotorEncoderTarget[motorA] = 50;
  motor[motorA] = 40;
  motor[motorB] = 40;
  motor[motorC] = 40;
}

_________________
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
Profile
Rookie

Joined: Tue Feb 26, 2013 12:54 am
Posts: 5
Post Re: Encoder Help
Coder A wrote:
Like this:


Code:
if(SensorValue[sonarSensor] < 10 )
{
  nMotorEncoder[motorA] = 0;
  bMotorReflected[motorA] = true;
  nMotorEncoderTarget[motorA] = 50;
  motor[motorA] = 40;
  motor[motorB] = 20;
  motor[motorC] = 20;
  wait1Msec(2000);
  bMotorReflected[motorA] = false;

  nMotorEncoder[motorA] = 0;
  nMotorEncoderTarget[motorA] = 50;
  motor[motorA] = 40;
  motor[motorB] = 40;
  motor[motorC] = 40;
}


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
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: Encoder Help
heinst wrote:
I tried that and the same thing happened...any other ideas?


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
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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.

Code:
if(SensorValue[touchSensor] == true)
{
   ClearTimer(T2);
   while(time1[T2] < 2500)
   {
      motor[motorB] = -75;
      motor[motorC] = -75;
      if(time1[T2] > 1500)
      {
         nMotorEncoder[motorB] = 0;
         nMotorEncoderTarget[motorB] = 720;
         motor[motorB] = 75;
      }
   }
}



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
Profile
Rookie

Joined: Tue Feb 26, 2013 12:54 am
Posts: 5
Post Re: Encoder Help
I figured it out:
Code:
bMotorReflected[motorA] = true;
         nMotorEncoder[motorA] = 0;
         nMotorEncoderTarget[motorA] = encoder_valueA;
         motor[motorA] = 40;
         while(nMotorRunState[motorA] != runStateIdle)
         {

         }
         motor[motorA] = 0;
         motor[motorB] = 20;
         motor[motorC] = 20;

         wait1Msec(2000);

         bMotorReflected[motorA] = false;
         nMotorEncoder[motorA] = 0;
         nMotorEncoderTarget[motorA] = encoder_valueA;
         motor[motorA] = 40;
         while(nMotorRunState[motorA] != runStateIdle)
         {

         }
         motor[motorA] = 0;
         motor[motorB] = 40;
         motor[motorC] = 40;


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 :biggrin:

Now the next problem.....how would I spin until a light source is found....i attached some updated code. Thanks for the help again.


Attachments:
CompetitionCode.c [4.48 KiB]
Downloaded 181 times
Thu Feb 28, 2013 1:56 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post 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:

Code:

if(SensorValue[touchSensor] == true)
{
   ClearTimer(T2);
   while(time1[T2] < 2500)
   {
      //take out here
      motor[motorC] = -75;
      if(time1[T2] > 1500)
      {
         nMotorEncoder[motorB] = 0;
         nMotorEncoderTarget[motorB] = 720;
         motor[motorB] = 75;
      }
      else
         motor[motorB] = -75;  //    <----moved line
   }
}



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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.