Assignment

Post your NXJ projects, project ideas, etc here!

Moderators: roger, 99jonathan, imaqine

Assignment

Postby kacper » Thu Nov 03, 2011 9:47 am

Hi, Our group has a big problem, because we dont know how to program our robot. He should create a program which has 10 operation set by us. After that he need to do it when we will push red button . We have to set his distance, speed and rotation speed. Below is exactly our assignment. Im waiting for some tips.


Programmable robot
In the second compulsory exercise in LRL I1 your group must build a programmable car robot. It
must be possible to program predefined route into it, and then the robot must follow this route.
A route is defined by a number of data sets each containing an angle, a speed and a distance that the
robot must execute.
The programming of the route must be done via the LCD display and the buttons on the NXT brick,
thus the user must be guided via text on the display.
The steps that your robot must be able to do are shown in the activity diagram.
The first step is to capture the route via the LCD display and buttons.
The robot must be able to take any number of datasets between one
and 10 sets.
A dataset contains:
1. Angle (-180..180)
2. Speed (0-100%)
3. Distance (0..100cm)
When the user has put in the number of datasets he/she wants he/she
activates a Route finished key. After that the robot waits for a start
signal from the user. When the start signal is given, the robot must
start executing the route. The steps that must be done to execute the
route are:
1. Turn the robot to the angle in the dataset.
2. Move the distance specified in the dataset, the speed must be
the one specified in the dataset.
3. If there are more datasets in the route go to 1
Note: You are not allowed to use Pilot, Robot, Behaviour or
classes like these. You may only use simple classes like MotorPort, LCD etc.
The software must be designed and implemented with more than one class, and must be
documented with class and activity diagrams.
kacper
New User
 
Posts: 2
Joined: Thu Nov 03, 2011 9:32 am

Re: Assignment

Postby skoehler » Thu Nov 03, 2011 12:36 pm

kacper wrote:Hi, Our group has a big problem, because we dont know how to program our robot. He should create a program which has 10 operation set by us. After that he need to do it when we will push red button . We have to set his distance, speed and rotation speed. Below is exactly our assignment. Im waiting for some tips.


You should probably start reading something and learn how to figure this one out by yourself.
Your supervisor will probably also be very helpful in pointing out good literature.
skoehler
leJOS Team Member
 
Posts: 1108
Joined: Thu Oct 30, 2008 4:54 pm

Re: Assignment

Postby kacper » Sat Nov 19, 2011 6:57 pm

ok , i tried to do it alone but it is to difficult for me ... ; / i should do it in 2 files but i dont have idea how and i have second problem, I dont know how to set this that program wait for me and dont run a program until when i push the button Escape ... i tried in second part if ( button.Escape.isPressed()) but then program turn off everything and didnt wait. so please help me because my supervisior dont want ot help .. .






import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Motor;

public class l1
{

public static void main(String[] args)
{

int[] speed = new int[4];
// speed[i]=speed*10;

int[] angle = new int[4];
// angle[i]=4.7*angle;

int[] distance = new int[4];
// distance[i]=35*distance;

for (int i = 0; i < 4; i++)
{
angle[i] = 0;
speed[i] = 0;
distance[i] = 0;

do
{
LCD.drawInt((i + 1), 5, 1);
LCD.drawString("Speed: " + speed[i], 1, 2);

if (Button.RIGHT.isPressed())
{
speed[i] = speed[i] + 10;
LCD.refresh();
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

else if (Button.LEFT.isPressed())
{
speed[i] = speed[i] - 10;
LCD.refresh();
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

}
while (!(Button.ENTER.isPressed()));

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

LCD.clearDisplay();

do
{
LCD.drawInt((i + 1), 5, 1);
LCD.drawString("Angle: " + angle[i], 1, 2);

if (Button.RIGHT.isPressed())
{
angle[i] = angle[i] + 10;
LCD.refresh();

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

else if (Button.LEFT.isPressed())
{
angle[i] = angle[i] - 10;
LCD.refresh();

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

}
}
while (!(Button.ENTER.isPressed()));

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

LCD.clearDisplay();

do
{
LCD.drawInt((i + 1), 5, 1);
LCD.drawString("Distance: " + distance[i], 1, 2);

if (Button.RIGHT.isPressed())
{
distance[i] = distance[i] + 10;
LCD.refresh();

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}

else if (Button.LEFT.isPressed())
{
distance[i] = distance[i] - 10;
LCD.refresh();

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

}
}
while (!(Button.ENTER.isPressed()));

try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}

LCD.clearDisplay();

}

for (int i = 0; i < 4; i++)
{
LCD.drawString("Activity nr " + (i + 1), 3, 3);

if (angle[i] > 0)
{
do
{
Motor.A.forward();
Motor.A.setSpeed(speed[i] * 4);
Motor.C.backward();
Motor.C.setSpeed(speed[i] * 4);

}
while (Motor.A.getTachoCount() < angle[i] * 5);

try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Motor.A.resetTachoCount();
do
{
Motor.A.forward();
Motor.A.setSpeed(speed[i] * 4);
Motor.C.forward();
Motor.C.setSpeed(speed[i] * 4);

}
while (Motor.A.getTachoCount() < distance[i] * 35);

try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Motor.A.resetTachoCount();
}
else if (angle[i] == 0)
{
do
{
Motor.A.forward();
Motor.A.setSpeed(speed[i] * 4);
Motor.C.forward();
Motor.C.setSpeed(speed[i] * 4);

}
while (Motor.A.getTachoCount() < distance[i] * 35);

try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Motor.A.resetTachoCount();
}
else
{
do
{
Motor.A.backward();
Motor.A.setSpeed(speed[i] * 4);
Motor.C.forward();
Motor.C.setSpeed(speed[i] * 4);

}
while (Motor.A.getTachoCount() > angle[i] * 5);

try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Motor.A.resetTachoCount();
do
{
Motor.A.forward();
Motor.A.setSpeed(speed[i] * 4);
Motor.C.forward();
Motor.C.setSpeed(speed[i] * 4);

}
while (Motor.A.getTachoCount() < distance[i] * 25);

try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
Motor.A.resetTachoCount();
}

}
}
}
kacper
New User
 
Posts: 2
Joined: Thu Nov 03, 2011 9:32 am


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff