Go to Post Pushing match, what pushing match? If they can't catch you they can't push you around. - IndySam [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-03-2006, 00:20
jamesgecko's Avatar
jamesgecko jamesgecko is offline
Linux Guy.
AKA: James D
FTC #0040 (Grep Lurch Grab)
Team Role: Leadership
 
Join Date: Oct 2004
Rookie Year: 2005
Location: Lawrenceville, Ga
Posts: 27
jamesgecko is an unknown quantity at this point
Send a message via AIM to jamesgecko Send a message via Yahoo to jamesgecko
Question Turning problems in Vex autonomous. [Solved]

I wrote the following code using easyC for Vex.
It's a function, it's supposed to take the angle I give it and turn in that direction. If I give it a positive angle, it turns to the right. I'm trying to make it turn to the left if I give it a negative angle, but it ain't happening. For some reason it simply turns to the right again. Any ideas?

Code:
#include "Main.h"
 
void turn ( int angle )
{ // Turns the robot a set number of degrees
      int done = 0; 
      int abs; 
 
      angle = angle/4 ; //For the optical sensors, one turn is 90 pulses.
      if ( angle < 0 )
      {
            abs = -angle ;
      }
      else
      {
            abs = angle ;
      }
      PresetEncoder ( L_OPTICAL_SENSOR_CHANNEL , Left_Optical_Sensor ) ;
      PresetEncoder ( R_OPTICAL_SENSOR_CHANNEL , Right_Optical_Sensor ) ;
      StartEncoder ( L_OPTICAL_SENSOR_CHANNEL ) ;
      StartEncoder ( R_OPTICAL_SENSOR_CHANNEL ) ;
      while ( done != 2 )
      {
            Left_Optical_Sensor = GetEncoder ( L_OPTICAL_SENSOR_CHANNEL ) ;
            Right_Optical_Sensor = GetEncoder ( R_OPTICAL_SENSOR_CHANNEL ) ;
            if ( Left_Optical_Sensor < abs )
            {
                  if ( angle > 0 & angle <= 90 )
                  {
                        SetMotor ( L_MOTOR , 255 ) ;
                  }
                  if ( angle >= -90 & angle < 0 )
                  {
                        SetMotor ( L_MOTOR , 0 ) ;
                  }
            }
            else
            {
                  SetMotor ( L_MOTOR , 127 ) ;
                  done = done + 1 ;
                  StopEncoder ( L_OPTICAL_SENSOR_CHANNEL ) ;
            }
            if ( Right_Optical_Sensor < abs )
            {
                  if ( angle > 0 & angle <= 90 )
                  {
                        SetMotor ( R_MOTOR , 255 ) ;
                  }
                  if ( angle >= -90 & angle < 0 )
                  {
                        SetMotor ( R_MOTOR , 0 ) ;
                  }
            }
            else
            {
                  SetMotor ( R_MOTOR , 127 ) ;
                  done = done + 1 ;
                  StopEncoder ( R_OPTICAL_SENSOR_CHANNEL ) ;
            }
      }
      return  ;
}
__________________
FVC40: We use all of the buffalo.

Last edited by jamesgecko : 09-03-2006 at 16:43. Reason: Adding "solved"
  #2   Spotlight this post!  
Unread 09-03-2006, 00:58
Keith Watson Keith Watson is offline
Registered User
FRC #0957 (WATSON)
Team Role: Mentor
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Wilsonville, OR
Posts: 112
Keith Watson is just really niceKeith Watson is just really niceKeith Watson is just really niceKeith Watson is just really nice
Re: Turning problems in Vex autonomous.

Code:
                  if ( angle > 0 & angle <= 90 )
This should be the logical operator &&, not the bit operator &.

Personally, I always write multiple expressions in the following form. It is more readable and forces the precedence I want. I have to type a few more keystrokes but it is worth the correctness and clarity.
Code:
                  if ( (angle > 0) && (angle <= 90) )
Otherwise someone who knows the functions you are calling will have to help you.
__________________
Keith Watson - Professional Software Engineer
No relation to "Kevin" Watson, who created the camera tracking code.

Last edited by Keith Watson : 09-03-2006 at 01:02. Reason: added not and fixed typo
  #3   Spotlight this post!  
Unread 09-03-2006, 07:18
koenig3456 koenig3456 is offline
Programming Coach
None #0681 (EARTH Squad)
Team Role: Coach
 
Join Date: Jan 2006
Location: Pennsylvania
Posts: 16
koenig3456 is an unknown quantity at this point
Re: Turning problems in Vex autonomous.

Since the wheels are mounted on opposite sides of the robot, they need to be operated opposite from each other. For example: To drive straight you would use:
SetMotor ( L_MOTOR , 255 ) ;
SetMotor ( R_MOTOR , 0 ) ;

Try swapping the SetMotor ( R_MOTOR , 255 ) ; and SetMotor ( R_MOTOR , 0 ) ; calls.
  #4   Spotlight this post!  
Unread 09-03-2006, 16:41
jamesgecko's Avatar
jamesgecko jamesgecko is offline
Linux Guy.
AKA: James D
FTC #0040 (Grep Lurch Grab)
Team Role: Leadership
 
Join Date: Oct 2004
Rookie Year: 2005
Location: Lawrenceville, Ga
Posts: 27
jamesgecko is an unknown quantity at this point
Send a message via AIM to jamesgecko Send a message via Yahoo to jamesgecko
Lightbulb Re: Turning problems in Vex autonomous.

Thanks, Keith. It works great now.

koenig3456: But I want the robot to turn... ;-)
__________________
FVC40: We use all of the buffalo.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[moderated]: NASA/VCU field problems Stephen P General Forum 42 09-03-2006 19:59
BAE Granite State Regional MattK Regional Competitions 15 03-03-2006 23:38
Autonomous Camera Integration GregC Programming 2 06-02-2005 14:34
Next Years Game? Jeremy General Forum 49 27-04-2004 01:53


All times are GMT -5. The time now is 23:06.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi