View unanswered posts | View active topics It is currently Mon Dec 22, 2014 11:44 am






Reply to topic  [ 15 posts ] 
JoystickDriver.c is not being kind to me. 
Author Message
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post JoystickDriver.c is not being kind to me.
Hi, ive been having some problems with programming our robot for the FTC competition coming up. My problem started when i wrote a simple code, and tried to compile it, thats when it gave me an error message that said "Unspecified error". I tried to find out what the problem was so i made a code without using
Code:
#include "JoystickDriver.c"
and it compiled no problems. So i opened joystickdriver.c to find out that it had many errors, i asked the coach and my teammates and they said that that happened last year. Now this wouldn't be much of a problem if i could still pull code from it, but i cant. What i need to know is if this is an update issue, how can i get the old/new joystickdriver.c? Im using robotc version 3.62 and any help would be appreciated, I've tried reinstalling robotc and downloading version2 and nothing worked. Thanks


Mon Oct 27, 2014 9:30 am
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: JoystickDriver.c is not being kind to me.
What kind of errors are you getting from the joystick driver?

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Mon Oct 27, 2014 8:18 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
BurningLights wrote:
What kind of errors are you getting from the joystick driver?

I dont have the laptop with me right now as it belongs to my coach, but the code seem like it should work, no unclosed parentheses or something, which leaves me to belive that robotc updated last year and joystickdriver.c is out of date, yet i cannot find a diffrent version. I asked where the programmer from last year got it but he dident know.


Mon Oct 27, 2014 8:46 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: JoystickDriver.c is not being kind to me.
And just to verify, your Compiler Target is set to Physical Robot, and your Platform Type is set to LEGO NXT + TETRIX/MATRIX, correct?

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Mon Oct 27, 2014 10:51 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
Yes i have it set correctly.


Tue Oct 28, 2014 8:58 am
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: JoystickDriver.c is not being kind to me.
Well, here's the code for the 3.62 JoystickDriver that I have and has worked very well for me:
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)) && defined(_Target_Robot_) && !defined(NaturalLanguage)
#pragma autoStartTasks        // Automatically start this task when the main user program starts.
#elif (defined(VEX2) || defined(NXT) || defined(TETRIX)) && defined(_Target_VirtWorld_)
//Virtual Worlds - No need to use most of this driver, so don't start the ReadMsgFromPC task.
#elif defined(NaturalLanguage)
//Manually Start for Natural Language - Otherwise, ReadMsgFromPC will never let the NL program end.
#elif (defined(NXT) || defined(TETRIX)) && defined(_Target_Emulator_)
  #warning "This driver may not work with 'Emulator'."
#else
  #error "This driver is not supported on this platform."
#endif

#pragma systemFile

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                    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!
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

#if defined(_Target_Robot_)
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

#else
TPCJoystick joystick;
#endif


#if defined(hasJoystickMessageOpcodes)
intrinsic void getJoystickSettings(TJoystick &joystick)
asm(opcdSystemFunctions, byte(sysFuncGetJoysticks),
variableRefRAM(joystick));
#endif


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

#if defined(_Target_Robot_)
#define getJoystickSettings(joystick)    memcpy(joystick, joystickCopy, sizeof(joystick))

short joy1Btn(int btn)
{   return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0);  }
short joy2Btn(int btn)
{   return ((joystick.joy2_Buttons & (1 << (btn - 1))) != 0);  }

#else

#define getJoystickSettings getPCJoystickSettings
short joy1Btn(int btn)
{   return ((joystick.joy1_Buttons & (1 << (btn - 1))) != 0);  }
#endif


// Code Below Does Not Apply to Virtual/Emulator Robots
#if (defined(NXT) || defined(TETRIX)) && defined(_Target_Robot_)
const TMailboxIDs kJoystickQueueID = mailbox1;
TJoystick joystickCopy;  // Internal buffer to hold the last received message from the PC. Do not use

long ntotalMessageCount = 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.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
#if defined(_Target_Robot_)
bool bDisconnected = false;
bool bOverrideJoystickDisabling = false;
long nNoMessageCounterLimit = 750;
long nNoMessageCounter = 0;
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;

  bool bTempUserMode,bTempStopPgm;

  while (true)
  {
    // Check to see if a message is available.
    bMsgFound = false;
    bDisconnected = 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)
        {
          if (nNoMessageCounter > nNoMessageCounterLimit)
          {
            hogCPU();
            if (!bOverrideJoystickDisabling)
            {
              bTempUserMode = joystickCopy.UserMode;
              bTempStopPgm = joystickCopy.StopPgm;

              memset(joystickCopy, 0, sizeof(joystickCopy));

              joystickCopy.UserMode = bTempUserMode;
              joystickCopy.StopPgm = bTempStopPgm;
              joystickCopy.joy1_TopHat = -1;
              joystickCopy.joy2_TopHat = -1;
            }
            bDisconnected = true;
            releaseCPU();
          }
          wait1Msec(4);    // Give other tasks a chance to run
          nNoMessageCounter++;
          continue;        // No message this time. Loop again
        }
        else
        {
          bDisconnected = false;
          nNoMessageCounter = 0;
          break;
        }
        //
        // 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.
        //
      }

      if (nSizeOfMessage > sizeof(tempBuffer))
        nSizeOfMessage = sizeof(tempBuffer);
      nBTCmdRdErrorStatus = cCmdMessageRead(&tempBuffer[0], 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;
    }

    // Once we've reached here, a valid message is available

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

    ++ntotalMessageCount;

    joystickCopy.UserMode           = (bool)tempBuffer[1];
    joystickCopy.StopPgm            = (bool)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
  }
}
#endif

///////////////////////////////////////////////////////////////////////////////////////////
//
//                                        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);

#if defined(TETRIX) && defined(_Target_Robot_)

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

task displayDiagnostics()
{
  string sFileName;
  bNxtLCDStatusDisplay = true;
  getUserControlProgram(sFileName);

  while (true)
  {
    if (bDisplayDiagnostics)
    {
      nxtDisplayTextLine(6, "Teleop FileName:");
      nxtDisplayTextLine(7, sFileName);

      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.
//
///////////////////////////////////////////////////////////////////////////////////////////
#endif
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[0]);
    }

    //
    // 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

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Oct 28, 2014 11:37 am
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
Thank you but when i put it into robotc and compiled it, it still gave me the same errors. I don't know whats wrong? it must be robotc doing this.


Tue Oct 28, 2014 12:20 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: JoystickDriver.c is not being kind to me.
Are the errors about task main not being defined? If so, that's normal for just trying to compile the joystick driver. However, if there other issues, then I might try completely uninstalling ROBOTC and then reinstalling it.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Oct 28, 2014 12:28 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
These are the errors i am getting.


Attachments:
errors.PNG
errors.PNG [ 50.68 KiB | Viewed 899 times ]
Tue Oct 28, 2014 12:39 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
I did reinstall robotc and it did the same thing. i might try again though.


Tue Oct 28, 2014 12:42 pm
Profile
Professor
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 214
Post Re: JoystickDriver.c is not being kind to me.
Well, doing some testing with my ROBOTC, it appears that some of the errors come from ROBOTC not recognizing sbyte as a type and not recognizing the existence of certain built-in functions. The only conclusion I can come to is that something is screwed up in your installation where the intrinsic files are corrupted. I would recommend uninstalling ROBOTC AND deleting the entire ROBOTC Development Environment folder found under Program Files/Robomatter Inc to make sure all of the files are erased. Then reinstall ROBOTC.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://bluechariotsoffire.com/.


Tue Oct 28, 2014 5:04 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
Thank you I will try that when I get to school tomorrow.


Tue Oct 28, 2014 7:19 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post Re: JoystickDriver.c is not being kind to me.
We have been looking into this issue (joystick control not working in ROBOTC Natural Language 4.26) and have been able to narrow down the issue. For the quick, easy fix:

- Disable Natural Language mode in ROBOTC (which can be toggled in the 'Robot -> Platform Type' menu)

Image

- Manually start the readMsgFromPC from task main.

Code:
task main()
{
startTask(readMsgFromPC);
}


We have implemented a fix for this issue in ROBOTC 4.27, which we hope to have available as soon as possible.

_________________
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 Oct 29, 2014 12:21 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
Thaks addy, but im still getting the problem, ive noticed you are using ev3, is that what i should have been using?


Attachments:
image.jpg
image.jpg [ 203.92 KiB | Viewed 751 times ]
Thu Oct 30, 2014 12:42 pm
Profile
Rookie

Joined: Mon Oct 27, 2014 9:14 am
Posts: 9
Post Re: JoystickDriver.c is not being kind to me.
Joystickdriver.c


Attachments:
image.jpg
image.jpg [ 232.02 KiB | Viewed 751 times ]
Thu Oct 30, 2014 12:47 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 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.