To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 27009
27008  |  27010
Subject: 
Re: I need help with a method in my class RADAR
Newsgroups: 
lugnet.robotics
Date: 
Sun, 1 Apr 2007 16:15:56 GMT
Original-From: 
Juan Antonio BreñaMoral,JAB, www.juanantonio.info <bren@ANTISPAMjuanantonio.info>
Viewed: 
4213 times
  
Currently, My methods runs, but the algorithm doesn run well;

//Import NXJ Packages
import java.util.*;
import lejos.nxt.*;
import javax.microedition.lcdui.Graphics;

/*
NXT LCD Dimensions:
Width: 100px; 0-99 -> 50
Height: 64px; 0-63 -> 32
*/

public class RADAR1_1 {

//Draw Radar Interface
public static void drawBackground(Graphics gObj){
gObj.drawArc(50-10, 32-10, 20,20,0,360);
gObj.drawArc(50-20, 32-20, 40,40,0,360);
gObj.drawArc(50-30, 32-30, 60,60,0,360);

//X Axis
for(int i=15;i<=85;i++){
gObj.setPixel(1,i,32);
}

//Y Axis
for(int j=0;j<=64;j++){
gObj.setPixel(1,50,j);
}

gObj.refresh();
}

/*
*
* B       C
*  * * * *
*  *    *
*  *   *
*  *  *
*  * *
*  *
* A
*
* A: has compass angle and the coordenates are: 50,32;
* AB: is the ultrasonic sensor value; HIPOTENUSE
* B: 90º
* C: ?
* A+B+C = 180;
*/

    public static int getCoordenateX(int angle,int distance){
double CX;
CX = 0;

    //Coordenadas 0 en eje de X;
    int initX = 50;
    CX = initX+distance;
    double part3;
    double part2;
    part2 = angle * Math.PI/180;
    part3 = Math.sin(part2);
    CX = CX * part3;
return Math.round((float) CX);
    }

    public static int getCoordenateY(int angle,int distance){
double CY;
CY = 0;

    //Coordenadas 0 en eje de Y;
    int initY = 32;
    CY = initY-distance;
    double part2;
    part2 = angle * Math.PI/180;
    double part3 =
    part3 = Math.cos(part2);
    CY = CY * part3;
return Math.round((float) CY);
    }


public static void credits(){
LCD.clear();
LCD.drawString("Juan Antonio",0,1);
LCD.drawString("Brenha. Moral",0,2);
LCD.drawString("juanantonio.info",0,3);
LCD.refresh();
}


public static void main(String [] options) throws Exception {
//Instances
Graphics g = new Graphics();
CompassSensor compass = new CompassSensor(SensorPort.S2);
UltrasonicSensor us = new UltrasonicSensor(SensorPort.S1);

Motor.A.setSpeed(900);
Motor.A.setPower(100);

drawBackground(g);

int degree;
int distance;
int memory;

while(!Button.ESCAPE.isPressed()){
distance = us.getDistance();
degree = (int) compass.getDegreesCartesian();
memory = (int)(Runtime.getRuntime().freeMemory());

if(distance <= 60){
Sound.playTone(50, 100);
}

int X;
int Y;
//Interface show obstacles with a distance in range 60cm.
if(distance <=60){
X = getCoordenateX(degree, distance);
Y = getCoordenateY(degree, distance);
g.setPixel(1,X,Y);
g.refresh();
}

//Is better to put LCD commands after the commands using Graphics Class
LCD.drawInt(distance,0,5);
LCD.drawInt(degree,0,6);
LCD.drawInt(memory,0,7);
LCD.refresh();

Motor.A.forward();//rotate(15);

//2007/04/01
//If section because NXJ doesn't have Garbaje Collector
if(memory <= 3000){
break;
}
}
//Stop Gyroscope System
Motor.A.stop();

credits();
Thread.sleep(2000);
}
}



Message is in Reply To:
  I need help with a method in my class RADAR
 
Hello guys, Yesterday, started to program with new NXJ realease. Currently I am developing a Radar Interface using Hitechnics Compass Sensor and Ultrasonic Sensor. I need your help with 2 methods: public static int getCoordenateX(int angle,int (...) (17 years ago, 1-Apr-07, to lugnet.robotics)

3 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