To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2554
2553  |  2555
Subject: 
Re: Converting a float to an integer
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Mon, 13 May 2002 01:39:24 GMT
Viewed: 
2453 times
  
It looks like xdist and ydist are integers. You divide an integer by an
integer, the answer is an integer.

For example, if xdist=5 and ydist=10, you have 5/10, the answer is 0 (with a
remainder of 5). So, if you do the multiply first, you will be dividing a
bigger number (let's say MAX_SPEED is also 10), so 10*5 is 50, then 50/5 is
5. Half of max speed, which is what you would expect.

In lugnet.robotics.rcx.legos, Michael Marklew writes:
I have built a plotter and want to draw a diagonal line of varying angles.
It requires one motor to run slower then the other at a ratio based on the
distance it has to travel compared to the other one.

So I do something like this

xspeed = (int) MAX_SPEED*(xdist/ydist);
motor_c_speed(xspeed);
lcd_int(xspeed); lcd_refresh();

The LCD always displays a "0" and of course the motor stops. I have
outputted each variable separately and the result is not 0. So I figure it
is a float to an integer problem.

Turns out the problem was the brackets around xdist/ydist... Take them out
and it works fine..
xspeed = (int) MAX_SPEED*xdist/ydist;




Message is in Reply To:
  RE: Converting a float to an integer
 
I have built a plotter and want to draw a diagonal line of varying angles. It requires one motor to run slower then the other at a ratio based on the distance it has to travel compared to the other one. So I do something like this xspeed = (int) (...) (22 years ago, 9-May-02, to lugnet.robotics.rcx.legos)

4 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR