View unanswered posts | View active topics It is currently Thu Aug 28, 2014 10:26 pm






Reply to topic  [ 6 posts ] 
Bluetooth startProgram 
Author Message
Rookie

Joined: Thu May 17, 2012 3:35 pm
Posts: 35
Post Bluetooth startProgram
Hello

Is it possible to start a Program from another NXT? I´ve connectet both NXT and its working. Im searching for a code like: RemoteStartProgram

Please help me

Thanks

Now, I tried a little bit. - I´ve got another Problem!
My Master send:
Code:
#pragma config(Sensor, S2, HTEOPD,  sensorAnalogActive)
#pragma config(Sensor, S4,     touchSensor1,   sensorTouch)

#include "drivers/HTEOPD-driver.h"

task main()
{
   int x = 0;
   SetSensorType(S2, sensorLightActive);
   wait1Msec(100);
   SetSensorMode(S2, modeRaw);
   wait1Msec(100);

  while(true)
    {
      eraseDisplay();
      x = SensorRaw[S2];
      nxtDisplayTextLine(0, "%4d", x);
      wait1Msec(100);
     
      if(SensorValue(HTEOPD) > 45)
      {
       PlaySound(soundBeepBeep); //Just for fun and testing
      wait1Msec(200);
 
      int my_number = 23;

      sendMessage(my_number);
      }
   
    if (SensorValue(touchSensor1) == 1)
    {
      int my_number2 = 70;
      wait1Msec(3000);
      my_number2 = 70;
      sendMessage(my_number2);
    }
    }
}


The EOPD sends one Message to the Slave: 23,
when the touchSensor is pressed the 17 and two motors should start.


Slave:
Code:
#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Motor,  mtr_S1_C1_1,     motorD, tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE, tmotorNormal, openLoop)



task DriveForward();

task DriveForward()
{
   motor[motorD] = 65;
   motor[motorE] = 65;
   wait1Msec(1000);
}


task main()
{
  int my_message;
  int my_message2;
 
  while(true)
   {
    //Read the message to variable
      my_message = message;
      my_message2 = message;
     
      if(my_message != 0) //Let's say something got through if the signal is not zero
      {
          nxtDisplayTextLine(2,"1: %d",my_message); //Display the value as stored in the variable
          ClearMessage(); //Clear
      }
           
      wait1Msec(500); //Checking for a message every half a second is

      if(my_message2 != 0)
      {
        StartTask(DriveForward);
        nxtDisplayTextLine(4,"2: %d",my_message2); //Display the value as stored in the variable
        ClearMessage(); //Clear   
       
      } 
    } 
}


Question: The motors always run when the EOPD sends 23 or the touchSensor is 70. They don´t stop.
Where is the mistake?

Thanks


Wed Aug 01, 2012 11:56 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Bluetooth startProgram
Hey there,

You say your motors don't stop but where is the code to stop them? :)

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


Thu Aug 02, 2012 12:40 am
Profile WWW
Rookie

Joined: Thu May 17, 2012 3:35 pm
Posts: 35
Post Re: Bluetooth startProgram
Sry. Like this? :

Code:
if(my_message2 != 0)
      {
        StartTask(DriveForward);
        wait1Msec(500);
StopTask(DriveForward);
        nxtDisplayTextLine(4,"2: %d",my_message2); //Display the value as stored in the variable
        ClearMessage(); //Clear   
       
      } 


.

But my question is: The motors always run when the EOPD sends 23 or the touchSensor is 70. They only should run, if the message is 70.

When the Slave gets the 23, another task should start (not in the code yet), but the motors start running.


Thu Aug 02, 2012 3:50 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3196
Location: Rotterdam, The Netherlands
Post Re: Bluetooth startProgram
What do you think will happen when this finishes:
Quote:
task DriveForward()
{
motor[motorD] = 65;
motor[motorE] = 65;
wait1Msec(1000);
}

?

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


Thu Aug 02, 2012 3:56 am
Profile WWW
Rookie

Joined: Thu May 17, 2012 3:35 pm
Posts: 35
Post Re: Bluetooth startProgram
ok.

Like this?

Code:
task DriveForward()
{
motor[motorD] = 65;
motor[motorE] = 65;
wait1Msec(1000);
motor[motorD] = 0;
motor[motorE] = 0;
}


But how can I stop the message 70? when the tastSensor is pressed the master should send once 70 to start the program in slave


Thu Aug 02, 2012 12:12 pm
Profile
Rookie

Joined: Thu May 17, 2012 3:35 pm
Posts: 35
Post Re: Bluetooth startProgram
hello

Thanks. Now its working. Question:

I search for a "stop send message". is this possible?

The robot should send only one message once: (I used wait1Msec for this.

Code:
      if(SensorValue(HTEOPD) > 45)
      {
       PlaySound(soundBeepBeep); //Just for fun and testing
      wait1Msec(200);

      int my_number = 23;

      sendMessage(my_number);
      wait1Msec(10000);    //  stop sending with time
      }


Fri Aug 03, 2012 11:57 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.