Go to Post rebound rumble didn't really have a lot of rebounding or surprise earthquakes. - Rynocorn [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
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 02-20-2014, 08:52 PM
AdamWiwc AdamWiwc is offline
Registered User
FRC #5185
 
Join Date: Jan 2014
Location: Airdrie
Posts: 4
AdamWiwc is an unknown quantity at this point
Speeding up and slowing down in autonomous

For some reason whenever I try to run this code; speed remains at 0 and it counts i up to x and then speed is suddenly changed to 1.0. Speed is supposed to be a decimal of x depending on how many times the for loop has run through. I don't understand why this is happening and would be very grateful for some clarity.

double speed;
int x = 200;

for(int i = 0; i <= x; i++){
double gyroAngle = gyro.getAngle();
speed = i/x;
chassis.drive(-speed,-gyroAngle * Kp);
System.out.println("Speed- " + speed);
System.out.println("Ticks- " + i);
Timer.delay(0.01);
}
Timer.delay(1.0);
for(int i = x; i >= 0; i--){
double gyroAngle = gyro.getAngle();
speed = i/x;
chassis.drive(-speed,-gyroAngle * Kp);
Timer.delay(0.01);
}
chassis.drive(0.0, 0.0); //full stop

Thanks
~Adam Wiwc
Reply With Quote
  #2   Spotlight this post!  
Unread 02-20-2014, 11:34 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
See http://stackoverflow.com/questions/3...oduce-a-double
Reply With Quote
  #3   Spotlight this post!  
Unread 02-20-2014, 11:51 PM
TFleig78's Avatar
TFleig78 TFleig78 is offline
Registered User
AKA: Tyler
FRC #0078 (Air Strike)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Rhode Island
Posts: 58
TFleig78 will become famous soon enoughTFleig78 will become famous soon enough
Re: Speeding up and slowing down in autonomous

You're performing integer division. When you divide an int by a larger int, you get 0. Java gets rid of the decimal portion of the number. Try making i a double instead of an int.
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 09:04 AM.

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