View unanswered posts | View active topics It is currently Thu Apr 24, 2014 5:06 pm






Reply to topic  [ 2 posts ] 
help what is wrong this code!! 
Author Message
Rookie

Joined: Mon Dec 12, 2011 2:10 am
Posts: 10
Post help what is wrong this code!!
Help me guys!... i have problem of this type of code! the common code in robotC and forums is about NXT to PC or NXT to NXT.. they have possible code to this project." NXT to Cellphone "?. tnx for link and reply",)

concept:

step 1: The lego mindstorm nxt identified the colors of object in field like (Green object, Yellow object and Blue is end point)

step 2: The lego mindstorm save the data gathered from the field given object.

step 3: After the lego mindstorm gathered and save the data and reach the sign of end point ("blue circle") inquiry the cellphone device given and trying to connect the blutooth and send.

step 4: The lego mindstorm send a message in cellphone of how many Green and Yellow object in field via bluetooth connection. waiting for the message in cellphone from NXT.

tnx guys, and to the admin for giving code and link",)

#pragma config(Sensor, S1, colorPort, sensorCOLORFULL)
#pragma config(Sensor, S2, compassSensor, sensorVirtualCompass)
#pragma config(Sensor, S3, lightSensor, sensorLightActive)
#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorB, rightMotor, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, leftMotor, tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
// This is for the NXT model, not TETRIX

/************************************\
|* ROBOTC Virtual World *|
|* *|
|* DO NOT OVERWRITE THIS FILE *|
|* MAKE SURE TO "SAVE AS" INSTEAD *|
\************************************/

long nElapsedTime = 0;
float fThroughput = 0;
long nSendTotal = 0;
long nSendGood = 0;
long nSendBad = 0;
long nSendBusy1 = 0;
long nSendBusy2 = 0;

long nRcvTries = 0;
long nReadCnt = 0;
long nReadBad = 0;

long nLastXmitTimeStamp = nPgmTime;
long nLastRcvdTimeStamp = nPgmTime;
long nDeltaTime = 0;

const int kTimestampHistogramSize = 41;
int nRcvHistogram[kTimestampHistogramSize];
int nXmitHistogram[kTimestampHistogramSize];

const int kTimeBetweenXmit = 30;

const int kMaxSizeOfMessage = 5;
const TMailboxIDs kQueueID = mailbox1;

void readDataMsg();

void sendDataMsg()
{
ubyte nXmitBuffer[kMaxSizeOfMessage] = {0x01, 0x02, 0x03, 0x04, 0x00}; // For NXT-G compatability, last byte of message must be zero because of string messsages.
const bool bWaitForReply = false;
TFileIOResult nBTCmdErrorStatus;

nxtDisplayTextLine(1, "Send %6d", nSendTotal);

nDeltaTime = nPgmTime - nLastXmitTimeStamp;
if (nDeltaTime < kTimeBetweenXmit)
{
nxtDisplayTextLine(2, "Bsy%6d %6d", nSendBusy1, ++nSendBusy2);
return;
}

if (bBTBusy)
{
nxtDisplayTextLine(2, "Bsy%6d %6d", ++nSendBusy1, nSendBusy2);
return;
}


nBTCmdErrorStatus = cCmdMessageWriteToBluetooth(nXmitBuffer, kMaxSizeOfMessage, kQueueID);
switch (nBTCmdErrorStatus)
{
case ioRsltSuccess:
case ioRsltCommPending:
nxtDisplayTextLine(3, "Send OK %6d", ++nSendGood);
nDeltaTime = nPgmTime - nLastXmitTimeStamp;
nLastXmitTimeStamp = nPgmTime;
if (nDeltaTime >= kTimestampHistogramSize)
nDeltaTime = kTimestampHistogramSize - 1;
++nXmitHistogram[nDeltaTime];
break;

case ioRsltCommChannelBad:
default:
nxtDisplayTextLine(4, "Send Bad %6d", ++nSendBad);
break;
}
return;
}

void checkBTLinkConnected()
{
if (nBTCurrentStreamIndex >= 0)
return;

PlaySound(soundLowBuzz);
PlaySound(soundLowBuzz);
eraseDisplay();
nxtDisplayCenteredTextLine(3, "BT not");
nxtDisplayCenteredTextLine(4, "Connected");
wait1Msec(3000);
StopAllTasks();
}

void readDataMsg()
{

const bool bWaitForReply = false;
TFileIOResult nBTCmdRdErrorStatus;
int nSizeOfMessage;
ubyte nRcvBuffer[kMaxSizeOfMessage * 5];

while (true)
{
nxtDisplayTextLine(5, "Rd Tries %6d", ++nRcvTries);

// Check to see if a message is available

nSizeOfMessage = cCmdMessageGetSize(kQueueID);
if (nSizeOfMessage <= 0)
{
wait1Msec(1); // Give other tasks a chance to run
break; // No message this time
}

if (nSizeOfMessage > kMaxSizeOfMessage)
nSizeOfMessage = kMaxSizeOfMessage;
nBTCmdRdErrorStatus = cCmdMessageRead(nRcvBuffer, nSizeOfMessage, kQueueID);
if (nBTCmdRdErrorStatus == ioRsltSuccess)
{

nDeltaTime = nPgmTime - nLastRcvdTimeStamp;
nLastRcvdTimeStamp = nPgmTime;
if (nDeltaTime >= kTimestampHistogramSize)
nDeltaTime = kTimestampHistogramSize - 1;
++nRcvHistogram[nDeltaTime];
// Keep a running count of the number of messages successfully read
nxtDisplayTextLine(6, "Read OK %6d", ++nReadCnt);
fThroughput = nElapsedTime / (float) nReadCnt;
}
else
nxtDisplayTextLine(7, "Read Bad %6d", ++nReadBad);
}
return;
}

void sendMessages()
{
//
// Send and receive 1M messages
//
for (nSendTotal = 0; nSendTotal < 1000000; ++nSendTotal)
{
checkBTLinkConnected();
sendDataMsg();
readDataMsg();
nElapsedTime = nPgmTime;
wait1Msec(1);
}
}

task main()
{
string sColor;
int msgSize;
byte msg[58];
while (true)
{
switch (SensorValue[colorPort])
{
case BLUECOLOR: sColor = "Blue"; break;
case GREENCOLOR: sColor = "Green"; break;
case YELLOWCOLOR: sColor = "Yellow"; break;
default: sColor = "???"; break;
}
nxtDisplayCenteredTextLine(3, sColor);
wait1Msec(50);
//lego to pc connection/////
nxtDisplayTextLine(1, "%3d, %3d",cCmdBTCheckStatus(0));
// check for a BT connection
switch (cCmdBTCheckStatus(0))
{
case(ioRsltSuccess):
// connected;
nxtDisplayTextLine(2," Connected");
// check for msg in mailbox1;
msgSize=cCmdMessageGetSize(mailbox1);
if (msgSize>0)
{
cCmdMessageRead(msg, msgSize, mailbox1);
nxtDisplayTextLine(3, msg);
}
break;
case(ioRsltCommChannelNotReady):
// not connected;
nxtDisplayTextLine(2,"Disconnected");
break;
default:
// Other condition;
nxtDisplayTextLine(2, "%3d, %3d",cCmdBTCheckStatus(0));
break;
}
wait1Msec(10);
}
////connection pc to cellphone//////
bNxtLCDStatusDisplay = true;
memset(nRcvHistogram, 0, sizeof(nRcvHistogram));
memset(nXmitHistogram, 0, sizeof(nXmitHistogram));
wait1Msec(2000);
sendMessages();
return;
}

tnx for helping me...


Last edited by rohan28 on Tue Jan 31, 2012 3:18 pm, edited 2 times in total.



Tue Jan 17, 2012 3:17 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: help what is wrong this code!!!... hel me
Rohan,

Tell us what the problem is instead of just typing the code. You're not giving us any clues here.

The more information you give us, the better we're able to help you.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 17, 2012 3:25 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.