ROBOTC.net forums
http://www.robotc.net/forums/

BlueTooth Woes (RobotC Edition!)
http://www.robotc.net/forums/viewtopic.php?f=1&t=4264
Page 1 of 1

Author:  NeXT-Generation [ Sun Feb 19, 2012 2:22 am ]
Post subject:  BlueTooth Woes (RobotC Edition!)

I have the following two programs:

Code:
#pragma config(Sensor, S1, ColorSens, sensorCOLORFULL)
#pragma config(Sensor, S2, ArmRst, sensorTouch)
#pragma config(Motor, motorB, ArmTurnMtr, tmotorNormal, PIDControl, encoder)
#pragma config(Motor, motorC, ArmMoveMtr, tmotorNormal, PIDControl, encoder)

void initialize();

const int DegreesToLoc[] = {1,2,3,4,5,6};

const ubyte IsConnected[] = {1};
const ubyte IAmConnected[] = {2};

ubyte SentMessage;

task main()
{
  initialize();
}

void initialize()
{
  btConnect(1, "Slave");
  cCmdMessageWriteToBluetooth(IsConnected[0], 1, 0);
  while(cCmdMessageRead(SentMessage, 1, 0) != IAmConnected[0]);

  motor[ArmMoveMtr] = -30;
  while(SensorValue(ArmRst) == 0);//94 1062
  motor[ArmMoveMtr] = 0;

  motor[ArmTurnMtr] = -30;
  while(motorPWMLevel[ArmTurnMtr] >= -55);
  motor[ArmTurnMtr] = 0;

  nMotorEncoder[ArmTurnMtr] = 0;
  nMotorEncoderTarget[ArmTurnMtr] = 94;
  motor[ArmTurnMtr] = 20;
  while(nMotorRunState[ArmTurnMtr] != runStateIdle);
  motor[ArmTurnMtr] = 0;

  nMotorEncoder[ArmMoveMtr] = 0;
  nMotorEncoderTarget[ArmMoveMtr] = 1062;
  motor[ArmMoveMtr] = 100;
  while(nMotorRunState[ArmMoveMtr] != runStateIdle);
  motor[ArmMoveMtr] = 0;
}


And:

Code:
#pragma config(Sensor, S1, NoBttn, sensorTouch)
#pragma config(Sensor, S2, YesBttn, sensorTouch)
#pragma config(Sensor, S3, LightSens, sensorLightInactive)
#pragma config(Sensor, S4, HTIRL, sensorI2CCustom)
#pragma config(Motor, motorC, TumblrMtr, tmotorNormal, PIDControl, reversed, encoder)

#include "drivers/HTIRL-driver.h";

void initialize();

const ubyte IsConnected[1] = {1};
const ubyte IAmConnected[1] = {2};

ubyte SentMessage;

tPFmotor Tread1AndLights = pfmotor_S4_C1_A;
tPFmotor Tread2 = pfmotor_S4_C1_B;
tPFmotor DispenserMtr = pfmotor_S4_C2_A;
tPFmotor PneumSwtch = pfmotor_S4_C2_B;
tPFmotor BrickScannerDisp = pfmotor_S4_C3_A;
tPFmotor ColorScanAlign = pfmotor_S4_C3_B;

task main()
{
  initialize();
}

void initialize()
{
  while(cCmdMessageRead(SentMessage, 1, 0) != IsConnected[0]);
  cCmdMessageWriteToBluetooth(IAmConnected[0], 1, 0);
}


When I run the programs, the bricks connect, the Master sends the message to the Slave, the "SentMessage" variable on the Slave turns to "1", but it doesn't send the Master the reply :breakcomputer: . It seems to me like it should work, but then again this is the first time I'm using BlueTooth :oops: .

This probably isn't the best way to do it, and I'm VERY open to suggestions :poke: .

Author:  NeXT-Generation [ Sun Feb 19, 2012 12:53 pm ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

Anyone? Please? :cry:

Author:  NeXT-Generation [ Tue Feb 21, 2012 12:56 am ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

ARRGHHHHH!!!! Now I've figured it out!!! And it was so simple!!!!!!! :breakcomputer: :breakcomputer: :breakcomputer: :crying: :crying: :crying: :crying: :evil: :evil: :evil: :evil: :downloading:

I've spent two days doing nothing and the answer was right in front of me!!!!! AAAAAAAAAAAAAAAAAAAA!!!!!!!!!

Please exscuse the tyraniccal rant. I just have a tight deadline for this project, and can't afford this kind of delay :wink: . Now back to your regularly scheduled programming.

:x :x :x :breakcomputer: :breakcomputer: :eek: :cry: :evil: :evil: :cry: :(

Author:  magicode [ Tue Feb 21, 2012 1:37 am ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

If you've figured out the solution to your problem, then perhaps you could post it here? That way, others with similar problems wont have to "spend two days doing nothing".

Author:  mightor [ Tue Feb 21, 2012 1:44 am ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

Yup, fess up your sins! If not for helping others, at least allow us to be entertained! Perhaps then I will tell you the story of how I wasted a weekend figuring out why I thought my compass module was broken, when it clearly wasn't.

- Xander

Author:  MHTS [ Tue Feb 21, 2012 8:31 am ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

Talking about entertained, I can share a story. This story is about our FRC robot, not FTC but entertaining nevertheless. Our FRC student couldn't get the servo to work, so he asked me to help him figure out what's wrong. I tried hooking up to a second servo, replacing the servo wire, even scope the sevo wire and saw nothing, and ten million other things and half hour later, couldn't understand why nothing works. Then I asked the student to try moving another motor. It didn't work either. In fact, nothing on the robot works. Then it dawned on him that since we were working on two robots: one for competition, one for testing software and he was working on the test bot before got dragged to test the servo on the competition robot that he forgot his laptop was still connected to the test bot. So we were commanding the test bot upstair through wireless the whole time while we were trying to debug the competition robot. Luckily the test bot upstair was sitting on two 2x4 off the ground or it might be running wild without us noticing.

Author:  NeXT-Generation [ Tue Feb 21, 2012 10:18 am ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

Okay! I was going to yesterday, but I was forced to go to bed. Anyway, my problem was: I thought that checking this:
Code:
while(cCmdMessageRead(SentMessage, 1, 0) != IsConnected[0]);

Was seeing if the contents of the message was not equal to my variable. However, it wasn't.
It WAS receiving the message, but it wasn't actually comparing it to anything!
Here is the fixed code.
Code:
while(SentMessage[0] != IsConnected[0]){cCmdMessageRead(SentMessage, 1, 0)}


mightor wrote:
Yup, fess up your sins! If not for helping others, at least allow us to be entertained! Perhaps then I will tell you the story of how I wasted a weekend figuring out why I thought my compass module was broken, when it clearly wasn't.

- Xander


Not funny enough for ya? Okay then, here's something: When I figured it out, I couldn't decide whether I wanted to woop with joy, or kick myself! :lol: :lol: Then it just seemed so obvious!! :poke: :poke:

Author:  mightor [ Tue Feb 21, 2012 1:01 pm ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

I spent 2 days trying to figure out why my dCompass wasn't working properly. I kept getting very weird readings that made no sense at all. First I thought it was my maths but that checked out. Then I tried NXT-G and NXC, with various firmwares, still the weird errors. I thought that I had broken my sensor during one of the many times I transport my stuff from one NXT demo to another. The code worked fine when John from Dexter Industries tested it so we both thought that the sensor was broken. So after a little conversation with Aswin, who also tested the code, etc, etc, I showed him a picture of my setup:
Attachment:
IMAG0308.jpg
IMAG0308.jpg [ 56.53 KiB | Viewed 5974 times ]

He said "Oh no wonder, it's too close to the brick." So I took it off my little frame, placed it about 10 cms from the brick and it all worked like a charm.

Turns out magnetic compasses are sensitive to magnetic fields. Who would've thought?

- Xander

Author:  NeXT-Generation [ Tue Feb 21, 2012 1:51 pm ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

mightor wrote:
I spent 2 days trying to figure out why my dCompass wasn't working properly. I kept getting very weird readings that made no sense at all. First I thought it was my maths but that checked out. Then I tried NXT-G and NXC, with various firmwares, still the weird errors. I thought that I had broken my sensor during one of the many times I transport my stuff from one NXT demo to another. The code worked fine when John from Dexter Industries tested it so we both thought that the sensor was broken. So after a little conversation with Aswin, who also tested the code, etc, etc, I showed him a picture of my setup:
Attachment:
IMAG0308.jpg

He said "Oh no wonder, it's too close to the brick." So I took it off my little frame, placed it about 10 cms from the brick and it all worked like a charm.

Turns out magnetic compasses are sensitive to magnetic fields. Who would've thought?

- Xander


I would have thought!!! Eventually. It would probably end up being the same as this problem. Agonizing over it, and then have an "eureka!" moment where you figure it out, but feel you should have seen it much sooner. That's actually how quite a few of my problems have been solved.

Author:  magicode [ Tue Feb 21, 2012 5:43 pm ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

One of the programmers on my team spent hours upon hours trying to get ROBOTC to install and run. She had been working with ROBOTC for two years, so we were all confidant in her ability to get it up and running. When it just wouldn't happen, She finally showed it to the rest of the team, hoping that someone could fix it. After about 5 seconds, we all looked at her like -_- Turns out that she was trying to execute the .exe file in Ubuntu.

Author:  aaaaeroauto [ Sat Jan 31, 2015 2:40 pm ]
Post subject:  Re: BlueTooth Woes (RobotC Edition!)

NeXT-Generation wrote:
mightor wrote:
I spent 2 days trying to figure out why my dCompass wasn't working properly. I kept getting very weird readings that made no sense at all. First I thought it was my maths but that checked out. Then I tried NXT-G and NXC, with various firmwares, still the weird errors. I thought that I had broken my sensor during one of the many times I transport my stuff from one NXT demo to another. The code worked fine when John from Dexter Industries tested it so we both thought that the sensor was broken. So after a little conversation with Aswin, who also tested the code, etc, etc, I showed him a picture of my setup:
Attachment:
IMAG0308.jpg

He said "Oh no wonder, it's too close to the brick." So I took it off my little frame, placed it about 10 cms from the brick and it all worked like a charm.

Turns out magnetic compasses are sensitive to magnetic fields. Who would've thought?

- Xander


I would have thought!!! Eventually. It would probably end up being the same as this problem. Agonizing over it, and then have an "eureka!" moment where you figure it out, but feel you should have seen it much sooner. That's actually how quite a few of my problems have been solved.



Thanks :roll:

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/