View unanswered posts | View active topics It is currently Thu Apr 24, 2014 11:16 am






Reply to topic  [ 5 posts ] 
Problems with retrieving sensor values 
Author Message
Rookie

Joined: Mon Oct 10, 2011 4:46 pm
Posts: 15
Post Problems with retrieving sensor values
When using the following code and looking at the RobotC debug window it appears that it accepts one set of readings and then just sits with no new values

Code:
#pragma config(Sensor, S1,     Left,           sensorSONAR)
#pragma config(Sensor, S2,     Center,         sensorSONAR)
#pragma config(Sensor, S3,     Right,          sensorSONAR)
#pragma config(Sensor, S4,     Light,          sensorLightInactive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
int L=0;
int C=0;
int R=0;
int Lht=0;
task main()
{
  while(true)
  {
    L=SensorValue(Left);
    C=SensorValue(Center);
    R=SensorValue(Right);
    Lht=SensorValue(Light);
  ubyte valueToSend[4];
      valueToSend[0] = L;
      valueToSend[1] = C;
      valueToSend[2] = R;
      valueToSend[3] = Lht;
      cCmdMessageWriteToBluetooth(valueToSend, 4,mailbox1);
   }
}


Fri Jun 22, 2012 2:28 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 537
Post Re: Problems with retrieving sensor values
I'm looking into this right now for you, in the meantime what are you transmitting to? Another NXT brick or a different Bluetooth receiver?

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Fri Jun 22, 2012 3:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3116
Location: Rotterdam, The Netherlands
Post Re: Problems with retrieving sensor values
Well, for one, it's SensorValue[<port>], not (), so you might want to fix that part first.

- 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]


Fri Jun 22, 2012 5:00 pm
Profile WWW
Rookie

Joined: Mon Oct 10, 2011 4:46 pm
Posts: 15
Post Re: Problems with retrieving sensor values
Just fixed the brackets thanks, I had a brain fart and its still doing it. I am using this to stream sensor data to another NXT.


Sun Jun 24, 2012 10:40 pm
Profile
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Problems with retrieving sensor values
ferret_guy wrote:
Just fixed the brackets thanks, I had a brain fart and its still doing it. I am using this to stream sensor data to another NXT.


Using bluetooth has been incredibly frustrating. I have no idea how much of it is NXT v. just plain Bluetooth issues, but I manage to lock up my PC, and/or the NXT at a rate of about 65 times per hour.
Anyhow, here is what I am using currently, which minumizes the lockups to only 65 an hour;

Code:
task BroadcastPose()
{
    nSchedulePriority = 5;  // lower than 'default'
    ubyte xmitBuff[12];
    while (true)
    {
        // live data logging
        int x;
        memcpy(xmitBuff[0], "PO", 2);
        x = time1[T1]; memcpy(xmitBuff[2], x, 2);
        x = nMotorEncoder[LEFT]; memcpy(xmitBuff[4], x, 2);
        x = nMotorEncoder[RIGHT]; memcpy(xmitBuff[6], x, 2);
        x = HTMCreadHeading(COMPASS); memcpy(xmitBuff[8], x, 2);
        x = 0; memcpy(xmitBuff[10], x, 2); // reserved for IMU heading
        while (bBTBusy) wait1Msec(10);
        //??cCmdMessageAddToQueue(0, xmitBuff, sizeof(xmitBuff));
        cCmdMessageWriteToBluetooth(xmitBuff, sizeof(xmitBuff), mailbox1);
        while (nBluetoothCmdStatus == ioRsltCommPending) wait1Msec(2);

        wait1Msec(1000);
    }
}


Notice a few waits in there. I can tell you the switch from transmit to receive is a huge hit, and so you are much better off ONLY doing one way communications which this is not. Even though you are only sending data, the NXT waits for a readMail request, before it sends. That is a transition. I'm currently re-implementing it using raw blueTooth, and one way only.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon Jun 25, 2012 2:34 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.