Friday, June 22, 2018

PX4 on STM32F4Discovery

We'll try to run the PX4 firmware on the STM32F4Discovery board.  Some documentation can be found here.   We'll try to run everything from Linux.

First, we build the PX4 bootloader for f4discovery.  There is a specific makefile target, make px4discovery_bl.  To flash the bootloader, we can use texane stlink, which we will build.  After installing it, we can run stlink-gui and download the bootloader through the mini USB port, detected as STMicroelectronics ST-LINK/V2.

Then we build the PX4 firmware with make px4-stm32f4discovery_default.  We connect to the micro USB port; it is detected as PX4 BL DISCOVERY and /dev/ttyACM0 port is created.  To flash, make px4-stm32f4discovery_default upload.

Connect a USB Serial adapter to PA3 (RX) and PA2 (TX), and run screen /dev/ttyUSB0 57600 to access NuttX terminal.  The boot message, 

sercon: Registering CDC/ACM serial driver
sercon: Successfully registered the CDC/ACM serial driver
HW arch: PX4_STM32F4DISCOVERY
FW git-hash: 7a82c777b28c49b3476be3da716984e6bdc987a9
FW version: 7.82.77 0 (122834176)
OS: NuttX
OS version: Release 7.22.0 (118882559)
OS git-hash: 63775322bf25adb406594f8e610122fe0cef2f7a
Build datetime: Jun 22 2018 22:25:57
Build uri: BUILD_URI
Toolchain: GNU GCC, 4.9.3 20150529 (prerelease)
MFGUID: 3138343532314719002e0034
MCU: STM32F???, rev. Z
UID: 2E0034:32314719:31383435
nsh: mount: mount failed: No such file or directory
nsh: tone_alarm: command not found
nsh: mkfatfs: mkfatfs failed: No such file or directory
nsh: tone_alarm: command not found
nsh: tune_control: command not found
nsh: mtd: command not found
INFO  [param] selected parameter default file /fs/microsd/params
ERROR [param] open '/fs/microsd/params' failed (2)
nsh: rgbled: command not found
nsh: blinkm: command not found
nsh: rgbled_pwm: command not found
  BAT_N_CELLS: curr: 0 -> new: 3
ERROR [param] Parameter SYS_USE_IO not found
ERROR [param] Parameter SYS_FMU_TASK not found
ERROR [param] Parameter MNT_MODE_IN not found
ERROR [param] Parameter MNT_MODE_OUT not found
nsh: dataman: command not found
nsh: gps: command not found
nsh: fmu: command not found
nsh: fmu: command not found
nsh: ms5611: command not found
nsh: ms5611: command not found
nsh: bst: command not found
nsh: adc: command not found
ERROR [param] Parameter SENS_EN_LL40LS not found
ERROR [param] Parameter SENS_EN_LL40LS not found
ERROR [param] Parameter SENS_EN_SF0X not found
ERROR [param] Parameter SENS_EN_SF1XX not found
ERROR [param] Parameter SENS_EN_MB12XX not found
ERROR [param] Parameter SENS_EN_TRANGER not found
ERROR [param] Parameter SENS_EN_TFMINI not found
ERROR [param] Parameter SENS_EN_LEDDAR1 not found
nsh: sensors: command not found
nsh: commander: command not found
nsh: send_event: command not found
nsh: load_mon: command not found
ERROR [param] Parameter UAVCAN_ENABLE not found
ERROR [param] Parameter SENS_EN_LL40LS not found
ERROR [param] Parameter TRIG_MODE not found
nsh: fmu: command not found
nsh: tune_control: command not found
nsh: mavlink: command not found
nsh: mavlink: command not found
ERROR [param] Parameter UAVCAN_ENABLE not found
nsh: mavlink: command not found
nsh: navigator: command not found
No autostart ID found
nsh: ekf2: command not found
nsh: tone_alarm: command not found
ERROR [param] Parameter MNT_MODE_IN not found
nsh: vmount: command not found
ERROR [param] Parameter SDLOG_MODE not found
ERROR [param] Parameter SDLOG_MODE not found
nsh: logger: command not found
nsh: mavlink: command not found

NuttShell (NSH)
nsh> ERROR [parameters] failed to open param file: /fs/microsd/params
ERROR [parameters] param save failed (-1)

nsh> help
help usage:  help [-v] [<cmd>]

  [           dirname     free        mkrd        rmdir       umount
  ?           date        help        mh          set         unset
  basename    dd          hexdump     mount       sh          usleep
  break       df          kill        mv          sleep       xd
  cat         echo        ls          mw          test
  cd          exec        mb          ps          time
  cp          exit        mkdir       pwd         true
  cmp         false       mkfatfs     rm          uname

Builtin Apps:
  cu
  bl_update
  config
  mixer
  nshterm
  param
  perf
  px4_simple_app
  reboot
  top
  uorb
  ver
  sercon
  serdis
nsh> ver all
HW arch: PX4_STM32F4DISCOVERY
FW git-hash: 7a82c777b28c49b3476be3da716984e6bdc987a9
FW version: 7.82.77 0 (122834176)
OS: NuttX
OS version: Release 7.22.0 (118882559)
OS git-hash: 63775322bf25adb406594f8e610122fe0cef2f7a
Build datetime: Jun 22 2018 22:25:57
Build uri: BUILD_URI
Toolchain: GNU GCC, 4.9.3 20150529 (prerelease)
MFGUID: 3138343532314719002e0034
MCU: STM32F???, rev. Z
UID: 2E0034:32314719:31383435
nsh>

Monday, June 11, 2018

Fan Speed Measurement

I have an application that requires the fan speed measurement.  We can use some photo detector and a light source between the fan blades as an encoder.

The CdS photoresistor cell does not have the speed.  A solar cell salvaged from a broken timer does respond adequately.

The solar cell is enclosed in a box with a small hole exposing the solar cell.  A LED flashlight is pointed at the solar cell through the hole.  The fan blades interrupts the light periodically.  The voltage generated by the solar cell is digitized and the variations are detected and measured to determine the rate.  The fan has 10 blades, at 1000RPM, the pulse rate is about 170Hz.  The scope captures the signal,

If we use a laser point, which has a small beam spot, we get,

Note the rising edge is faster, but the falling edge still has the long tail.