OCCRA
Go to Post Remember everyone, during build season, if you mess something up..... In the words of Adam Savage... Failure is always an option! (and so is blowing stuff up) - J.Warsoff [more]
Home
Go Back   Chief Delphi > Competition > OCCRA
CD-Media  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-02-2016, 04:36 PM
pjt0620 pjt0620 is offline
Registered User
FRC #2832
 
Join Date: Sep 2016
Rookie Year: 2007
Location: Livonia MI,
Posts: 8
pjt0620 is an unknown quantity at this point
[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.
Reply With Quote
Reply


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


All times are GMT -5. The time now is 08:14 PM.

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


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi