View unanswered posts | View active topics It is currently Thu Oct 30, 2014 2:39 pm






Reply to topic  [ 5 posts ] 
Encoders help asap please 
Author Message
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Encoders help asap please
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, Irseeker, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3, light, sensorNone)
#pragma config(Sensor, S4, sonar, sensorNone)
#pragma config(Motor, mtr_S1_C1_1, left1, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, left2, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C2_1, right1, tmotorTetrix, openLoop, reversed, encoder)
#pragma config(Motor, mtr_S1_C2_2, right2, tmotorTetrix, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

task main()
{
nMotorEncoder[left2] = 0;//reset the value of encoder B to zero
nMotorEncoder[right1] = 0;//reset the value of encoder C to zero
nMotorEncoderTarget[left2] = 1400;//set the encoder target to 720
nMotorEncoderTarget[right1] = 1400;//set the encoder target to 720
motor[left2] = -32;//turn on motorB at 32% power
motor[right1] = -30;//turn on motorB at 30% power
motor[left1] = -32;//turn on motorB at 32% power
motor[right2] = -30;



while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle);
{ /* This is an idle loop. The program waits until the condition is satisfied*/}
motor[left2] = 0; //Turn off motors
motor[right1] = 0;
motor[left1] = 0;
motor[right2] = 0;



nMotorEncoder[left2] = 0;//reset the value of encoder B to zero
nMotorEncoder[right1] = 0;//reset the value of encoder C to zero
nMotorEncoderTarget[left2] = 825;//set the encoder target to 825
nMotorEncoderTarget[right1] = 825;//set the encoder target to 825
motor[left2] = 32;//turn on motorB at 32% power
motor[right1] = -30;//turn on motorB at 30% power
motor[left1] = 32;//turn on motorB at 32% power
motor[right2] = -30;


while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle);
{ /* This is an idle loop. The program waits until the condition is satisfied*/}
motor[left2] = 0; //Turn off motors
motor[right1] = 0;
motor[left1] = 0; //
motor[right2] = 0;


nMotorEncoder[left2] = 0;//reset the value of encoder B to zero
nMotorEncoder[right1] = 0;//reset the value of encoder C to zero
nMotorEncoderTarget[left2] = 2500;//set the encoder target to 2500
nMotorEncoderTarget[right1] = 2500;//set the encoder target to 2500
motor[left2] = -32;//turn on motorB at 32% power
motor[right1] = -30;//turn on motorB at 30% power
motor[left1] = -32;//turn on motorB at 32% power
motor[right2] = -30;


while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle);
{ /* This is an idle loop. The program waits until the condition is satisfied*/}
motor[left2] = 0; //Turn off motors
motor[right1] = 0;
motor[left1] = 0;
motor[right2] = 0;





}


Attachments:
middle peg.c [2.91 KiB]
Downloaded 244 times
Wed Dec 12, 2012 8:45 am
Profile
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Re: Encoders help asap please
The goal is to go reverse for a set distance, then do a turn, and then go in reverse one time all using encoders. For an odd reason it runs until the encoder reaches the maximum amount of clicks only in reverse and will not execute any other parts of the code.


Wed Dec 12, 2012 8:48 am
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Encoders help asap please
I'm not quite sure what you're trying to do here:
Code:
while(nMotorRunState[left2] != runStateIdle)(nMotorRunState[right1] != runStateIdle);

If you want to check whether both motors are in runStateIdle, use the AND (&&) command.
Code:
while((nMotorRunState[left2] != runStateIdle) && (nMotorRunState[right1] != runStateIdle));


Wed Dec 12, 2012 10:54 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 597
Post Re: Encoders help asap please
Code:
nMotorEncoderTarget[left2] = 1400;//set the encoder target to 720
nMotorEncoderTarget[right1] = 1400;//set the encoder target to 720
motor[left2] = -32;//turn on motorB at 32% power
motor[right1] = -30;//turn on motorB at 30% power


This will also cause problems. What you are saying here is 'set the encoder target to +1400, then move the motors in a negative direction'. The motors will turn on and the encoders will move away from the target, not towards it; eventually you will hit what is called the overflow for the encoders, at which point the values will 'roll over' to the opposite amount (for the NXT motors, this amount is -32767 to +32767; once -32767 is reached, the encoders will roll over to +32767). This is why you will see the motors run for a very long time and then suddenly stop; they are moving towards the -32767 rollover point and, once they overflow to +32767, they then stop.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Dec 12, 2012 11:31 am
Profile
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Re: Encoders help asap please
Should I just set the target to a negative number then to avoid the over flow and also now I have four motor encoders on the robot. However I am trying to be able to have the while that scans the encoders to meet the distance of like 720 for a half rotation or 1440 for a full rotation I want to be able to do a turn so the left side be a -100 power level and nmotorencoder target to = -720 and to have the right side be a 720 and motor power to = 100 is this the right way to do this and will it work?


Thu Dec 27, 2012 2:33 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.