Difference between revisions of "ARDUINO MEGA Functions Debug"

From ROBOTC API Guide
Jump to: navigation, search
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<yambe:breadcrumb>ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
+
{{DISPLAYTITLE:2560 (MEGA) Debug Functions}}
 +
<yambe:breadcrumb self="2560 (MEGA) Debug">ARDUINO_MEGA_Functions_and_Variables|Functions and Variables</yambe:breadcrumb>
 
<br />
 
<br />
 +
 
The debugger in ROBOTC allows you to see all of your sensor, motor and variables while running your program. ROBOTC also has a debug terminal called the "Debug Stream" that you can use to output a terminal-like stream of information to have an additional way to monitor your program.
 
The debugger in ROBOTC allows you to see all of your sensor, motor and variables while running your program. ROBOTC also has a debug terminal called the "Debug Stream" that you can use to output a terminal-like stream of information to have an additional way to monitor your program.
 +
 +
The debug stream is buffered directly in memory on the Arduino platform - You can store 300 bytes of debug stream data on the Arduino when running away from the PC. Once the Arduino is connected to the PC, you can open the debug stream and the entire buffer will be written to the "Debug Stream" debugger window.
  
 
You can open this debugger window from the "Robot -> Debugger Windows -> Debug Stream" window when in Expert or Super User mode.
 
You can open this debugger window from the "Robot -> Debugger Windows -> Debug Stream" window when in Expert or Super User mode.
  
(Add picture of Debug Stream)
+
[[File:DebugStream.png]]
 
{{tl|1|1}}
 
{{tl|1|1}}
 
<br />
 
<br />
Line 41: Line 45:
 
<br />
 
<br />
  
== memset ==
+
== writeDebugStreamLine ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">memset</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">void </span><span class="bigCodeBasic">&pToBuffer</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nValue</span><span class="bigCodePunc">, </span><span class="bigKeywordBI">const short </span><span class="bigCodeBasic">nNumbOfBytes</span><span class="bigCodePunc">)</span>
+
| class="functionType"| <span class="bigKeywordBI">void </span><span class="bigKeywordB">writeDebugStreamLine</span><span class="bigCodePunc">(</span><span class="bigKeywordBI">const string </span><span class="bigCodeBasic">sFormatString</span><span class="bigCodePunc">, </span><span class="bigCodeBasic">...</span><span class="bigCodePunc">)</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) Sets a block of memory at <span class="codeBasic">pToBuffer</span> to the value <span class="codeBasic">nValue</span>. <span class="codeBasic">nNumbOfBytes</span> is the number of bytes to set. This is a useful function for initializing the value of an array to all zeros. Identical to the function found in conventional C 'string.h' library.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_void|void]]) The Debug Stream functionality allow the user to output formatted text to a debug terminal. This command works similar to a print to LCD command, but displays the information to the "Debug Stream" ROBOTC debugger window.
 +
 
 +
The only difference between this function and "writeDebugStream" is that a new line character is added after every call of "writeDebugStreamLine".
 
|-
 
|-
 
|
 
|
Line 54: Line 60:
 
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   ! width="20%" style="border-style: solid; border-width: 0px 0px 1px 0px"|Data Type
 
   |-
 
   |-
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|''pToBuffer''  
+
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|''sFormatString''  
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|buffer to set
+
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|A formatted string following standard C-Style convention for showing data inline.
 
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]]
 
   | style="border-style: solid; border-width: 1px 0px 1px 0px"|[[Data_Types#dataType_void|void]]
  |-
 
  | style="border-style: solid; border-width: 0px 0px 1px 0px"|''nValue''
 
  | style="border-style: solid; border-width: 0px 0px 1px 0px"|value to set buffer to
 
  | style="border-style: solid; border-width: 0px 0px 1px 0px"|[[Data_Types#dataType_short|short]]
 
  |-
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|''nNumbOfBytes''
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|number of bytes to set
 
  | style="border-style: solid; border-width: 0px 0px 0px 0px"|[[Data_Types#dataType_short|short]]
 
 
   |-
 
   |-
 
   |}
 
   |}
Line 72: Line 70:
 
   |-
 
   |-
 
   |<syntaxhighlight lang="robotc">
 
   |<syntaxhighlight lang="robotc">
int kSendSize = 1;                                   // we will be sending 1 byte
+
  int fooBarVar = 503;                       //Create a Variable to Display
ubyte BytesToSend[kSendSize];                        // create a ubyte array of size 1
+
  writeDebugStream("Value: %d", fooBarVar);  //Write the string "Value: 503" to the Debug Stream
short nMsgXmit = 0;                                  // we will be setting them to 0
+
memset(BytesToSend, nMsgXmit, sizeof(BytesToSend));  // set the Byte Array to 0
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   |-
 
   |-
Line 83: Line 79:
 
<br />
 
<br />
  
== nVexMasterVersion ==
+
== getAvailSpaceInDebugStream ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="variableType"| <span class="bigKeywordBI">const word </span><span class="bigKeywordB">nVexMasterVersion</span>
+
| class="variableType"| <span class="bigKeywordBI">intrinsic short </span><span class="bigKeywordB">getAvailSpaceInDebugStream</span><span class="codePunc">()</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_word|word]])  Variable contains the firmware version for the VEX master CPU.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_short|short]])  Variable will return the current amount of space available in the debug stream. For the Arduino platform, the maximum size of the debug stream is 300 bytes.
 
|-
 
|-
 
|
 
|
 
   {|
 
   {|
 
   |-
 
   |-
   |<syntaxhighlight lang="robotc">int MasterFirmwareVer = nVexMasterVersion; // stores the value of the Master Firmware to a variable</syntaxhighlight>
+
   |<syntaxhighlight lang="robotc">
 +
  while(true)
 +
  {
 +
    if(getAvailSpaceInDebugStream() == 0)              //Check if there is still room available
 +
      wait1Msec(50);                                   //No Room: Wait for a while.
 +
    else
 +
      writeDebugStream("Still Have Room!", fooBarVar); //Got room, let's write some data!
 +
  }
 +
  </syntaxhighlight>
 
   |-
 
   |-
 
   |}
 
   |}
Line 100: Line 104:
 
<br />
 
<br />
  
== version ==
+
== bFloatConversionErrors ==
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
{| style="color:black;" width="100%" cellpadding="5%" cellspacing="0" border="0"
 
|-
 
|-
| class="variableType"| <span class="bigKeywordBI">const word </span><span class="bigKeywordB">version</span>
+
| class="variableType"| <span class="bigKeywordBI">intrinsic bool </span><span class="bigKeywordB">bFloatConversionErrors</span>
 
|-
 
|-
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_word|word]]) Contains the firmware version number.
+
| style="font-family:Verdana, Geneva, sans-serif; color:black; background-color:#FFFFFF; text-align:left; font-size:100%;"|([[Data_Types#dataType_bool|bool]]) When true, this variable will generate an exception if an out of range error occurs when converting a "float" value to an integer. ROBOTC will convert out of range exceptions into the largest possible integer number.
|-
+
|
+
  {|
+
  |-
+
  |<syntaxhighlight lang="robotc">
+
displayNextLCDNumber(version);  // display the current firmware version on the LCD</syntaxhighlight>
+
  |-
+
  |}
+
 
|-
 
|-
 
|}
 
|}
 
<br />
 
<br />

Latest revision as of 20:48, 11 May 2012

ARDUINOFunctions and Variables → 2560 (MEGA) Debug


The debugger in ROBOTC allows you to see all of your sensor, motor and variables while running your program. ROBOTC also has a debug terminal called the "Debug Stream" that you can use to output a terminal-like stream of information to have an additional way to monitor your program.

The debug stream is buffered directly in memory on the Arduino platform - You can store 300 bytes of debug stream data on the Arduino when running away from the PC. Once the Arduino is connected to the PC, you can open the debug stream and the entire buffer will be written to the "Debug Stream" debugger window.

You can open this debugger window from the "Robot -> Debugger Windows -> Debug Stream" window when in Expert or Super User mode.

DebugStream.png

Color Key
Function:
Variable:


writeDebugStream

void writeDebugStream(const string sFormatString, ...)
(void) The Debug Stream functionality allow the user to output formatted text to a debug terminal. This command works similar to a print to LCD command, but displays the information to the "Debug Stream" ROBOTC debugger window.
Parameter Explanation Data Type
sFormatString A formatted string following standard C-Style convention for showing data inline. void
  int fooBarVar = 503;                       //Create a Variable to Display
  writeDebugStream("Value: %d", fooBarVar);  //Write the string "Value: 503" to the Debug Stream


writeDebugStreamLine

void writeDebugStreamLine(const string sFormatString, ...)
(void) The Debug Stream functionality allow the user to output formatted text to a debug terminal. This command works similar to a print to LCD command, but displays the information to the "Debug Stream" ROBOTC debugger window.

The only difference between this function and "writeDebugStream" is that a new line character is added after every call of "writeDebugStreamLine".

Parameter Explanation Data Type
sFormatString A formatted string following standard C-Style convention for showing data inline. void
  int fooBarVar = 503;                       //Create a Variable to Display
  writeDebugStream("Value: %d", fooBarVar);  //Write the string "Value: 503" to the Debug Stream


getAvailSpaceInDebugStream

intrinsic short getAvailSpaceInDebugStream()
(short) Variable will return the current amount of space available in the debug stream. For the Arduino platform, the maximum size of the debug stream is 300 bytes.
  while(true)
  {
    if(getAvailSpaceInDebugStream() == 0)              //Check if there is still room available
      wait1Msec(50);                                   //No Room: Wait for a while.
    else
      writeDebugStream("Still Have Room!", fooBarVar); //Got room, let's write some data!
  }


bFloatConversionErrors

intrinsic bool bFloatConversionErrors
(bool) When true, this variable will generate an exception if an out of range error occurs when converting a "float" value to an integer. ROBOTC will convert out of range exceptions into the largest possible integer number.