View unanswered posts | View active topics It is currently Wed Aug 05, 2020 10:03 am






Reply to topic  [ 1 post ] 
Bluetooth acceleration steering between 2 NXT 
Author Message
Rookie

Joined: Sun Apr 10, 2011 5:09 am
Posts: 1
Post Bluetooth acceleration steering between 2 NXT
Hello!

I've made an robot using 2 NXT.
One is for the belts with 2 motors, 1 touch sensor and 1 accelerator. This work that if I press down the touch sensor I can use the accelerator and steer the belts.

The other NXT is for the tower that acts like a ballshooter. 3 motors, 1 touch sensor an 1 accelerator. I use 2 motors to turn the tower horisontal and vertical with the accelerator, and 1 motor to fire the balls with the touch sensor.

In other words I can have one controll in each hand to steer the tank :)

Now I got 2 more NXT brains I would like to use as a remote control with bluetooth connection so I don't have to follow the robot as its driving. But I don't know how to program this 4 NXT's so 2 of them are master with 1 slave each.. Can someone help me?

Here is the code for the TOWER in .c:

#pragma config(Sensor, S1, fire, sensorTouch)
#pragma config(Sensor, S2, HTAC, sensorLowSpeed)
#pragma config(Motor, motorA, Elevation, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, Rotation, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, fire, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "common.h"
#include "HTAC-driver.h"

task main ()
{
PlaySoundFile("waz.rso");
while (1)


{
int _x_axis1 = 0;
int _y_axis1 = 0;
int _z_axis1 = 0;
int steer=0;



// It's better to read them all at once, if you want to know
// all of them anyway. It is a lot more efficient.
if (!HTACreadAllAxes(HTAC, _x_axis1, _y_axis1, _z_axis1)) {
nxtDisplayTextLine(4, "ERROR!!");
wait1Msec(2000);
StopAllTasks();
}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//fire
if(SensorValue(fire) == 1)
{PlaySoundFile("got.rso");
wait10Msec(10);
steer=1;}

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//rotate right
else if(_y_axis1 > 30 && _y_axis1 <200)
steer=2;

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//rotate left
else if(_y_axis1>-200 && _y_axis1 <-30)
steer=3;


//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//tilt backwards
else if(_z_axis1>-200 && _z_axis1 <-30)
steer=4;


//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//tilt forwards
else if(_z_axis1 > 30&& _z_axis1 < 200)
steer=5;



//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

switch ( steer )
{
case 1:
motor[motorC] = -100;
wait1Msec(370);
motor[motorC] = 0;
break;
case 2:
{motor[motorB]=-6;};
break;

case 3:
{motor[motorB]=6;};
break;

case 4:
{motor[motorA]=-7;}
break;
case 5:
{motor[motorA]=7;}
break;

default:
{motor[motorA]=0;
motor[motorB]=0;
motor[motorC]=0;}
break;
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
}


And here is the code for the BELTS:

#pragma config(Sensor, S1, MSAC, sensorLowSpeed)
#pragma config(Sensor, S2, kill, sensorTouch)
#pragma config(Sensor, S4, light, sensorTouch)
#pragma config(Motor, motorA, left, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, right, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "common.h"
#include "MSAC-driver.h"

task main ()
{
int _x_tilt = 0;
int _y_tilt = 0;
int _z_tilt = 0;
int steer=0;

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXHovedprogramXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
while (1)
{
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MSACsetRange(MSAC, MSAC_RANGE_10);
//PlaySound(soundBeepBeep);
//while(bSoundActive);
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Read the tilt data from the sensor
if (!MSACreadTilt(MSAC, _x_tilt, _y_tilt, _z_tilt))
{
nxtDisplayTextLine(4, "ERROR!!");
wait1Msec(2000);
StopAllTasks();
}
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if (SensorValue[kill]==0)
steer=0;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//rotate right
else if(_y_tilt < -8 && _y_tilt > -22)
steer=2;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//rotate left
else if(_y_tilt>8 && _y_tilt <31)
steer=4;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//drive backwards
else if (_z_tilt>10 && _z_tilt<25)
steer=7;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//drive forwards
else if(_z_tilt < -15&& _z_tilt > -30)
steer=8;
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
switch ( steer )
{
case 0:
{motor[motorA]=0;
motor[motorC]=0;}
break;

case 2:
{motor[motorA]=100;
motor[motorC]=-20;}
break;

case 4:
{motor[motorA]=-20;
motor[motorC]=100; }
break;

case 7:
{motor[motorA]=-100;
motor[motorC]=-100; }
break;

case 8:
{motor[motorA]=100;
motor[motorC]=100; }
break;

default:
{motor[motorA]=0;
motor[motorC]=0;}
break;
}
}
}


Can someone please tell me how to integrate each program with bluetooth? I need one program for master and one for slave for each program ;)


Sun Apr 10, 2011 5:31 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.