View unanswered posts | View active topics It is currently Fri Oct 18, 2019 4:46 pm

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
using shaft encoders to drive in a straight line
Author Message
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3
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.

Sun May 27, 2007 4:40 pm
Rookie

Joined: Tue May 15, 2007 1:01 pm
Posts: 10

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
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3

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

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 if you need help with turning email me at core2extremist2@gmail.com

Tue May 29, 2007 9:22 am
Rookie

Joined: Tue May 15, 2007 1:01 pm
Posts: 10

perhaps you shoud use "else if" statements instead of three "if"'s

Tue May 29, 2007 1:30 pm
Rookie

Joined: Sun May 27, 2007 4:35 pm
Posts: 3

that might work but that was something i threw together insted of a PID

Tue May 29, 2007 2:41 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 posts ]

#### 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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning