Mapping

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

Moderator: roger

Mapping

Postby NuMatic » Thu May 03, 2007 7:20 pm

Hi, im new to this, but I think I followed your start up guide correctly.

I found a code on this website http://www.phptr.com/articles/article.asp?p=26439&seqNum=3&rl=1 Which enables you to display a map...

I copied the code, and im progressivly getting through it... as I've had no end of errors. Wondering if someone could have a look at my few problems left...

Note that im currently not using a tower or an rcx...


This code collects the mapping data

import josx.platform.rcx.*;
import josx.rcxcomm.*;
import josx.robotics.*;
import java.io.*;

class DataSender implements SensorListener
{
Navigator robot;
static final byte ARRAY_SIZE = 10;
public short [] xCoords;
public short [] yCoords;
byte count = 0;

public DataSender(Navigator robot)
{
this.robot = robot;

xCoords = new short [ARRAY_SIZE];
yCoords = new short [ARRAY_SIZE];

Sensor.S2.addSensorListener(this);
}

public static void main(String [] args) throws IOException
{
TimingNavigator robot = new TimingNavigator(Motor.C,Motor.A, 4.475f, 1.61f);
robot.forward();

DataSender ds = new DataSender(robot);
try
{
Button.RUN.waitForPressAndRelease();
robot.stop();
Button.VIEW.waitForPressAndRelease();
}
catch(InterruptedException ie){}

// Send data:
RCXDataPort port = new RCXDataPort(); - Cannot resolve symbol
DataOutputStream out = new DataOutputStream(port.getOutputStream());
out.writeShort(0);
out.writeShort(0);
for(byte i=0;i<ARRAY_SIZE;++i) {
out.writeShort(ds.xCoords[i]);
out.writeShort(ds.yCoords[i]);
}
out.flush();
}

/** Records the x, y position when bumper hits an object.*/
public void stateChanged(Sensor bumper, int oldValue, int newValue) {
{
if (bumper.readBooleanValue() == true) {
robot.stop();
if (count < ARRAY_SIZE) {
xCoords[count] = (short) robot.getX();
yCoords[count] = (short) robot.getY();
++count;
}
robot.travel( -20);
robot.rotate( (float) (Math.random() * 180));
robot.forward();
}
}
}
}

I think that error has something to do with no being able to find the class??


Displays Map
import java.io.*;
import pc.irtower.comm.*;
import java.awt.*;
import java.awt.event.*;

public class MapData() extends Canvas - expects {
{
int ARRAY_SIZE = 10;
short [] xCoords;
short [] yCoords;

public MapData() {
xCoords = new short[ARRAY_SIZE];
yCoords = new short[ARRAY_SIZE];
PCDataPort port = null;
try {
port = new PCDataPort("COM2");
DataInputStream in = new DataInputStream(port.getInputStream());
for(int i=0;i<ARRAY_SIZE;++i) {
xCoords[i] = in.readShort();
System.out.println("x = " + xCoords[i]);
yCoords[i] = in.readShort();
System.out.println("y = " + yCoords[i]);
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
}

public static void main(String [] args)
{

Frame mainFrame = new Frame("Explorer Command Center");
mainFrame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
mainFrame.setSize(400, 300);
mainFrame.add(new MapData());
mainFrame.setVisible(true);
}

public void paint(Graphics g)
{
int height = this.getSize().height;
int width = this.getSize().width;
g.setColor(Color.orange);
g.drawLine(width/2,0,width/2, height);
g.drawLine(0,height/2, width, height/2);
g.setColor(Color.black);
for(int i=0;i<ARRAY_SIZE-1;++i)
{
g.drawLine(xCoords[i] + width/2, yCoords[i] + height/2,
xCoords[i+1] + width/2, yCoords[i + 1]+height/2);
}
}
} - Expected {

This code is a bit funny... if i remove the () from the bold line after MapData, it brings errors to

import java.io.*;
import pc.irtower.comm.*;
import java.awt.*;
import java.awt.event.*;

public class MapData extends Canvas
{
int ARRAY_SIZE = 10;
short [] xCoords;
short [] yCoords;

public MapData() {
xCoords = new short[ARRAY_SIZE];
yCoords = new short[ARRAY_SIZE];
PCDataPort port = null;
try {
port = new PCDataPort("COM2");

but even more weird, is that lejosc compile on command gives 18 errors... and all are connot resolve symbol...

lol, I know this a bit messy... but Im sure someone would love to sort this out for me =D

Thanks for looking,
el_tomo - who is your daddy?
NuMatic
New User
 
Posts: 1
Joined: Thu May 03, 2007 6:22 pm

Return to RCX Software

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff