To use FicTrac with a closed-loop setup (to provide real time feedback), you need to configure FicTrac to output data via a socket port. To do so, you will need to (1) set a valid sock_port in your configuration text file and (2) write a python script in the fictrac/script directory for receiving data via said socket. The python script can also be used to output variables of interest as voltages via a Phidget device, a 4 channel analog output device (+/- 10V) that can be connected via USB cable.

  1. To begin, first download Python (make sure python is added to your Path) and PyCharm for Windows
  2. In PyCharm, install the packages pip, setuptools, numpy, and Phidget22 by going to File > settings > Project: pythonProject > Python Interpreter
  3. Download Phidgets drivers for windows
  4. Below is a socket_client script that has been stripped down to the bare minimum needed to interface between FicTrac and the Phidget. It is a good starting point so go ahead and download it:

Current version (>=2021)

📎 socket_client_360.py

Previous version (<2021)

📎 socket_client_360_old.py

Note: as of 2021 FicTrac modified to use TCP to UDP, meaning that the program (fictrac.exe) does not have to wait for the receiving side (socket_client.py) in order to start running. If you are using a newer build of FicTrac, make sure you download the most recent socket_client script. This includes the necessary lines of code for switching between TCP and UDP. If you are using an older build of FicTrac, you may need to re-download and re-build or you may need to modify the C++ code. For more information, see this post and this post.

  1. First, ensure that the PORT value at the top of your python script matches the sock_port value in your text configuration file (e.g. 65432). If you are having trouble with getting the socket port to work:

  2. Try a different socket (e.g. 12345)

  3. Try temporarily disabling your firewall. If this solves the issue, you can open the specific port instead by adding a new rule to windows firewall

  4. Check to see if the socket is either receiving or listening by entering netstat -an | find "#####" into your command prompt 1. If your socket does not show up when fictrac is running, it is probably an issue on the receiving end (aka your fictrac configuration) 1. If your socket does not show up when the python script is running, it is probably an issue on the listening end (aka your python script configuration)

  5. The Phidget device has x4 available analog output channels. As such, the python script above is designed to relay x4 FicTrac parameters as 0-10V signals:

    Ch0) aout_yaw - heading orientation

    Ch1) aout_x - integrated x position

    Ch2) aout_y - integrated y position

    Ch3) aout_yaw_gain - optional, modified version of heading orientation that can be used to manipulate the gain between the fly’s movement and the movement of a pattern across the arena

Note: avoid splitting Phidget channels using a BNC adapter (i.e. m-to-2f), as this can add a surprising amount of noise due to grounding differences across devices.

  1. These are not the only four parameters that can be used. A complete list of available FicTrac parameters can be found here.

  2. A new FicTrc variable can be extracted by simply adjusting the value of each float(toks[#])

  3. You will then need to convert said signal to a 0-10V scale 1. e.g. if your value is in radians, X*10/2pi 1.

  4. To give the fly control over the X pattern (e.g. load a single stripe pattern, which should occupy the X channel), plug Phidget device, Ch0, into ADC2. This sends Yaw information to the controller. Alternatively, you can use the yaw gain, and connect Ch3 to ADC2.