Announcement

Collapse
No announcement yet.

120.9 - 0 = 0 ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Todd Wasson
    replied
    Thanks, Tim. I didn't know that. Was curious as to why if I just put the value in the variables place in the equation, it would work, but the variable by itself wouldn't. Thanks!
    Todd Wasson


    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Code:
    #COMPILE EXE
    DEFSNG a-z
    
    FUNCTION PBMAIN() AS LONG
    LOCAL TEXT AS STRING
    LOCAL TEXT2 AS STRING
    LOCAL TEXT3 AS STRING
    LOCAL TEXT4 AS STRING
    PI=3.141593
    YAW=0
    WHEELBASE=10 '108/12
    REAR_WEIGHT_PERCENT=.5
    LEFT_WEIGHT_PERCENT=.5
    FRONT_TRACK_WIDTH=6
    REAR_TRACK_WIDTH=6
    DIST_CG_FRONT_AXLE = WHEELBASE * REAR_WEIGHT_PERCENT
    DIST_CG_REAR_AXLE = WHEELBASE * (1-REAR_WEIGHT_PERCENT)
    DIST_CG_FRONT_RIGHT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(FRONT_TRACK_WIDTH*LEFT_WEIGHT_PERCENT)^2)
    DIST_CG_FRONT_LEFT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(FRONT_TRACK_WIDTH*(1-LEFT_WEIGHT_PERCENT))^2)
    DIST_CG_REAR_RIGHT_WHEEL=SQR(DIST_CG_REAR_AXLE^2-(REAR_TRACK_WIDTH*LEFT_WEIGHT_PERCENT)^2)
    DIST_CG_REAR_LEFT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(REAR_TRACK_WIDTH*(1-LEFT_WEIGHT_PERCENT))^2)
    CIRCUM_FRONT_RIGHT=2 * DIST_CG_FRONT_RIGHT_WHEEL * PICIRCUM_FRONT_LEFT=2 * DIST_CG_FRONT_LEFT_WHEEL * PI
    CIRCUM_REAR_RIGHT=2 * DIST_CG_REAR_RIGHT_WHEEL * PICIRCUM_REAR_LEFT=2 * DIST_CG_REAR_LEFT_WHEEL * PI
    D1 = FRONT_TRACK_WIDTH * LEFT_WEIGHT_PERCENT  'FRONT RIGHT
    D2 = REAR_TRACK_WIDTH * LEFT_WEIGHT_PERCENT   'REAR RIGHT
    D3 = REAR_TRACK_WIDTH * (1-LEFT_WEIGHT_PERCENT) 'REAR LEFT
    D4 = FRONT_TRACK_WIDTH * (1-LEFT_WEIGHT_PERCENT)'FRONT LEFT
    ANGLE_TO_WHEEL_FRONT_RIGHT=ATN(D1/DIST_CG_FRONT_AXLE)*180/PI
    ANGLE_TO_WHEEL_REAR_RIGHT=180-ATN(D2/DIST_CG_REAR_AXLE)*180/PI
    ANGLE_TO_WHEEL_REAR_LEFT=180+ATN(D3/DIST_CG_REAR_AXLE)*180/PI
    ANGLE_TO_WHEEL_FRONT_LEFT=360-ATN(D4/DIST_CG_FRONT_AXLE)*180/PI
    TEXT$= "Angle to front right wheel:"+STR$ (ANGLE_TO_WHEEL_FRONT_RIGHT)
    TEXT2$= "Angle to rear right wheel:"+STR$ (ANGLE_TO_WHEEL_REAR_RIGHT)
    TEXT3$= "Angle to rear left wheel:"+STR$ (ANGLE_TO_WHEEL_REAR_LEFT)
    TEXT4$= "Angle to front left wheel:"+STR$ (ANGLE_TO_WHEEL_FRONT_LEFT)
    DIRECTION_VEL_FRONT_RIGHT= (ANGLE_TO_WHEEL_FRONT_RIGHT + YAW + 90) MOD 360
    DIRECTION_VEL_REAR_RIGHT= (ANGLE_TO_WHEEL_REAR_RIGHT + YAW + 90) MOD 360
    DIRECTION_VEL_REAR_LEFT= (ANGLE_TO_WHEEL_REAR_LEFT + YAW + 90) MOD 360
    DIRECTION_VEL_FRONT_LEFT= (ANGLE_TO_WHEEL_FRONT_LEFT + YAW + 90) MOD 360
    TEXT$="Velocity direction: Front right:"+STR$(DIRECTION_VEL_FRONT_RIGHT)
    TEXT2$="Rear right:"+STR$(DIRECTION_VEL_REAR_RIGHT)
    TEXT3$="Rear left:"+STR$(DIRECTION_VEL_REAR_LEFT)
    TEXT4$="Front left:"+STR$(DIRECTION_VEL_FRONT_LEFT)
    TRUE_VELOCITY=10
    X_COMPONENT = SIN (DIRECTION_VEL*PI/180) * TRUE_VELOCITY
    Y_COMPONENT = COS (DIRECTION_VEL*PI/180) * TRUE_VELOCITY
    CAR_X_VEL=0
    CAR_Y_VEL=0
    IF CAR_X_VEL>=0 AND CAR_Y_VEL>=0 THEN
       IF ABS(CAR_Y_VEL) < .000001 THEN
          CAR_DIRECTION = 0
       ELSE
          CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)
       END IF
    END IF
    IF CAR_X_VEL<0 AND CAR_Y_VEL>=0 THEN
       IF ABS(CAR_Y_VEL) < .000001 THEN
          CAR_DIRECTION = 0
       ELSE
          CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)+360
       END IF
    END IF
    IF CAR_Y_VEL<0 THEN
       IF ABS(CAR_Y_VEL) < .000001 THEN
          CAR_DIRECTION = 0
       ELSE
          CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)+180'----Here is problem area:
       END IF
    END IF
    MSGBOX STR$(DIRECTION_VEL_FRONT_RIGHT )+"    "+STR$(CAR_DIRECTION)
    SLIP_FRONT_RIGHT = DIRECTION_VEL_FRONT_RIGHT-CAR_DIRECTION
    MSGBOX STR$(SLIP_FRONT_RIGHT)
    END FUNCTION
    You were dividing by zero and ending up with a number that prints out as zero but is really undefined. It acts like a very negative number. No matter what you add to or subtract from it you will get zero.

    Check for zero before you divide.

    Tim Wisseman



    [This message has been edited by Tim Wisseman (edited April 18, 2000).]

    Leave a comment:


  • Todd Wasson
    started a topic 120.9 - 0 = 0 ?

    120.9 - 0 = 0 ?

    Code:
    '''''Find slip angles of tires based on rotation and translation
    #COMPILE EXE
    DEFSNG a-z
    
    FUNCTION PBMAIN() AS LONG
    LOCAL TEXT AS STRING
    LOCAL TEXT2 AS STRING
    LOCAL TEXT3 AS STRING
    LOCAL TEXT4 AS STRING
    PI=3.141593
    YAW=0
    WHEELBASE=10'108/12
    REAR_WEIGHT_PERCENT=.5
    LEFT_WEIGHT_PERCENT=.5
    FRONT_TRACK_WIDTH=6
    REAR_TRACK_WIDTH=6
    
    DIST_CG_FRONT_AXLE = WHEELBASE * REAR_WEIGHT_PERCENT
    DIST_CG_REAR_AXLE = WHEELBASE * (1-REAR_WEIGHT_PERCENT)
    
    DIST_CG_FRONT_RIGHT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(FRONT_TRACK_WIDTH*LEFT_WEIGHT_PERCENT)^2)
    DIST_CG_FRONT_LEFT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(FRONT_TRACK_WIDTH*(1-LEFT_WEIGHT_PERCENT))^2)
    DIST_CG_REAR_RIGHT_WHEEL=SQR(DIST_CG_REAR_AXLE^2-(REAR_TRACK_WIDTH*LEFT_WEIGHT_PERCENT)^2)
    DIST_CG_REAR_LEFT_WHEEL=SQR(DIST_CG_FRONT_AXLE^2-(REAR_TRACK_WIDTH*(1-LEFT_WEIGHT_PERCENT))^2)
    CIRCUM_FRONT_RIGHT=2 * DIST_CG_FRONT_RIGHT_WHEEL * PI
    CIRCUM_FRONT_LEFT=2 * DIST_CG_FRONT_LEFT_WHEEL * PI
    CIRCUM_REAR_RIGHT=2 * DIST_CG_REAR_RIGHT_WHEEL * PI
    CIRCUM_REAR_LEFT=2 * DIST_CG_REAR_LEFT_WHEEL * PI
    D1 = FRONT_TRACK_WIDTH * LEFT_WEIGHT_PERCENT  'FRONT RIGHT
    D2 = REAR_TRACK_WIDTH * LEFT_WEIGHT_PERCENT   'REAR RIGHT
    D3 = REAR_TRACK_WIDTH * (1-LEFT_WEIGHT_PERCENT) 'REAR LEFT
    D4 = FRONT_TRACK_WIDTH * (1-LEFT_WEIGHT_PERCENT)'FRONT LEFT
    ANGLE_TO_WHEEL_FRONT_RIGHT=ATN(D1/DIST_CG_FRONT_AXLE)*180/PI
    ANGLE_TO_WHEEL_REAR_RIGHT=180-ATN(D2/DIST_CG_REAR_AXLE)*180/PI
    ANGLE_TO_WHEEL_REAR_LEFT=180+ATN(D3/DIST_CG_REAR_AXLE)*180/PI
    ANGLE_TO_WHEEL_FRONT_LEFT=360-ATN(D4/DIST_CG_FRONT_AXLE)*180/PI
    TEXT$= "Angle to front right wheel:"+STR$ (ANGLE_TO_WHEEL_FRONT_RIGHT)
    TEXT2$= "Angle to rear right wheel:"+STR$ (ANGLE_TO_WHEEL_REAR_RIGHT)
    TEXT3$= "Angle to rear left wheel:"+STR$ (ANGLE_TO_WHEEL_REAR_LEFT)
    TEXT4$= "Angle to front left wheel:"+STR$ (ANGLE_TO_WHEEL_FRONT_LEFT)
    DIRECTION_VEL_FRONT_RIGHT= (ANGLE_TO_WHEEL_FRONT_RIGHT + YAW + 90) MOD 360
    DIRECTION_VEL_REAR_RIGHT= (ANGLE_TO_WHEEL_REAR_RIGHT + YAW + 90) MOD 360
    DIRECTION_VEL_REAR_LEFT= (ANGLE_TO_WHEEL_REAR_LEFT + YAW + 90) MOD 360
    DIRECTION_VEL_FRONT_LEFT= (ANGLE_TO_WHEEL_FRONT_LEFT + YAW + 90) MOD 360
    TEXT$="Velocity direction: Front right:"+STR$(DIRECTION_VEL_FRONT_RIGHT)
    TEXT2$="Rear right:"+STR$(DIRECTION_VEL_REAR_RIGHT)
    TEXT3$="Rear left:"+STR$(DIRECTION_VEL_REAR_LEFT)
    TEXT4$="Front left:"+STR$(DIRECTION_VEL_FRONT_LEFT)
    TRUE_VELOCITY=10
    X_COMPONENT = SIN (DIRECTION_VEL*PI/180) * TRUE_VELOCITY
    Y_COMPONENT = COS (DIRECTION_VEL*PI/180) * TRUE_VELOCITY
    CAR_X_VEL=0
    CAR_Y_VEL=0
    IF CAR_X_VEL>=0 AND CAR_Y_VEL>=0 THEN CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)
    IF CAR_X_VEL<0 AND CAR_Y_VEL>=0 THEN CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)+360
    IF CAR_Y_VEL<0 THEN CAR_DIRECTION=(ATN(CAR_X_VEL/CAR_Y_VEL)*180/PI)+180
    '----Here is problem area:
    MSGBOX STR$(DIRECTION_VEL_FRONT_RIGHT )+"    "+STR$(CAR_DIRECTION)
    SLIP_FRONT_RIGHT = DIRECTION_VEL_FRONT_RIGHT-CAR_DIRECTION
    MSGBOX STR$(SLIP_FRONT_RIGHT)
    
    END FUNCTION

    Problem is in the last few lines.
    DIRECTION_VEL_FRONT_RIGHT = about 120.9
    CAR_DIRECTION=0. These show up ok in the first MSGBOX. SLIP_FRONT_RIGHT is the difference between the two, it should be 120.9, but comes up as 0 for some reason. What's happening?

    Todd Wasson
Working...
X