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






Reply to topic  [ 2 posts ] 
Enconders autonomous. 
Author Message
Rookie

Joined: Mon Feb 27, 2012 5:26 pm
Posts: 20
Post Enconders autonomous.
The question I have 4 drive motors but two encoders is there a way to make them all go the same direction and distance? I am having an issue that they are traveling way too far.
here is the code.

Code:
#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,     right1,        tmotorTetrix, openLoop, reversed, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     right2,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_1,     left1,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     left2,         tmotorTetrix, openLoop, encoder)
//*!!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] = 5;//set the encoder target to 720
nMotorEncoderTarget[right1] = 5;//set the encoder target to 720
motor[left2] = -20;//turn on motorB at 50% power
motor[right1] = -20;//turn on motorC at 50% power


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


Attachments:
rubber3.c [1.37 KiB]
Downloaded 171 times
Mon Dec 10, 2012 2:19 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 597
Post Re: Enconders autonomous.
There are a couple of things here that I am seeing that could be causing the problems. First, I've noticed that you have the 'reversed' boxes checked for motors left2 and right1 AND are using negative motor values to move forward; while this will work, it can get a bit confusing and should generally be avoided.

Second, the nMotorEncoder and nMotorEncoderTarget commands use the raw data returned from the encoders; to set an encoder target of 720, you would need to use nMotorEncoderTarget(720);

The third thing that may be incorrect is that you are using the runStateIdle as an idle loop (according to the comments) but have two motor commands inside of it; this means that the code inside of the loop will continue while the conditions are true and this may need changed.

For the original problem, though, we usually see the motors rotating continually if the motor power values do not match the target encoder values; if the motor moving forward (positive) causes the encoder to move backwards (negative), you will need to compensate for that in your code. Otherwise, the distance between where the robot is and where it needs to be (as far as the encoders are concerned) will keep growing, not shrinking.

_________________
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


Mon Dec 10, 2012 2:42 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.