We need to all remember we are no better than our fellow man, no matter what job we all hold, what socio-economic status that's involved, or anything. Plain and simple, we're all fellow travelers on this pale blue dot called Earth. - trobots.com [more]
 Chief Delphi [OCCRA]: Common 2016 OCCRA programming mistakes
 portal register members calendar search Today's Posts Mark Forums Read FAQ rules

#1
11-02-2016, 04:36 PM
 pjt0620 Registered User FRC #2832 Join Date: Sep 2016 Rookie Year: 2007 Location: Livonia MI, Posts: 8
[OCCRA]: Common 2016 OCCRA programming mistakes

Hi I'm Pete you may know me as an inspector or for some of you that guy that helped you with your code at the competition,
I've noticed a couple of common mistakes lots of teams are making when programming their robots this year. I'm gonna keep a running list here as the season goes on so if you are having issues with your code you may be able to find the answer here.

The first most common issue I've seen is people making is trying to set up their motors to buttons incorrectly the symptoms of this are the motor spins one way fine but the other way it moves slowly or jumps a bit.
The incorrect code looks like this:
Code:
```if(vexRT[Btn5U] == 1)
{
motor[leftMotor] = 127
}
if(vexRT[Btn5U] == 0)
{
motor[leftMotor] = 0
}
if(vexRT[Btn5D] == 1)
{
motor[leftMotor] = -127
}
if(vexRT[Btn5D] == 0)
{
motor[leftMotor] = 0
}```
Now to see why that will not work lets walk through it line by line in its failure case
Code:
```if(vexRT[Btn5U] == 1)// or (1 == 1) or True, We are holding down the up button so its value is pressed or 1
{
motor[leftMotor] = 127 //The motor is now set to 127 or full forward
}
//Motor is full forward or 127
if(vexRT[Btn5U] == 0)// or (1 == 0) or False, We are holding down the up button so its value is pressed or 1
{
motor[leftMotor] = 0 //This set 0 does not run as expected since 1 is not equal to 0 go figure
}
//Motor is still full forward or 127 due to the last if failed again no issues so far
if(vexRT[Btn5D] == 1)// or (0 == 1) or False, We are NOT holding down the down button so its value is NOT pressed or 0
{
motor[leftMotor] = -127 //This set -127 does not run as expected since 1 is not equal to 0 go figure
}
//The motor is still going full forward 127 which is again expected as we are only holding the up button
if(vexRT[Btn5D] == 0)// or (0 == 0) or True, This is the start of our problem this statement is also True lets keep going and see the effect this has
{
motor[leftMotor] = 0 //Now we are setting the motor to 0 or Stopped
}
//Now even though we are holding the up button down the motor has been stopped due to the fact that the code for the down button not being pressed was put after the up button set the motor to full forward causing it to almost immediately turn the motor back off```
One of the ways of fixing this is to use an else if statement as shown below
Code:
```if (vexRT[Btn5U] == 1)
{
motor[leftMotor] = 127
}
else if (vexRT[Btn5U] == 1)
{
motor[leftMotor] = -127
}
else
{
motor[leftMotor] = 0
}```
In this case an else if will protect ageist that issue due to the fact it leaves no case where the code can contradict itself and set the value of the motor twice in one loop of the code.

More common issues to be posted shortly.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum     Rumor Mill     Career     Robot Showcase Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         C/C++         Java         Python     Sensors     Control System     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics Competition     Awards         Chairman's Award     Rules/Strategy         Scouting     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     District Events     Off-Season Events     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A Other     Chit-Chat         Games/Trivia         Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         The Blue Alliance     FIRST In the News...     FIRST Lego League     FIRST Tech Challenge     VEX     Televised Robotics     Math and Science     NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion

All times are GMT -5. The time now is 09:38 AM.

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

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top