View unanswered posts | View active topics It is currently Sun Dec 21, 2014 7:25 am






Reply to topic  [ 5 posts ] 
Remote Control with NXT-Bee 
Author Message
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Remote Control with NXT-Bee
My class is currently working on a project with the NXT-Bee. We've succesfully created a remote control with one NXT (master) controlling another (slave). The master uses two touch sensors and the NXT buttons as commands for the other robot. As an extension, I wanted the students to program the slave robot to send the encoder values to the master robot and have the encoder values displayed. That is where we are having problems. The code is below; any help would be appreciated. Thanks,

Master:

Code:
#pragma config(Sensor, S1,     leftTouch,      sensorTouch)
#pragma config(Sensor, S2,     rightTouch,     sensorTouch)
#pragma config(Sensor, S3,     backwards,      sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

// master robot is the remote control

#include "XbeeTools.h"
// include the function:XbeeTools

task main()
{
   InitRS485();

   string messageToSend="";  //Creates an empty string to store the message to send in
   string sendNextMessage=""; //Creates an empty string to store the response message in

   string leftEncoderCount = "Calculating";
   string rightEncoderCount = "Calculating";

   while(true)
   {
      if(SensorValue(rightTouch)==1)//if the sensor value of the right touch is equal to 1, robot adds "R" to messageToSend
         strcat(messageToSend, "R");  //forward right motor

      else//or else it adds "1" to the messageToSend
         strcat(messageToSend, "1");  //stop right motor

      if (SensorValue(leftTouch)==1)//if the sensor value of the left touch is equal to 1, robot adds "L" to messageToSend
         strcat(messageToSend, "L");  // Add "R" to the messageToSend

      else//or else it adds "2" to the messageToSend
         strcat(messageToSend, "2");   // off left motor

      if (SensorValue(backwards)==1) //if the sensor value of the 3rd touch is equal to 1, robot adds "B" to messageToSend
         strcat(messageToSend, "B");  // backward motor

      else//or else it adds "3" to the messageToSend
         strcat(messageToSend, "3");  // off both motors

      if (nNxtButtonPressed == 1) //If the NXT button 1 is pressed, adds
         strcat(messageToSend, "C"); //Close Arm motor

      else if (nNxtButtonPressed==2) //Else it adds '4' to the messageToSend
         strcat(messageToSend, "4"); //Open Arm motor

      SendString(messageToSend); //Sends the message to the second robot.

      ReceiveString(sendNextMessage); //Receives go-ahead message "OK" from second bot
      while(sendNextMessage != "OK")  //Until that happens, keep checking for messages
      {
         ReceiveString(sendNextMessage); // Receive message
         nxtDisplayTextLine(1, "Send? ", sendNextMessage); //Display message
         wait1Msec(10);
      }
      sendNextMessage = "No"; //Changes value of the 'sendNextMessage' string

      ReceiveString(leftEncoderCount); //Receives go-ahead message "OK" from second bot
      while(leftEncoderCount == "Calculating")  //Until that happens, keep checking for messages
      {
         ReceiveString(leftEncoderCount); // Receive message
         nxtDisplayTextLine(3, "LEncoder: ", leftEncoderCount); //Display message
         wait1Msec(10);
      }
      SendString("OK");

      ReceiveString(rightEncoderCount); //Receives go-ahead message "OK" from second bot
      while(rightEncoderCount == "Calculating")  //Until that happens, keep checking for messages
      {
         ReceiveString(rightEncoderCount); // Receive message
         nxtDisplayTextLine(5, "REncoder: ", rightEncoderCount); //Display message
         wait1Msec(10);
      }
      SendString("OK");

   }


}


Slave:
Code:
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "XbeeTools.h"
//master robot is the remote control

task main()
{
   InitRS485();
   //initaliting the motor
   string messageReceived = "None";
   //the string variable for the mesage receieved
   string leftEncoderCount;
   string rightEncoderCount;

   nMotorEncoder[motorC]=0;
   nMotorEncoder[motorB]=0;

   while(true)
   {

      ReceiveString(messageReceived); //this is the robot receiving the message

      while(messageReceived == "None")
      {
         ReceiveString(messageReceived); //this is the robot receiving the message
         motor[motorA]=0;
         motor[motorB]=0;
         motor[motorC]=0;
         wait1Msec(10);
      }

      if(StringFind(messageReceived, "B") == 2) //If the third character (index 2) is a B
      {
         motor[motorB] = -100;
         motor[motorC] = -100;
      }

      else if (StringFind(messageReceived, "3") == 2) //else, if the first character is a 3
      {

         if(StringFind(messageReceived, "R") == 0) //If the first character (index 0) is an R
         {
            motor[motorB] = 100; //Turn motorB on at 100 power
         }
         else if (StringFind(messageReceived, "1") == 0) //else, if the first character is a 1
         {
            motor[motorB] = 0; //Turn motorB off
         }

         if(StringFind(messageReceived, "L") == 1) //If the second character (index 1) is an L
         {
            motor[motorC] = 100; //Turn motorC on at 100 power
         }
         else if (StringFind(messageReceived, "2") == 1) //else, if the second character is a 2
         {
            motor[motorB] = 0; //Turn motorC off
         }
      }

      if(StringFind(messageReceived, "C") == 3) //If the fourth character (index 3) is an C
      {
         motor[motorC] = 50; //Turn motorC on at 100 power
      }
      else if (StringFind(messageReceived, "4") == 3) //else, if the fourth character is a 4
      {
         motor[motorB] = -50; //Turn motorC off
      }

      SendString("OK");

//*******
      sprintf(leftEncoderCount, "%d", nMotorEncoder[motorA]);
      sprintf(rightEncoderCount, "%d", nMotorEncoder[motorB]);

      messageReceived="None";
SendString(leftEncoderCount);

      while(messageReceived == "None")
      {
         ReceiveString(messageReceived); //this is the robot receiving the message
         motor[motorA]=0;
         motor[motorB]=0;
         motor[motorC]=0;
         wait1Msec(10);
      }

      messageReceived="None";
      SendString(rightEncoderCount);

      while(messageReceived == "None")
      {
         ReceiveString(messageReceived); //this is the robot receiving the message
         motor[motorA]=0;
         motor[motorB]=0;
         motor[motorC]=0;
         wait1Msec(10);
      }
   }
}


Wed Feb 13, 2013 10:39 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Remote Control with NXT-Bee
Hi there,

Let me start by not shouting at you :)

What problems are you having? Could you elaborate a little? I can't test the code for you, some friends of mine are currently using my NXTBee pair for their own nefarious purposes.

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


Mon Feb 18, 2013 3:43 pm
Profile WWW
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Remote Control with NXT-Bee
Ha! Nice.

My students were working through this lab: http://www.robotc.net/firewiki/index.php?title=Remote_Control_(simple)

From there, they wanted to improve the capabilities of their remote controls. They added a third touch sensor to instruct the slave robot to move backwards, and they used the NXT buttons to command the gripper attachment on Motor A to open or close. They programmed all of this successfully.

Next, I gave them the challenge of having the slave robot send encoder values back to the master. Once we added that part, our robots now do nothing. The programs says its running, but none of the commands on the remote control (master robot) do not work. If you need more detail, let me know.

I would like to get to the point where the slave robot is creating a map on the LCD screen of the master robot. I'll need some help though, so any help would be greatly appreciated.


Mon Feb 18, 2013 7:25 pm
Profile
Rookie

Joined: Sat Jun 01, 2013 6:26 am
Posts: 2
Location: India
Post Re: Remote Control with NXT-Bee
Mightor will help us to get out from this problem as he said " I can't test the code for you "..


So wait..

_________________
GGI


Thu Jun 06, 2013 7:29 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Remote Control with NXT-Bee
How about the code in here: http://botbench.com/blog/2011/02/12/com ... he-nxtbee/

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


Wed Oct 23, 2013 9:00 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

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:  
cron



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