1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

NXC - adding hex digits and timing

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.

NXC - adding hex digits and timing

Postby tabbycatrobots » 13 Feb 2012, 16:26

I'm plan to use BlueTooth communications between 4 robots to sync their movements. To better understand
how I might do this, I've been writing programs that just send BT messages, then display the results. Some
messages are the sum of hex values, and these messages were arriving incomplete. Displaying the sum on the
sending NXT, before sending, I found the incomplete messages. To debug this, I wrote some smaller simpler
programs. If seems that if my program uses (sends, displays) the sum of several hex digits too soon after the
addition, the value is incomplete. (Although, I haven't totally ruled out my typing, my code, or ????) I tried this
on 2 different NXTs, with same results. Any suggestions are appreciated. My test program below has 6 different
examples that I've tried. Trials 0 and 1 are probably the simplest "FAILS" , "WORKS" examples. Does that fact
that I'm using #defines matter? The problem seems to be worse as the battery wears down, but I haven't done
enough tests to confirm this.
Thanks. Howard

Code: Select all
//  File hex_addition_test_02.nxc
//  Created by: hdrake, TabbyCat Robots      2012Feb13


#define  ACK_STUB      0xc0000000
#define  I_NEED        0x00310000

#define BUTTON_PRESS_DELAY          700

task main()
{
    unsigned long    msg_to_send;
    unsigned long    data_digits;

    unsigned char    rcvd_msg_id;
    unsigned char    poll_cntr_A;


    rcvd_msg_id = 1;

/******************  Trial 0 - Base  -  Fails  ********************************/

    msg_to_send = ACK_STUB + rcvd_msg_id;

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 0 Fails");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  Trial 1 - Wait  -  Works  ********************************/

    msg_to_send = ACK_STUB + rcvd_msg_id;
    Wait(500);  //  Works

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 1 Works");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  Trial 2 - Fails  *****************************************/

    msg_to_send = ACK_STUB + I_NEED + rcvd_msg_id;  //  Fails

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 2 Fails");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  Trial 3 - Fails  *****************************************/

    msg_to_send = 0xc0000000 + 0x00310000 + rcvd_msg_id;  //  Fails

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 3 Fails");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);

/******************  Trial 4 - Fails  *****************************************/

    msg_to_send = 0xc0000000 + 0x310000 + rcvd_msg_id;  //  Fails

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 4 Fails");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  Trial 5 - Works  *****************************************/

    msg_to_send = 0xc0310001;  //  Works

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 5 Works");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  Trial 6 - Works Sometimes  *******************************/

//            data_digits = 0x310000;  //  Works
    data_digits = I_NEED;  //  Works
    msg_to_send = ACK_STUB + data_digits + rcvd_msg_id;  //  Works

    ClearLine(LCD_LINE2);
    TextOut(0, LCD_LINE2, "Trial 6 Works");
    ClearLine(LCD_LINE3);
    TextOut(0, LCD_LINE3, "Sometimes");
    ClearLine(LCD_LINE6);
    TextOut(0, LCD_LINE6, FormatNum("ACKm 0x%x", msg_to_send));

    TextOut(0, LCD_LINE8, "Push BTNctr");
    until(ButtonPressed(BTNCENTER, TRUE));
    Wait(BUTTON_PRESS_DELAY);
    ClearLine(LCD_LINE8);


/******************  End  *****************************************************/


}  //  End of  -  File  -  hex_addition_test_02.nxc


tabbycatrobots
 
Posts: 96
Joined: 27 Dec 2010, 19:10

Re: NXC - adding hex digits and timing

Postby doc-helmut » 13 Feb 2012, 17:06

I can confirm this from my own observations:
BT is very shaky and often messages get broken.
My approach is to send a message und response a checksum; if the checksum is correct all is fine, and if not: send again {do until eternity} ;)
regards,
HaWe
±≠≈αγδεωΔΦΣ∫√∅∞
NXC CHESS for NXT: http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
indispensable for NXC + EV3-C: easy + trouble-free network & sensor+motor remote control for rs485, BT, USB!
User avatar
doc-helmut
 
Posts: 2425
Joined: 29 Sep 2010, 14:25

Re: NXC - adding hex digits and timing

Postby mcsummation » 13 Feb 2012, 17:26

What do you (both of you) mean by "broken"? I've sent lots of BT messages from/to a PC without ever seeing any problem. Is what you are seeing only with NXT/NXT communication?
McSummation aka James
http://www.mcsummation.com/Mindstorms/
mcsummation
 
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: NXC - adding hex digits and timing

Postby tabbycatrobots » 13 Feb 2012, 17:42

I am not saying that my problem is with BT. I was experimenting with sending different types
of messages on multiple BT queues when I saw a problem. After testing with a very simple
program, see the code in my original post above, that contains no BT operations, it appears
that the problem may be in adding hex numbers, but that doesn't seem to make sense. I
am puzzled.
tabbycatrobots
 
Posts: 96
Joined: 27 Dec 2010, 19:10

Re: NXC - adding hex digits and timing

Postby mcsummation » 13 Feb 2012, 18:01

I downloaded your code, compiled it using BricxCC 3.3.8.10 and ran it on FW 1.31 (lms_arm_nbcnxc_131_20111019_1659.rfw) and all examples work properly. What are you seeing in the ones you say "fail"?
McSummation aka James
http://www.mcsummation.com/Mindstorms/
mcsummation
 
Posts: 220
Joined: 23 Jan 2012, 17:07
Location: Round Rock, TX

Re: NXC - adding hex digits and timing

Postby afanofosc » 13 Feb 2012, 18:13

I can't explain what you are seeing other than that you've got a buggy compiler. I assume that it is not the very latest test release version. Are you running on a Windows platform or some other platform such as Mac OSX or Linux? What are your compiler options set to?

In any case, the version of the compiler that I am running is displaying the correct number in all cases. I am running the latest test release and have the optimization level set to 3 along with internal compiler, automatic firmware version, and enhanced firmware set in the BricxCC Preferences dialog.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

Re: NXC - adding hex digits and timing

Postby tabbycatrobots » 13 Feb 2012, 20:32

I'm running BCC Version 3.3(Build 3.3.8.8) 6/29/2010 5:37:12AM. On Windows XP Professional SP3.
Compiler options - Enhanced firmware, NXT 2.0 compatible firmware, optimization level set to 3.
The firmware on my NXT is FW NBC/NXC 1.31.
I am seeing the following results
Trial 0 - 0x1
Trial 1 - 0xC0000001
Trial 2 - 0x310001
Trial 3 - 0x310001
Trial 4 - 0x310001
Trial 5 - 0xC0310001
Trial 6 - 0x310001
I tried changing the compiler options to: Use internal compiler, Enhanced firmware, NXT 2.0 compatible firmware,
optimization level set to 3, Automatic firmware version. I still see the same failures. So, that sounds like it is
the version of the compiler. What is the current best to upgrade to? Thanks.
Howard
tabbycatrobots
 
Posts: 96
Joined: 27 Dec 2010, 19:10

Re: NXC - adding hex digits and timing

Postby afanofosc » 13 Feb 2012, 22:23

I would recommend a compiler upgrade. The latest official release (3.3.8.9) is newer. Newer still is the latest test release from http://bricxcc.sourceforge.net/test_releases/

I generally recommend installing the latest official release and then extracting the latest test release zip over it. You could also be experiencing a firmware defect which probably no longer exists so you may want to use the 1.32 build from the test_releases folder.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

Re: NXC - adding hex digits and timing

Postby tabbycatrobots » 14 Feb 2012, 02:07

I upgraded to 3.3.8.9. Still seeing the same failures. Unfortunately, with 3.3.8.9, my program
wfcr_ldr_bt_21_sprt_send.nxc, in the attached zip file, no longer compiles. I've reverted to 3.3.8.8, and
the program, wfcr_ldr_bt_21_sprt_send.nxc, compiles. I think it makes sense for me, at this time
to stay with 3.3.8.8. As I'm finding BT is somewhat time sensitive, and I'm often putting in Waits,
and while loops, adding an additional Wait is not a problem. I'll try upgrading to 3.3.8.10 and FW 1.32
when they become official. I tend to be on the conservative side when it comes to SW / FW / HW
upgrades. Thanks for looking at this.
Howard
Attachments
Ldr_BT_Init_21.zip
(25.23 KiB) Downloaded 4 times
tabbycatrobots
 
Posts: 96
Joined: 27 Dec 2010, 19:10

Re: NXC - adding hex digits and timing

Postby afanofosc » 14 Feb 2012, 06:18

As it turns out when I made the 3.3.8.9 release I accidentally broke a few of the Remote* functions that send direct commands to other NXTs. This was very quickly fixed and has been fixed in every test release of 3.3.8.10 since the official release of 3.3.8.9.

Bluetooth communication is not timing dependent so much as it is dependent upon checking that you aren't stepping on top of a previous attempt to send or receive a bluetooth message.

In any case, it appears that 3.3.8.8 generates valid code with optimization level 0, 1, and 2 but not with optimization level 3. The optimizer is messing up the addition code in some cases. Inserting the wait just added a line of code that for reasons I don't completely understand changed the behavior of the optimizer so that it didn't foul up the generated code.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
User avatar
afanofosc
Site Admin
 
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN

Next

Return to Mindstorms Software

Who is online

Users browsing this forum: No registered users and 1 guest