FrontPage

Source & Compile

Source

  • Phenox source programs are very simple, consisting of following 3 source files.
    • pxlib.c(/root/dirs/pc/code/basic)
    • pxlib.h(/root/dirs/pc/code/basic)
    • main.c(/root/dirs/pc/work/(user project folder)

Compile

Library building

  • If users modify pxlib.c or pxlib.h, library compilation is needed as follows.
    cd /root/dirs/pc/code
    make clean all

Project building

  • After library building is finished, project compilation is needed as follows.
    cd /root/dirs/pc/work/(user project folder)
    make clean all
  • Users can compile all projects by make-command in work/ folder
    cd /root/dirs/pc/work/
    make clean all

Executing script

  • Before runnging Phenox program, users need to mount SD card (recognized as mmcblk0p1) in /mnt, but this command can be summarized in one shell script such as tutorial_***.sh in /root/dirs. So copy it and change folder name.
    cp tutorial_***.sh user_custom.sh
    vi user_custom.sh
  • To enable Phenox to execute program immediately after finishing boot, copy script to /etc/profile.d
    cp user_custom.sh /etc/profile.d

Simple main.c example

Struct

Operating parameters(pconfig)

  • User can modify following parameters which depend on environment and payload.
  • duty_hover
    • Nominal duty in hovering state(manual and automatic mode)
  • duty_hover_max
    • Maximum duty in hovering state(manual and automatic mode)
    • If this parameter is too small, Phenox cannot go upper.
  • duty_hover_min
    • Minimum duty in hovering state(manual and automatic mode)
    • If this parameter is too large, Phenox cannot go down.
  • duty_up
    • Constant duty in goint upper state(automatic mode)
    • If this parameter is too small, Phenox cannot go upper.
  • duty_down
    • Constant duty in goint down state(automatic mode)
    • If this parameter is too large, Phenox cannot go down.
  • pgain_vision_tx, dgain_vision_tx
    • PD control gain of X axis(visual feedback controller of the bottom camera).
  • pgain_vision_ty, dgain_vision_ty
    • PD control gain of Y axis(visual feedback controller of the bottom camera).
  • pgain_vision_tz, dgain_vision_tz
    • PD control gain of Z axis(visual feedback controller of the front camera).
  • pgain_sonar,dgain_sonar
    • PD control gain of Z axis(feedback controller of the range sensor).
  • whisleborder
    • Threashold of detecting whisle
  • soundborder
    • Threashold of detecting sound
  • uptime_max
    • Maximum time in going-upper state(seconds)
  • downtime_max
    • Maximum time in going-down state(seconds)
  • Usage
    pconfig pc;
    pxget_pconfig(&pc)//get current pconfig mode
    pc.*** = foo;//edit parameter which users are interested in. 
    pxset_pconfig(&pc)//reflect the parameter.
    • Users can left unknown or unfamiliar parameters open.
    • The change of the parameter is immediately updated anyware in the source program by calling pxset_pconfig().

Manual control input(manconfig)

  • Phenox orders these configurations in manual mode.
  • Any controllers can be applied to control Phenox manually by programming reactions by pressing button to reflect manconfig and by making custom host machine program.
  • stop
    • 0:Nothing
    • 1:stop all motors
  • start
    • 0:Nothing
    • 1:
      • If motor is not rotating, Phenox enters startup mode for 3 seconds and enters to hovering state.
      • If motor is rotating, Phenox enters hovering state.
  • yaw
    • -1:CCW yaw rotation when Phenox is in hovering state.
    • 0:Nothing
    • 1:CW yaw rotation when Phenox is in hovering state.
  • horizontal
    • Analog value from 0 to 255 to control X axis.
    • Nominl value should be 127.
  • vertical
    • Analog value from 0 to 255 to control Y axis.
    • Nominl value should be 127.
  • height
    • Analog value from 0 to 255 to control Z axis.
    • Nominal value should be 127.
  • Usage
    manconfig mc;
    mc.start = commandfromcontroller[0];
    mc.yaw = commandfromcontroller[1];
    mc.stop = commandfromcontroller[2];
    mc.horizontal = commandfromcontroller[3];
    mc.vertical = commandfromcontroller[4]; 
    mc.height = commandfromcontroller[5]; 
    pxset_manconfig(&mc);
    • In tutorial, to prevent receiving special character such as 0x03(ctrl+c) to Phenox program, all characters are received with "or 0x80".

Self-state(selfstate)

  • pitch
    • Current pitch angle(degree around X axis)
  • roll
    • Current roll angle(degree around Y axis)
  • yaw
    • Current yaw angle(degree around Z axis)
  • vision_tx
    • Self-position estimated from visual feature points(X axis)
  • vision_ty
    • Self-position estimated from visual feature points(Y axis)
  • vision_tz
    • Self-position estimated from visual feature points(Z axis)
  • vision_vx
    • Self-velocity estimated from visual feature points(X axis)
  • vision_vy
    • Self-velocity estimated from visual feature points(Y axis)
  • vision_vz
    • Self-velocity estimated from visual feature points(Z axis)
  • range
    • Self-position estimated from range sensor(Z axis)
  • Usage
    selfstate st;
    pxget_selfstate(&st);
    printf("%.2f %.2f %.2f %.2f %.2f %.2f %.2f\n",st.pitch,st.roll,st.yaw,st.vision_tx,st.vision_ty,st.vision_tz,st.range);

Function

Base

void pxinit_chain()

  • This function executes initialize sequence which users should call at first of program,
    • It includes memory map allocation for communication for CPU0(Linux) and CPU1(Baremetal).
  • CPU0 wakes CPU1 up to enter to initialize sequence of peripherals as following steps
    1. IMU initialization
    2. Motor controller initialization
    3. Mic initialization.
    4. Two camera initialization.
  • Default values of pconfig and manconfig are set by this function.
  • Users must call this function first before executing any destributed functions.

void pxclose_chain()

  • This function frees memory and close feature points tracking log.
  • Users exexute this function before closing program.

int pxget_cpu1ready()

  • This finction is used for waiting for initialization of CPU1 after pxinit_chain().
  • CPU1 starts following program in the background after initialization.
    1. calculates self attitude from IMUs.
    2. feature points and image acquision background and writes its contents to DDR3 at 30fps.
    3. battery voltage monitoring
  • Sound detection starts once for self check.If users execute pxset_sound_detect(0), a trigger of sound detection is set again, whose threshold parameter is defined in pconfig thus editable by users.
    return
    0CPU1 is not initialized
    1CPU1 is initialized

void pxset_manauto(int val)

  • This function sets controller mode to Phenox
    val
    0Phenox enters manual control mode immediately
    1Phenox enters automatic control mode immediately
  • If users use manual-auto combination, switching from manual to auto and vice versa should be possible by pressing button of a controller.

int pxget_manauto();

  • This function gets current controller mode from Phenox
    return
    0Phenox is in manual control mode.
    1Phenox is in automatic control mode.

void pxset_automode_xy(int val)

  • When CPU0 is in automatic control mode(pxget_manauto() == 1) and in hovering state (pxget_operate_mode() == 2), this function defines horizontal control strategy
  • If val == 0: Phenox selects PD controller based on visual feature points of the bottom camera.
    • Users can set target position by pxset_visioncontrol_xy(float tx,float ty)
    • PD controll parameter can be tuned by editing pgain_vision_tx,dgain_vision_tx,pgain_vision_ty and dgain_vision_ty in pconfig.
  • If val == 1: Users directly control roll,pitch angle by degree.
    • pxset_dst_pitch(float degree) and pxset_dst_roll(float degree) are used to set target angle.
val
0Phenox selects PD control based on visual feature points of bottom camera.
1Phenox selects direct angle control of roll,pitch angle based on IMUs

void pxset_visioncontrol_xy(float tx,float ty);

  • This functions set desired horizontal position(tx,ty) based on visual feature points after selecting pxset_automode_xy(0)
    • As follows, relative position from current position should be applied to prevent unexpexted and sudden moving.
      selfstate st;
      pxget_selfstate(&st);
      pxset_visioncontrol_xy(st.vision_tx+alpha,st.vision_ty+beta);

void pxset_automode_z(int val)

  • When CPU0 is in automatic control mode(pxget_manauto() == 1) and in hovering state (pxget_operate_mode() == 2), this function defines height control strategy.
    • If val == 0: Phenox selects PD control based on visual feature points using front camera
      • User can set desired height using pxset_visioncontrol_z()
      • PD controll parameter can be tuned by editing pgain_vision_tz and dgain_vision_tz in pconfig.
    • If val == 1: Phenox selects PD control based on range sensor.
      • User can set desired height using pxset_rangecontrol_z()
      • PD control parameter can be tuned by editing pgain_range_tz and dgain_range_tz in pconfig.
val
0Phenox selects PD control based on visual feature points of front camera
1Phenox selects PD control based range sensor(30cm to 120cm)

void pxset_visioncontrol_z(float tz);

  • This functions set desired height based on visual feature points tracking after selecting pxset_automode_z(0)
    • As follows, relative position from current position should be applied to prevent unexpexted and sudden moving.
      selfstate st;
      pxget_selfstate(&st);
      pxset_visioncontrol_z(st.vision_tz+alpha)

void pxset_rangecontrol_z(float tz);

  • This functions set desired height based on range sensor measurement after selecting pxset_automode_z(1)
  • Range sensor is different from visual feature point based method in that it can measure absolute height.
  • range sensor can be applied only from 30cm to 120cm, so the value should be between 30.0 and 120.0.

void pxset_operate_mode(int val);

  • When CPU0 is in automatic control mode(pxget_manauto() == 1), Phenox behaves as follows.
  1. When motor is not rotating
  • If val == 0: Halt mode
  • If val == 1: Startup and going-upper mode
    • Phenox enters startup sequence for 3sec, and goes upper.
    • Then, Phenox enters hovering state(pxset_operate_mode() == 2) automatically when it reaches user-defined height or user-defined limit time.
    1. User-defined height
    • After users call pxset_automode_z(1)(height estimation using range sensor), height value which Phenox enters hovering mode from going-upper mode, can be set using pxset_sonarcontrol_z(float val)
    1. User-defined limit time
    • Limit time which Phenox enters hovering mode from going-upper mode,can be set by editing uptime_max in pconfig (in seconds)
  • If val == 2: Startup and hovering mode
    • Phenox enters startup sequence for 3sec, and enters hovering state based on user-defined height control rule and user-defined horizontal control rule.
    1. User-defined height control rule
    • If pxget_automode_z() == 0 (height control using feature points of bottom camera)
      • Users can set desired height by calling pxset_visioncontrol_z(float val)
      • PD controll parameter can be tuned by editing pgain_vision_tz and dgain_vision_tz in pconfig.
    • If pxget_automode_z() == 1 (height control using range sensor)
      • Users can set desired height by calling pxset_sonarcontrol_z(float val)
      • PD controll parameter can be tuned by editing pgain_range_tz and dgain_range_tz in pconfig.
    1. User-defined horizontal control rule
    • if pxget_automode_xy() == 0 (horizontal control using feature points in images)
      • Users can set desired horizontal position by calling pxset_visioncontrol_xy(float tx,float ty);
      • PD controll parameter can be tuned by editing pgain_vision_tx,dgain_vision_tx,pgain_vision_ty and dgain_vision_ty in pconfig.
    • If pxget_automode_xy() == 1 (Users directly control roll,pitch angle)
      • Users can directly control roll,pitch angle by calling pxset_dst_pitch(float degree) and pxset_dst_roll(float degree).
  • If val == 3: Go to halt mode immediately

2.when motor is rotating

  • If val == 0: Phenox stops motors immediately.
  • If val == 1: Phenox enters going-upper mode skipping startup sequence.
  • If val == 2: Phenox enters hovering mode skipping startup sequence.
  • If val == 3: Phenox enters going-down mode skipping startup sequence.Condition going to halt all motor mode(val = 0) can be changed based on user-defined limit time(in seconds)

Image

int pxget_img_detect(char id)

  • In Phenox, FPGA continues to get image from two camera and write to DDR3 in the background, 30fps.
    • And there is an idle time between the end of image signal to the start of image signal. Thus, users need to copy the contents of images to manually allocated region in this idle time.
    • pxget_img_detect() returns the state whether the selected camera signal is in idle state.
id
0front camera is selected
1bottom camera is selected
return
0the selected camera signal is not in idle state(cannot copy contents)
1the selected camera signal is in idle state(can copy contents)

void pxset_imgfull(char id, IplImage? *img, int div)

  • This functions saves image of the selected camera to user-defined region.
    • Initialization of IplImage? is requiered before calling this function.
      IplImage *img = cvCreateImage(cvSize(hlength,vlength),IPL_DEPTH_8U,3);
id
0front camera is selected
1bottom camera is selected
div
0image size is 320 x 240 x 2byte(RGB color)
1image size is 160 x 120 x 2byte(RGB color)
2image size is 80 x 60 x 2byte(RGB color)

void pxset_featurelog(int val)

  • This function writes feature points location and its tracking information of specified camera to the file system.
  • This function should be called periodically in timer interrput function.
  • Log file is automaically created and initialized in pxlib.c, so users don't need any initialization.
val
0feature points of front camera is saved in log file
1feature points of bottom camera is saved in log file
  • Users can find feature the log file in /media/boot/featurelog.txt
  • And users can see log file using openframeworks using our visualizer software.
  • In our Ubuntu host machines, following comands starts visualizer.
    cd ~/openframework/of_v0.7.4_linux64_release/examples/visualizer
    make clean all
    cp /media/boot/featurelog.txt .
    ./bin/visualizer

Sound

int pxget_whisle_detect();

  • If whisle sound(3kHz peak) is detected, return 1
  • Users need to reset this state to call pxset_whisle_detect(0), which enables next whisle detection.
return
0whisle sound is not detected
1whisle sound is detected

void pxset_whisle_detect(int val);

  • This function is used to reset state of pxget_whisle_detect() as follows to enables next whisle detection.
    pxset_whisle_detect(0);

void pxset_whisle_border(int val);

  • This function is used to set threashold of whisle detection.

int pxget_sound_detect();

  • If voice sound is detected, return 1
  • Users need to reset this state to call pxset_sound_detect(0), which enables next sound detection.

void pxset_sound_detect(int val);

  • This function is used to reset state of pxget_sound_detect() as follows to enables next sound detection.
    pxset_sound_detect(0);

int pxget_sound(short *buffer, int size);

  • This function copies sound raw data to allocated buffer.
  • Size over 36,864 byte is ignored. It is equivalent to 1.8 seconds of sound data (10kHz,16bit data).

Attach file: filemain.c 918 download [Information]

Front page   Edit Unfreeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2014-06-28 (Sat) 03:38:39 (1427d)