Lockup with Game Control Plus by Quark

edited November 2016 in Library Questions

I am using the GC+ library to get Windows 7 joystick movements to processing. I then use the processing program to communicate with my Arduino microprocessor. Its a great library, awesome tutorials and documentation. My problem is it works for about 5 minutes flawlessly then my processing programs totally locks up. I cannot get the program to run again unless I reboot my computer. I am sorry I cannot follow the directions for posting code. Wow what I mess I am.

 /**
 Demonstration of using a joystick for Game Control Plus

 When this sketch runs it will try and find
 a game device that matches the configuration
 file 'joystick' int the data file of the processing folder.  if it can't match this device
 then it will present you with a list of devices
 you might try and use.  Use the configurator in the Processing-->Files-->examples-->GC+ to write a data file that is included into the procesing
 folder.  You keymap and name various functions.  These are then written down below in a code. (get matched
 device and get slider).

 The chosen device requires 2 sliders and 2 buttons.
 */

import org.gamecontrolplus.gui.*;
import org.gamecontrolplus.*;
import net.java.games.input.*;

import processing.serial.*;

ControlIO control;
ControlDevice stick;
float px, py, pz, pzz;
Serial myPort;  // Create object from Serial class

public void setup() {
  myPort = new Serial(this, "COM4", 9600);//this port can be different on even the same PC.
  size(400, 400);
  // Initialise the ControlIO
  control = ControlIO.getInstance(this);
  // Find a device that matches the configuration file
  stick = control.getMatchedDevice("XBOX4"); // the device is named in the config file made by GC+ ap
  if (stick == null) {
    println("No suitable device configured");
    System.exit(-1); // End the program NOW!
  }
}

public void draw() {
  px = stick.getSlider("STEERING").getValue(); //these values are named in the config file made by  GC+ ap
  py = stick.getSlider("THROTTLE").getValue();
  pz = stick.getSlider("BRAKE").getValue();  

  px=map(px,-1,1,0,255);//data from game control is usually -1.0000 to + 1.0000///PWM of Arduino requires 0-255 for analogWrite output.
  px = int(px);
  py=map(py,-1,1,127,255);
  py=int(py);
  pz=map(pz,-1,1,127,0);
  pz=int(pz);

  pzz=py-(127-pz);

delay(100);
    myPort.write("H" + int(px) + "," + int(pzz) + "\n");    //Arduino is looking for H255,255\n (can be any non numberical value to stop must be H to start)
    background(255, 255, 240);
fill(255, 0, 0);
textSize(25);
text(int(px), 75, 100);//do not write to Processing monitor it takes too long, better to write to GUI.
text(int(pzz),75,200);

}

``

Answers

  • ok have an update. Once my processing program locks up if I unplug the USB cable that is communicating with my Arduino microcontroller the program un freezes and starts working. Obviously it is a communication problem- but how can the USB port stop a processing program??

  • I assume that this is the full code that demonstrates the problem. Try commenting out lines 27 and 54 so that you are only using GC+ and report back here.

  • Answer ✓

    Ah I seem to have missed your last post. It appears to be a problem with communicating with the arduino and not GCP.

    In your original post you say it locks the computer so that you have to reboot it, but now you say that you can unfreeze the sketch by unplugging the arduino. Which is it?

    If it is just the Processing sketch you should be able to stop it in Windows Task Manager.

    It might be that Processing is being 'blocked' while writing to the serial port. Try my suggestion above.

  • Wow Thank you Quark for reading my post. Turns out it was a bad USB cable that disconnected whenever I moved my lap top. I am so happy I found the GC+, it is a real gem.

Sign In or Register to comment.