using float vs int variable in rotate()

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

using float vs int variable in rotate()

Postby matt.e » Wed Jul 18, 2012 12:21 am

Any suggestions why I get an error with this sample program? Error says "angle" should be int instead of float when used in rotate(). I'm new to this, thanks for your help

Code: Select all
public class RotateExample
{
   public static void main(String args[])
   {
      // The distance to move forward
      float distance = 50.0f;
      
      // The radius of the wheels
      float radius = 2.8f;
      
      // The approximate value of Pi
      float Pi = 3.1415f;
      
      // The angle in degrees according to our formula
      float angle = (180*distance)/(Pi*radius);
      
      // Now rotating both wheels by that many degrees and
      // the robot should drive forward by 'distance'
      Motor.A.rotate(angle);
      Motor.C.rotate(angle);
   }
}
matt.e
New User
 
Posts: 2
Joined: Wed Jul 18, 2012 12:06 am

Re: using float vs int variable in rotate()

Postby roger » Wed Jul 18, 2012 2:55 am

The reason is simple. The rotate method in the NXTRegulatedMotor requires an integer parameter. See this link.
http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#rotate(int)
Perhaps your are new to Java and did not know that Java is a strongly typed language. All variables must belong to a specific type, and all method parameters require a specific type. Sometimes you can convert one type to another by casting the variable.
roger
Moderator
 
Posts: 368
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA

Re: using float vs int variable in rotate()

Postby matt.e » Wed Jul 18, 2012 11:13 pm

Yes, very new. Thanks for your help
matt.e
New User
 
Posts: 2
Joined: Wed Jul 18, 2012 12:06 am


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests

more stuff