View unanswered posts | View active topics It is currently Tue Jul 22, 2014 12:11 pm






Reply to topic  [ 7 posts ] 
JoystickDriver.c doesn't Compile. 
Author Message
Rookie

Joined: Tue Dec 04, 2012 4:51 pm
Posts: 4
Post JoystickDriver.c doesn't Compile.
Help, we need a program that drives our robot. The sample programs won't compile because the JoystickDriver.c file is not compilable due to errors. Here are the errors:
**Error**:'*' Indirection levels mismatch. Call to 'cCmdMessageRead'. Parameter: 'ubyte * pData' is '(ubyte) tempBuffer)' of type 'ubyte'.
*Warning*:Invalid '=' operation for types 'bool' and 'sbyte'
*Warning*:Invalid '=' operation for types 'bool' and 'sbyte'
**Error**:Procedure call Parameters don't match declaration for 'strcat(char * pToBuffer, char * pFromBuffer)'

Thanks for your help!
FYI: We have RobotC for NXT 3.54


Tue Dec 04, 2012 4:57 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 555
Post Re: JoystickDriver.c doesn't Compile.
Would you be able to post the entire code using the [code][/code] tags? This way, we will be able to take a deeper look at it and hopefully debug what exactly is going wrong with it. Thank you in advance!

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Tue Dec 04, 2012 5:07 pm
Profile
Rookie

Joined: Tue Dec 04, 2012 4:51 pm
Posts: 4
Post Re: JoystickDriver.c doesn't Compile.
We are using the sample program "Joystick1" with no modifications.
Code:
#pragma config(Hubs,  S1, HTMotor,  none,     none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorTetrix, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

//TJoystick joystick;

task main()
{
  while (true)
  {
    getJoystickSettings(joystick);
    motor[motorD] = joystick.joy1_y1;
    motor[motorE] = joystick.joy1_y2;
  }
}


Within JoystickDriver.c we are getting the errors listed above. Neither file has been modified from its original form. This problem started when we upgraded to RobotC 3.54 from 2.26. Here is the code for JoystickDriver.c

Code:
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                    HiTechnic Servo/Motor Controller Device Driver  - UPDATED 1/08/2009//
//
// With the TETRIX system, the PC Controller Station sends messages over Bluetooth to the NXT containing
// current settings of a PC joystick. The joystick settings arrive using the standard NXT BLuetooth
// "message mailbox" facility.
//
// This is a short ROBOTC program to extract the joystick data from a mailbox message and format it
// into data structure that can be easily acccessed by end user programs.
//
// The driver resides in a separate file that can be simply added to any user program with a
// "#include" preprocessor directive. End users should not have to modify this program and can use
// it as is.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

#if defined(NXT) || defined(TETRIX)
   #pragma autoStartTasks        // Automatically start this task when the main user program starts.
#elif defined(VEX)
   #pragma platform(VEX, FRC)
#endif

#pragma systemFile            // this eliminates warning for "unreferenced" functions

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    Joystick Information Structure
//
//
// Structure containing info from Joystick.
//
// "short" variables are used to prevent conversion errors. For example, negating a byte variable with
// value -128 results in -128 because -128 does not fit in a byte!
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

typedef struct
{
   bool    UserMode;          // Autonomous or Telep-Operated mode
   bool    StopPgm;           // Stop program

   short   joy1_x1;           // -128 to +127
   short   joy1_y1;           // -128 to +127
   short   joy1_x2;           // -128 to +127
   short   joy1_y2;           // -128 to +127
   short   joy1_Buttons;      // Bit map for 12-buttons
   short   joy1_TopHat;       // value -1 = not pressed, otherwise 0 to 7 for selected "octant".

   short   joy2_x1;           // -128 to +127
   short   joy2_y1;           // -128 to +127
   short   joy2_x2;           // -128 to +127
   short   joy2_y2;           // -128 to +127
   short   joy2_Buttons;      // Bit map for 12-buttons
   short   joy2_TopHat;       // value -1 = not pressed, otherwise 0 to 7 for selected "octant".
} TJoystick;


TJoystick joystick;      // User defined variable access


#if defined(hasJoystickMessageOpcodes)

   intrinsic void getJoystickSettings(TJoystick &joystick)
                         asm(opcdSystemFunctions, byte(sysFuncGetJoysticks),
                               variableRefRAM(joystick));

#endif
#if defined(NXT) || defined(TETRIX)

const TMailboxIDs kJoystickQueueID = mailbox1;
TJoystick joystickCopy;  // Internal buffer to hold the last received message from the PC. Do not use

long ntotalMessageCount = 0;

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// "Macro" to get a non-volatile copy of the last joystick settings so
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

#define getJoystickSettings(joystick)    memcpy(joystick, joystickCopy, sizeof(joystick))
bool joy1Btn(int btn)
{   return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0);  }
bool joy2Btn(int btn)
{   return ((joystick.joy2_Buttons & (1 << (btn - 1))) != 0);  }

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        Receive Messages Task
//
// Dedicated task that continuously polls for a Bluetooth message from the PC containing the joystick
// values. Operaton of this task is nearly transparent to the end user as the earlier "#pragma autoStartTasks"
// statement above will cause it to start running as soon as the user program is started.
//
// The task is very simple. It's an endless loop that continuously looks for a Bluetooth mailbox
// message from the PC. When one is found, it reformats and copies the contents into the internal
// "joystickCopy" buffer.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

void resetJoystick() {
   hogCPU();
   joystickCopy.UserMode  = false;
   joystickCopy.StopPgm   = true;

   joystickCopy.joy1_x1 = 0;
   joystickCopy.joy1_y1 = 0;
   joystickCopy.joy1_x2 = 0;
   joystickCopy.joy1_y2 = 0;
   joystickCopy.joy1_Buttons = 0;
   joystickCopy.joy1_TopHat = -1;

   joystickCopy.joy2_x1 = 0;
   joystickCopy.joy2_y1 = 0;
   joystickCopy.joy2_x2 = 0;
   joystickCopy.joy2_y2 = 0;
   joystickCopy.joy2_Buttons = 0;
   joystickCopy.joy2_TopHat = -1;
   releaseCPU();
}

task readMsgFromPC()
{
   bool bMsgFound;

  TFileIOResult nBTCmdRdErrorStatus;
   const int kMaxSizeOfMessage = 18;
   sbyte tempBuffer[kMaxSizeOfMessage];

   // Initialize setting to default values in case communications with PC is broken.

   //joystickCopy.TeamColor = false;
   joystickCopy.UserMode  = false;
   joystickCopy.StopPgm   = true;

   joystickCopy.joy1_x1 = 0;
   joystickCopy.joy1_y1 = 0;
   joystickCopy.joy1_x2 = 0;
   joystickCopy.joy1_y2 = 0;
   joystickCopy.joy1_Buttons = 0;
   joystickCopy.joy1_TopHat = -1;

   joystickCopy.joy2_x1 = 0;
   joystickCopy.joy2_y1 = 0;
   joystickCopy.joy2_x2 = 0;
   joystickCopy.joy2_y2 = 0;
   joystickCopy.joy2_Buttons = 0;
   joystickCopy.joy2_TopHat = -1;

   int cyclesWithoutUpdate = 0;
   while (true)
   {
      // Check to see if a message is available.
      bMsgFound = false;
      while (true)
      {
       //
         // There may be more than one message in the queue. We want to get to the last received
         // message and discard the earlier "stale" messages. This loop simply discards all but
         // the last message.
         //
         int nSizeOfMessage;

         nSizeOfMessage = cCmdMessageGetSize(kJoystickQueueID);

         if (nSizeOfMessage <= 0)
         {
            if (!bMsgFound)
            {
              cyclesWithoutUpdate++;
              wait1Msec(4);    // Give other tasks a chance to run
              if(cyclesWithoutUpdate == 150) {
               resetJoystick();
              }
              continue;        // No message this time. Loop again
            }else {
              cyclesWithoutUpdate = 0;
            }

            //
            // No more messages available and at least one message found. This is not essential but
            // useful to ensure that we're working with the latest message. We simply discard earlier
            // messages. This is useful because there could be many messages queued and we don't
            // want to work with stale data.
            //
            break;
         }
        if (nSizeOfMessage > sizeof(tempBuffer))
          nSizeOfMessage = sizeof(tempBuffer);
        nBTCmdRdErrorStatus = cCmdMessageRead((ubyte)tempBuffer, nSizeOfMessage, kJoystickQueueID);
        nBTCmdRdErrorStatus = nBTCmdRdErrorStatus; //Get rid of info message
        //
        // Repeat loop until there are no more messages in the queue. We only want to process the
        // last message in the queue.
        //
        bMsgFound = true;
      }

      cyclesWithoutUpdate = 0;
     // Once we've reached here, a valid message is available

      hogCPU();   // grab CPU for duration of critical section

      ++ntotalMessageCount;

      joystickCopy.UserMode           = tempBuffer[1];
      joystickCopy.StopPgm            = tempBuffer[2];

      joystickCopy.joy1_x1            = tempBuffer[3];
      joystickCopy.joy1_y1            = tempBuffer[4];
      joystickCopy.joy1_x2            = tempBuffer[5];
      joystickCopy.joy1_y2            = tempBuffer[6];
      joystickCopy.joy1_Buttons       = (tempBuffer[7] & 0x00FF) | (tempBuffer[8] << 8);
      joystickCopy.joy1_TopHat        = tempBuffer[9];

      joystickCopy.joy2_x1            = tempBuffer[10];
     joystickCopy.joy2_y1            = tempBuffer[11];
     joystickCopy.joy2_x2            = tempBuffer[12];
     joystickCopy.joy2_y2            = tempBuffer[13];
     joystickCopy.joy2_Buttons       = (tempBuffer[14] & 0x00FF) | (tempBuffer[15] << 8);
      joystickCopy.joy2_TopHat        = tempBuffer[16];

     joystickCopy.joy1_y1            = -joystickCopy.joy1_y1; // Negate to "natural" position
     joystickCopy.joy1_y2            = -joystickCopy.joy1_y2; // Negate to "natural" position

     joystickCopy.joy2_y1            = -joystickCopy.joy2_y1; // Negate to "natural" position
     joystickCopy.joy2_y2            = -joystickCopy.joy2_y2; // Negate to "natural" position


     releaseCPU(); // end of critical section
   }
}

#if defined(TETRIX)
///////////////////////////////////////////////////////////////////////////////////////////
//
//                                        displayDiagnostics
//
// THis task will display diagnostic information about a TETRIX robot on the NXT LCD.
//
// If you want to use the LCD for your own debugging use, call the function
// "disableDiagnosticsDisplay()
//
///////////////////////////////////////////////////////////////////////////////////////////

bool bDisplayDiagnostics = true;  // Set to false in user program to disable diagnostic display

void getUserControlProgram(string& sFileName);

void disableDiagnosticsDisplay()
{
  bDisplayDiagnostics = false;   // Disable diagnostic display
}


task displayDiagnostics()
{
  string sFileName;

  getUserControlProgram(sFileName);
   nxtDisplayTextLine(6, "Teleop FileName:");
   nxtDisplayTextLine(7, sFileName);
  bNxtLCDStatusDisplay = true;
  while (true)
   {
      if (bDisplayDiagnostics)
      {
         getJoystickSettings(joystick);                   //Update variables with current joystick values

         if (joystick.StopPgm)
           nxtDisplayCenteredTextLine(1, "Wait for Start");
         else if (joystick.UserMode)
            nxtDisplayCenteredTextLine(1, "TeleOp Running");
         else
            nxtDisplayCenteredTextLine(1, "Auton Running");

         if ( externalBatteryAvg < 0)
            nxtDisplayTextLine(3, "Ext Batt: OFF");       //External battery is off or not connected
         else
            nxtDisplayTextLine(3, "Ext Batt:%4.1f V", externalBatteryAvg / (float) 1000);

         nxtDisplayTextLine(4, "NXT Batt:%4.1f V", nAvgBatteryLevel / (float) 1000);   // Display NXT Battery Voltage

         nxtDisplayTextLine(5, "FMS Msgs: %d", ntotalMessageCount);   // Display Count of FMS messages
      }

      wait1Msec(200);
  }
}

///////////////////////////////////////////////////////////////////////////////////////////
//
//                                        getUserControlProgram
//
// This function returns the name of the TETRIX User Control program. It reads the file
// "FTCConfig.txt" and builds the name of the file from the contents.
//
// Note that the filename includes the ".rxe" (robot executable file) file extension.
//
///////////////////////////////////////////////////////////////////////////////////////////

const string kConfigName = "FTCConfig.txt";

void getUserControlProgram(string& sFileName)
{
  byte   nParmToReadByte[2];
  int    nFileSize;
   TFileIOResult nIoResult;
   TFileHandle hFileHandle;

  sFileName = "";
  nParmToReadByte[1] = 0;
  hFileHandle = 0;
  OpenRead(hFileHandle, nIoResult, kConfigName, nFileSize);
  if (nIoResult == ioRsltSuccess)
  {
    for (int index = 0; index < nFileSize; ++index)
    {
      ReadByte(hFileHandle, nIoResult,  nParmToReadByte[0]);
      strcat(sFileName, nParmToReadByte);
   }

    //
    // Delete the ".rxe" file extension
    //
    int nFileExtPosition;

    nFileExtPosition = strlen(sFileName) - 4;
    if (nFileExtPosition > 0)
      StringDelete(sFileName, nFileExtPosition, 4);
  }
  Close(hFileHandle, nIoResult);
  return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    waitForStart
//
// Wait for the start of either the autonomous or tele-op phase. User program is running on the NXT
// but the phase has not yet started. The FMS (Field Management System) is continually (every 50 msec)
// sending information to the NXT. This program loops getting the latest value of joystick settings.
// When it finds that the FMS has started the  phase, it immediately returns.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void waitForStart()
{
  while (true)
  {
    getJoystickSettings(joystick);
    if (!joystick.StopPgm)
      break;
  }
  return;
}

#endif
#endif


Last edited by NBCRobotics on Wed Dec 05, 2012 4:36 pm, edited 1 time in total.



Tue Dec 04, 2012 5:15 pm
Profile
Rookie

Joined: Tue Dec 04, 2012 4:51 pm
Posts: 4
Post Re: JoystickDriver.c doesn't Compile.
Our problem seems to lie in passing the Joystick stack to the NXT and is specific to RobotC v3.54.

When using RobotC v2.26, we are able to connect via bluetooth, download programs, and control motors with the game controller wirelessly.

When using RobotC v3.54, we are able to connect via bluetooth and download programs, however, JoystickDriver.c creates errors and won't compile. If we comment out the 2 offending lines of code, everything compiles and downloads. We can then run the program from the Joystick Control - FTC menu, however at that point things break down. The joystick menu on screen properly displays the current state of all buttons, but I don't think that information is being passed to the NXT (either because of the commented-out lines of JoystickDriver.c or as part of the root cause of the problem).

I have tested various programs, attempted to display the values being parsed by JoystickDriver.c to the NXT screen, and placed code in both the initializerobot and main tasks to further refine the source of the problem. As far as I can tell, the tempbuffer array is empty and no actual values are being passed to the joystick object. This leads to issues with WaitForStart() because it references Joystick.StopPgm, and setting a motor = Joystick.joy1_y1 leaves the motor set to 0.

At this point we are able to get basic functionality using RobotC 2.26, but it doesn't have support to use the IR sensors for this year's challenge.

Please help with any insight you may have as to workarounds or solutions.

Thank you,
The Greyhounds


Wed Dec 05, 2012 4:18 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 555
Post Re: JoystickDriver.c doesn't Compile.
I've done a side-by-side comparison of the JoystickDriver.c code you've posted and the current version, and there are a few major differences between the two: I'm assuming the JoystickDriver.c file that you have is from the previous 2.0 version that was on the computer and for some reason didn't get updated.

I would suggest doing a clean uninstall/reinstall of ROBOTC (making sure to clean out the ROBOTC directory to ensure that new files are loaded with the install). Alternatively, I can post a link to just the newer JoystickDriver.c file, but I would still be concerned about the possible age of the other files (such as ROBOTCIntrinsics.c) that are used extensively in ROBOTC.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Dec 05, 2012 4:53 pm
Profile
Rookie
User avatar

Joined: Wed Dec 01, 2010 5:15 pm
Posts: 30
Post Re: JoystickDriver.c doesn't Compile.
Check if you have a JoystickDriver.c file in the same directory as your code. That would mess up the correct compilation. If so, you should delete it.


Wed Dec 05, 2012 7:37 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 555
Post Re: JoystickDriver.c doesn't Compile.
Following up on this one, were you able to get JoystickDriver.c working? If so, what was the culprit (for future reference)? If not, are there any other error codes or symptoms that you are seeing?

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Tue Dec 18, 2012 12:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.