Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

NXC simulator


  • Please log in to reply

#1
thelostlaurens

thelostlaurens

    New Member

  • Member
  • Pip
  • 7 posts
Hi! I have this school project to let a robot drive over a "map"
Posted Image

the robot is not allowed to cross the 2nd thingy.

I was wondering if there was a way to test this on my pc, since we have to hand it in on tuesday, and it'd be nice if it worked :D
I thought it was possible with windows robotics studio (or something like that) but I downloaded it, and I don't really get how I should be supposed to do that.

so, help would be quite welcome :D you can test it for me aswell if that's easier, it's not like I want to be able to test it myself, I want to be sure that it works ;)

this is the script I made:

mutex moveMutex;
#define m1 50 //move speed 1 (forward motor 1)
#define m2 55 //move speed 2 (forward motor 2)
#define m3 70 //move speed 3 (turn motor)

#define w1 100 //wait time 1 (forward)
#define w2 900 //wait time 2 (90)
#define w3 1800 //wait time 3 (180)

#define Z 12 // off the line
#define R 4 // red's value
#define G 5 // yellow's value

#define d 7 // distance from robot to object

int r; //number of times robot passed red
int g; //number of times robot passed yellow

task rijden() //standard drive task
{
Acquire(moveMutex);
OnFwd(OUT_A,m1);
OnFwd(OUT_C,m2);
Wait(w1);
Float(OUT_AC);
Release(moveMutex);
}

task lijn() //checks if the robot's still on the line, if not it corrects
{
Acquire(moveMutex);
if (SensorUS(IN_1) == Z)
{
OnFwd(OUT_A,m2);
OnFwd(OUT_c,m1);
Wait(w1);
Float(OUT_AC);
}
Release(moveMutex);
}

task afstand() // checks if there's something in front of the robot
{
Acquire(moveMutex);
if (SensorUS(IN_2) <= d)
{
Off(OUT_AC);
Wait(w1);
}
Release(moveMutex);
}

task kleur() //checks if our robot is on a color
{
if (SensorUS(IN_1) == R)
{
r=r+1;
}
if (SensorUS(IN_1) == G)
{
g=g+1;
}
}

task rood() //does stuff for certain values of red
{
Acquire(moveMutex);
switch®
{
case 2: //turn to the right
OnFwd(OUT_A,m3);
OnRev(OUT_C,m3);
Wait(w2);
Off(OUT_AC);
break;
case 3: //180
OnFwd(OUT_A,m3);
OnRev(OUT_C,m3);
Wait(w3);
Off(OUT_AC);
break;
case 4: //turn left
OnFwd(OUT_C,m3);
OnRev(OUT_A,m3);
Wait(w2);
Off(OUT_AC);
break;
}
Release(moveMutex);
}

task geel() //does stuff for different values of yellow
{
Acquire(moveMutex);
switch(g)
{
case 1: //turns left
case 8:
case 5:
case 6:
OnFwd(OUT_C,m3);
OnRev(OUT_A,m3);
Wait(w2);
Off(OUT_AC);
break;
case 3: //180
OnFwd(OUT_A,m3);
OnRev(OUT_C,m3);
Wait(w3);
Off(OUT_AC);
break;
case 7: //forbidden cross over
OnFwdReg(OUT_AC,m1, OUT_REGMODE_SYNC);
Wait(w1);
Off(OUT_AC);

OnFwd(OUT_A,m3);
OnRev(OUT_C,m3);
Wait(w3);
Off(OUT_AC);

OnFwdReg(OUT_AC,m1, OUT_REGMODE_SYNC);
Wait(w1);
Off(OUT_AC);
break;
}
Release(moveMutex);
}

task main()
{
SetSensorLowspeed(IN_1);
SetSensorUltrasonic(IN_2);
r = 0;
g = 0;
while (r != 5)
{
Precedes(rijden, lijn, afstand, kleur, geel, rood);
}
}
  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP