View unanswered posts | View active topics It is currently Wed Jul 30, 2014 6:44 am






Reply to topic  [ 5 posts ] 
using shaft encoders to drive in a straight line 
Author Message
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3
Post using shaft encoders to drive in a straight line
I have vex with 2 shaft encoders on 2 wheels.
I am trying to programe it to drive in a straight line, because now it has a slight drift to the right.
If some one could give me some code on how to do this, that would help alot.

also how would you make a bump sensor an intorupt so any were in your code if you hit that swich then the program stops. :?: :mrgreen:


Sun May 27, 2007 4:40 pm
Profile
Rookie

Joined: Tue May 15, 2007 1:01 pm
Posts: 10
Post 
wat i did for my bot was just configure the motor power until it runs in a straight line and not use the shaft encoders


Tue May 29, 2007 8:57 am
Profile
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3
Post 
the problem with that is if your batterys gets low then you have to reconfigure and that get very time consuming some times. i figured it out
if you have two shaft encoders then you do 3 if statments like this.

if(sensorvalue(R_left) == sensorvalue(R_right)// going straight
{
motor[Motor_L] = 50;// ajust these ratios depending on how fast you
motor[Motor_R] = 50;//want to go 80 is about as fast as you can go without gearing
}

if(sensorvalue(R_left) > sensorvalue(R_right)//driffting to the right
{
motor[Motor_L] = 50;
motor[Motor_R] = 55;
}

if(sensorvalue(R_left) < sensorvalue(R_right)// drifting to the left
{
motor[Motor_L] = 55;
motor[Motor_R] = 50;
}

and thats it
:D

if you want to put it in a sub routine to go a cirtan distance

void DriveStraight (int distance)
{
while(sensorvalue(R_left) != 7 /*change this value depending on what the diamitor of you whelle is mine was 5" this is the number of ticks per inch. you figure the cercoumfrence and divide it by 100. that gives you your ticks per inch*/ *distance)
{
if(sensorvalue(R_left) == sensorvalue(R_right)// going straight
{
motor[Motor_L] = 50;// ajust these ratios depending on how fast you
motor[Motor_R] = 50;//want to go 80 is about as fast as you can go without gearing
}

if(sensorvalue(R_left) > sensorvalue(R_right)//driffting to the right
{
motor[Motor_L] = 50;
motor[Motor_R] = 55;
}

if(sensorvalue(R_left) < sensorvalue(R_right)// drifting to the left
{
motor[Motor_L] = 55;
motor[Motor_R] = 50;
}
}
}

and your done

and if you need help with turning email me at core2extremist2@gmail.com


Tue May 29, 2007 9:22 am
Profile
Rookie

Joined: Tue May 15, 2007 1:01 pm
Posts: 10
Post 
perhaps you shoud use "else if" statements instead of three "if"'s


Tue May 29, 2007 1:30 pm
Profile
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3
Post 
that might work but that was something i threw together insted of a PID


Tue May 29, 2007 2:41 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.