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 / 27008
27007  |  27009
Subject: 
I need help with a method in my class RADAR
Newsgroups: 
lugnet.robotics
Date: 
Sun, 1 Apr 2007 15:29:48 GMT
Original-From: 
Juan Antonio BreñaMoral,JAB, www.juanantonio.info <bren@juanantonio.+antispam+info>
Viewed: 
4222 times
  
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 distance){
float CX;
CX = 0;

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

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

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

this methods are used to know the coordenate X and Y to set a pixel in the
interface.

My code is:

//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){
float CX;
CX = 0;

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

    /*
    public static int getCoordenateY(int angle,int distance){
float CY;
CY = 0;

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

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 sonic = new UltrasonicSensor(SensorPort.S1);

drawBackground(g);

int value;
value = 0;
int degree;
int distance;

while(!Button.ESCAPE.isPressed()){
value = sonic.getDistance();
distance = value;

if(value <= 20){
Sound.playTone(50, 100);
}
value = (int) compass.getDegreesCartesian();
degree = value;

g.setPixel(1,0,0);
g.refresh();

value = (int)(Runtime.getRuntime().freeMemory());
LCD.drawInt(value,0,7);

//int X;
//double XX;
//X = getCoordenateX(degree, distance);
//X = XX.round();

//LCD.drawInt(X,0,6);

LCD.refresh();

Motor.A.setPower(80);
Motor.A.rotate(15);

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

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

You can see the output in my site: http://www.juanantonio.info/jab_cms.php?id=93

Thanks.

Juan Antonio Breña Moral
www.juanantonio.info



Message has 2 Replies:
  Re: I need help with a method in my class RADAR
 
Currently, My methods runs, but the algorithm doesn run well; //Import NXJ Packages import java.util.*; import lejos.nxt.*; import javax.microedition.l....Graphics; /* NXT LCD Dimensions: Width: 100px; 0-99 -> 50 Height: 64px; 0-63 -> 32 */ public (...) (17 years ago, 1-Apr-07, to lugnet.robotics)
  Re: I need help with a method in my class RADAR
 
Hi Guys, At the end, I finished the class. I read some useful calculus from Krystian Majewski, (URL) source code is here: (URL) abrazo (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