Go to Post Programming team motto: If it doesn't work, use a bigger hammer. - WizenedEE [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 18-02-2007, 16:03
Cody Carey's Avatar
Cody Carey Cody Carey is offline
,':-)
AKA: C. Carey
FRC #0306 (CRT)
Team Role: Alumni
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Corry, PA
Posts: 1,137
Cody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond reputeCody Carey has a reputation beyond repute
Send a message via AIM to Cody Carey Send a message via Yahoo to Cody Carey
User Code Critique

Hello everyone, I was just cleaning up the user code for this years 'bot, but I did it in notepad... so I'm not completely up on the syntax. I looked over it the best I could, but I would like some help so that I don't have to debug it when I go in on Monday. I would also like to know If I am using "SetRelay" correctly, and if there is anything that is done just plain sloppy/ how to fix it. Any help would be GREATLY appreciated

Thank you,
-Cody C.

Code:
unsigned char check;
unsigned char topcheck;


\*---------------------------ramp control-------------------------------*/

if (p3_sw_top == 1 && topcheck == 0);            // Press top button, kick cylinder extends; press top button cylinder retracts
     
    {
    SetRelay ( 2 , 1 ,0 ) ;
    topcheck==1; 
    }


else if (p3_sw_top == 1 && topcheck == 1);        
     
    {
    SetRelay ( 2 , 0 ,1 ) ;
    topcheck==0; 
    }


if (p3_sw_trig == 1 && check == 0);              // Press trigger... Hippo folds down and ramp folds out; Press again, reset.
     
    {
    SetRelay ( 3 , 1 ,0 );
    SetRelay ( 4 , 0 , 1 );
    SetRelay ( 5 , 1 ) ;
    check==1; 
    }


else if (p3_sw_trig == 1 && check == 1);
     
    {
    SetRelay ( 3 , 0 ,1 ) ;
    SetRelay ( 4 , 1 , 0 );
    SetRelay ( 5 , 0 ) ;
    check==0; 
    }


/*----------------------------Arm control------------------------------------*/


if (p4_sw_aux1 == 1);                 // if top red switch is up, Hippo is up and Jaw is closed
    
    {
    SetRelay ( 4 , 1 , 0 ) ;
    SetRelay ( 5 , 1 )
    }

if (p4_sw_aux1 == 0);                // if top red switch is down, Hippo is down and Jaw is open
    
    {
    SetRelay ( 4 , 0 , 1 ) ;
    SetRelay ( 5 , 0 )
    }

if (p4_sw_aux2 == 1);                // if bottom red switch is up, Hippo is down and Jaw is closed (ramp down)
    
    {
    SetRelay ( 4 , 0 , 1 ) ;
    SetRelay ( 5 , 1 )
    }



/*-------------------------Shifting-------------------------------------------*/



if (p4_sw_top == 0 && p3_sw_trig == 0);        // if shifter is in Bottom position, servos are in position 1
     
    {
    pwm05=0; 
    }


if (p4_sw_top == 1 && p3_sw_trig == 0);        // if shifter is in Middle position, servos are in position 2
     
    {
    pwm05=127; 
    }

if (p4_sw_top == 1 && p3_sw_trig == 1);        // if shifter is in Top position, servos are in position 3
     
    {
    pwm05=255; 
    }
__________________
  #2   Spotlight this post!  
Unread 18-02-2007, 16:29
Tureyhall Tureyhall is offline
Registered User
AKA: Thomas Hall
FRC #0668 (Apes Of Wrath)
Team Role: Programmer
 
Join Date: Feb 2006
Rookie Year: 2004
Location: San Jose
Posts: 40
Tureyhall will become famous soon enoughTureyhall will become famous soon enough
Re: User Code Critique

The obvious problems have been fixed:

Code:
unsigned char check;
unsigned char topcheck;


\*---------------------------ramp control-------------------------------*/

if (p3_sw_top == 1 && topcheck == 0)            // Press top button, kick cylinder extends; press top button cylinder retracts
    {
    SetRelay ( 2 , 1 ,0 ) ;
    topcheck = 1; 
    }
else if (p3_sw_top == 1 && topcheck == 1)
    {
    SetRelay ( 2 , 0 ,1 ) ;
    topcheck = 0; 
    }


if (p3_sw_trig == 1 && check == 0)              // Press trigger... Hippo folds down and ramp folds out; Press again, reset.
    {
    SetRelay ( 3 , 1 ,0 );
    SetRelay ( 4 , 0 , 1 );
    SetRelay ( 5 , 1 ) ;
    check = 1; 
    }
else if (p3_sw_trig == 1 && check == 1)
    {
    SetRelay ( 3 , 0 ,1 ) ;
    SetRelay ( 4 , 1 , 0 );
    SetRelay ( 5 , 0 ) ;
    check = 0; 
    }


/*----------------------------Arm control------------------------------------*/


if (p4_sw_aux1 == 1)                 // if top red switch is up, Hippo is up and Jaw is closed
    {
    SetRelay ( 4 , 1 , 0 ) ;
    SetRelay ( 5 , 1 );
    }

if (p4_sw_aux1 == 0)                // if top red switch is down, Hippo is down and Jaw is open
    {
    SetRelay ( 4 , 0 , 1 ) ;
    SetRelay ( 5 , 0 );
    }

if (p4_sw_aux2 == 1)                // if bottom red switch is up, Hippo is down and Jaw is closed (ramp down)
    {
    SetRelay ( 4 , 0 , 1 ) ;
    SetRelay ( 5 , 1 );
    }



/*-------------------------Shifting-------------------------------------------*/



if (p4_sw_top == 0 && p3_sw_trig == 0)        // if shifter is in Bottom position, servos are in position 1
    {
    pwm05=0;
    }

if (p4_sw_top == 1 && p3_sw_trig == 0)        // if shifter is in Middle position, servos are in position 2
    {
    pwm05=127; 
    }

if (p4_sw_top == 1 && p3_sw_trig == 1)        // if shifter is in Top position, servos are in position 3
    {
    pwm05=255; 
    }
I haven't seen a "setRelay" function before, so I can't help you there.
__________________
/*Nerd Camouflage*/

2005 SVR - 668+1072+840 - Semifinalists.
2006 SVR - 668+1280+1693 - Finalists.
2007 SVR - 668+604+624 - Quarter-finalists, Xerox Creativity Award, two highest scores (290-2, 128-0) at SVR.
2007 Nat's - TBA.
  #3   Spotlight this post!  
Unread 18-02-2007, 16:57
BossOfTheGame BossOfTheGame is offline
Not the garbage man
FTC #0020 (The Rocketeers)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2003
Location: Clifton Park
Posts: 6
BossOfTheGame will become famous soon enough
Send a message via AIM to BossOfTheGame
Re: User Code Critique

Well, first of all you shouldn't have semicolons after each if, that is bad. The comment was mixed up. You had a backwards slash and it should have been a forwards slash. You were also forgeting semicolons after some statements. The last thing I saw was you used == to assign when == is used to compare. = is used to assign. I formated it for you and fixed some errors. Here you go.

Code:
unsigned char check;
    unsigned char topcheck;
    /*---------------------------ramp control-------------------------------*/
    if (p3_sw_top == 1 && topcheck == 0) // Press top button, kick cylinder extends; press top button cylinder retracts
    {
      SetRelay(2, 1, 0);
      topcheck = 1;
    }
    else if (p3_sw_top == 1 && topcheck == 1)
    {
      SetRelay(2, 0, 1);
      topcheck = 0;
    }
    if (p3_sw_trig == 1 && check == 0) // Press trigger... Hippo folds down and ramp folds out; Press again, reset.
    {
      SetRelay(3, 1, 0);
      SetRelay(4, 0, 1);
      SetRelay(5, 1);
      check = 1;
    }
    else if (p3_sw_trig == 1 && check == 1)
    {
      SetRelay(3, 0, 1);
      SetRelay(4, 1, 0);
      SetRelay(5, 0);
      check = 0;
    }
    /*----------------------------Arm control------------------------------------*/
    if (p4_sw_aux1 == 1) // if top red switch is up, Hippo is up and Jaw is closed
    {
      SetRelay(4, 1, 0);
      SetRelay(5, 1);
    }
    if (p4_sw_aux1 == 0) // if top red switch is down, Hippo is down and Jaw is open
    {
      SetRelay(4, 0, 1);
      SetRelay(5, 0);
    }
    if (p4_sw_aux2 == 1) // if bottom red switch is up, Hippo is down and Jaw is closed (ramp down)
    {
      SetRelay(4, 0, 1);
      SetRelay(5, 1);
    }
    /*-------------------------Shifting-------------------------------------------*/
    if (p4_sw_top == 0 && p3_sw_trig == 0) // if shifter is in Bottom position, servos are in position 1
    {
      pwm05 = 0;
    }
    if (p4_sw_top == 1 && p3_sw_trig == 0) // if shifter is in Middle position, servos are in position 2
    {
      pwm05 = 127;
    }
    if (p4_sw_top == 1 && p3_sw_trig == 1) // if shifter is in Top position, servos are in position 3
    {
      pwm05 = 255;
    }
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
Trouble using Kevin Watson's Serial Code with Vex user API StargateFan Programming 3 13-01-2007 15:42
Critique this code Ben Englert Programming 12 06-04-2006 01:21
New IFI Default/User and Master Code Alex698 Programming 6 28-02-2006 23:04
Critique Mike Website Design/Showcase 5 18-06-2005 02:15
user code to default code phoenixomega001 Programming 5 09-01-2005 00:09


All times are GMT -5. The time now is 04:11.

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