Update of /cvsroot/playerstage/code/player/utils/playerv
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28058/utils/playerv

Modified Files:
        Makefile.am playerv.c playerv.h pv_dev_ptz.c registry.c 
Added Files:
        pv_dev_actarray.c 
Log Message:
added actarray support to playerv


Index: registry.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/registry.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** registry.c  21 Nov 2007 09:34:19 -0000      1.30
--- registry.c  9 Jan 2008 11:45:37 -0000       1.31
***************
*** 32,35 ****
--- 32,44 ----
    switch (device->addr.interf)
    {
+     case PLAYER_ACTARRAY_CODE:
+       device->proxy = actarray_create(mainwnd, opt, client,
+                                     device->addr.index,
+                                     device->drivername,
+                                     device->subscribe);
+       device->fndestroy = (fndestroy_t) actarray_destroy;
+       device->fnupdate = (fnupdate_t) actarray_update;
+       break;
+ 
      case PLAYER_AIO_CODE:
        device->proxy = aio_create(mainwnd, opt, client,

Index: playerv.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/playerv.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** playerv.h   21 Nov 2007 09:34:19 -0000      1.52
--- playerv.h   9 Jan 2008 11:45:37 -0000       1.53
***************
*** 48,51 ****
--- 48,53 ----
  #define COLOR_GRID_MINOR         0xE0E0E0
  #define COLOR_AIO                0x000000
+ #define COLOR_ACTARRAY_DATA      0x00C000
+ #define COLOR_ACTARRAY_CMD       0x0000C0
  #define COLOR_DIO                0x000000
  #define COLOR_LASER              0x0000C0
***************
*** 172,175 ****
--- 174,218 ----
  
   /***************************************************************************
+   * ActArray device
+   ***************************************************************************/
+ 
+  // ActArray device info
+  typedef struct
+  {
+    // Driver name
+    char *drivername;
+ 
+    // Menu stuff
+    rtk_menu_t *menu;
+    rtk_menuitem_t *subscribe_item;
+    rtk_menuitem_t *command_item;
+ 
+    // Figures for drawing the actarray
+    rtk_fig_t **actuator_fig;
+    rtk_fig_t **actuator_fig_cmd;
+    double * lastvalue;
+    int fig_count;
+    mainwnd_t *mainwnd;
+ 
+    // ActArray device proxy
+    playerc_actarray_t *proxy;
+ 
+    // Timestamp on most recent data
+    double datatime;
+ 
+  } actarray_t;
+ 
+  // Create a actarray device
+  actarray_t *actarray_create(mainwnd_t *mainwnd, opt_t *opt, playerc_client_t 
*client,
+                        int index,  const char *drivername, int subscribe);
+ 
+  // Destroy a actarray device
+  void actarray_destroy(actarray_t *actarray);
+ 
+  // Update a actarray device
+  void actarray_update(actarray_t *actarray);
+ 
+ 
+  /***************************************************************************
    * Bumper device
    ***************************************************************************/

--- NEW FILE: pv_dev_actarray.c ---
/* 
 *  PlayerViewer
 *  Copyright (C) Andrew Howard 2002
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
/***************************************************************************
 * Desc: PTZ device interface
 * Author: Andrew Howard
 * Date: 26 May 2002
 * CVS: $Id: pv_dev_actarray.c,v 1.1 2008/01/09 11:45:37 thjc Exp $
 ***************************************************************************/

#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "playerv.h"

void actarray_draw(actarray_t *actarray);
void actarray_move(actarray_t *actarray);
void actarray_allocate(actarray_t *actarray, int size);
void actarray_deallocate(actarray_t *actarray);

#define ARRAY_SPACING 1
#define ARRAY_X_OFFSET 2


// Create a actarray device
actarray_t *actarray_create(mainwnd_t *mainwnd, opt_t *opt, playerc_client_t 
*client,
                  int index, const char *drivername, int subscribe)
{
  char section[64];
  char label[64];
  actarray_t *actarray;
  
  actarray = malloc(sizeof(actarray_t));
  actarray->datatime = 0;
  actarray->drivername = strdup(drivername);
  actarray->proxy = playerc_actarray_create(client, index);

  // Set initial device state
  snprintf(section, sizeof(section), "actarray:%d", index);
  if (subscribe)
  {
    if (playerc_actarray_subscribe(actarray->proxy, PLAYER_OPEN_MODE) != 0)
      PRINT_ERR1("libplayerc error: %s", playerc_error_str());
    playerc_actarray_get_geom(actarray->proxy);
  }

  // Construct the menu
  snprintf(label, sizeof(label), "actarray:%d (%s)", index, 
actarray->drivername);
  actarray->menu = rtk_menu_create_sub(mainwnd->device_menu, label);
  actarray->subscribe_item = rtk_menuitem_create(actarray->menu, "Subscribe", 
1);
  actarray->command_item = rtk_menuitem_create(actarray->menu, "Command", 1);
  
  // Set the initial menu state
  rtk_menuitem_check(actarray->subscribe_item, 
actarray->proxy->info.subscribed);

  // Construct figures
  actarray->actuator_fig = NULL;
  actarray->actuator_fig_cmd = NULL;
  actarray->lastvalue = NULL;
  actarray->mainwnd = mainwnd;
  
  return actarray;
}


// Destroy a actarray device
void actarray_destroy(actarray_t *actarray)
{
  // Destroy figures
  actarray_allocate(actarray,0);
  free(actarray->actuator_fig);
  free(actarray->actuator_fig_cmd);

  // Destroy menu items
  rtk_menuitem_destroy(actarray->command_item);
  rtk_menuitem_destroy(actarray->subscribe_item);
  rtk_menu_destroy(actarray->menu);

  // Unsubscribe/destroy the proxy
  if (actarray->proxy->info.subscribed)
    playerc_actarray_unsubscribe(actarray->proxy);
  playerc_actarray_destroy(actarray->proxy);

  free(actarray->drivername);
  free(actarray);
}

void actarray_allocate(actarray_t *actarray, int size)
{
  int ii;
  if (size == actarray->fig_count)
    return;
  if (size < actarray->fig_count)
  {
    for (ii=size; ii < actarray->fig_count; ++ii)
    {
      rtk_fig_destroy(actarray->actuator_fig[ii]);
      rtk_fig_destroy(actarray->actuator_fig_cmd[ii]);
    }
  }
  actarray->actuator_fig = realloc(actarray->actuator_fig, size * 
sizeof(rtk_fig_t*));
  actarray->actuator_fig_cmd = realloc(actarray->actuator_fig_cmd, size * 
sizeof(rtk_fig_t*));
  actarray->lastvalue = realloc(actarray->lastvalue, size*sizeof(double));
  if (size > actarray->fig_count)
  {
    for (ii=actarray->fig_count; ii < size; ++ii)
    {
      actarray->lastvalue[ii] = 1e10;
      actarray->actuator_fig[ii] = rtk_fig_create(actarray->mainwnd->canvas, 
actarray->mainwnd->robot_fig, 10);
      actarray->actuator_fig_cmd[ii] = 
rtk_fig_create(actarray->mainwnd->canvas, actarray->mainwnd->robot_fig, 11);
      rtk_fig_movemask(actarray->actuator_fig_cmd[ii], RTK_MOVE_TRANS);
      rtk_fig_origin(actarray->actuator_fig_cmd[ii], 
ARRAY_SPACING*ii+ARRAY_X_OFFSET, 0, 0);
      rtk_fig_color_rgb32(actarray->actuator_fig_cmd[ii], COLOR_ACTARRAY_CMD);
      rtk_fig_ellipse(actarray->actuator_fig_cmd[ii], 0, 0, 0, 0.2, 0.2, 0);

    }
  }
  actarray->fig_count = size;
}


// Update a actarray device
void actarray_update(actarray_t *actarray)
{
  int ii;
  // Update the device subscription
  if (rtk_menuitem_ischecked(actarray->subscribe_item))
  {
    if (!actarray->proxy->info.subscribed)
    {
      if (playerc_actarray_subscribe(actarray->proxy, PLAYER_OPEN_MODE) != 0)
        PRINT_ERR1("libplayerc error: %s", playerc_error_str());
      playerc_actarray_get_geom(actarray->proxy);
    }
  }
  else
  {
    if (actarray->proxy->info.subscribed)
      if (playerc_actarray_unsubscribe(actarray->proxy) != 0)
        PRINT_ERR1("libplayerc error: %s", playerc_error_str());
  }
  rtk_menuitem_check(actarray->subscribe_item, 
actarray->proxy->info.subscribed);

  // Draw in the actarray scan if it has been changed.
  if (actarray->proxy->info.subscribed)
  {
    if (actarray->proxy->info.datatime != actarray->datatime)
      actarray_draw(actarray);
    actarray->datatime = actarray->proxy->info.datatime;
  }
  else
  {
    for (ii = 0; ii < actarray->fig_count; ++ii)
    {
      rtk_fig_show(actarray->actuator_fig[ii], 0);
    }
  }

  // Move the actarray
  if (actarray->proxy->info.subscribed && 
rtk_menuitem_ischecked(actarray->command_item))
  {
    for (ii = 0; ii < actarray->fig_count; ++ii)
    {
      rtk_fig_show(actarray->actuator_fig_cmd[ii], 1);
    }
    actarray_move(actarray);
  }
  else
  {
    for (ii = 0; ii < actarray->fig_count; ++ii)
    {
      rtk_fig_show(actarray->actuator_fig_cmd[ii], 0);
    }
  }
}

// Draw the actarray scan
void actarray_draw(actarray_t *actarray)
{
  double value;
  double min, max;
  double ax, ay, bx, by;
  double fx, fd;

  int ii;

  actarray_allocate(actarray, actarray->proxy->actuators_count);

  for(ii = 0; ii < actarray->proxy->actuators_count; ++ii)
  {
    value = actarray->proxy->actuators_data[ii].position;
    min = -1;
    max = 1;
    if (actarray->proxy->actuators_geom && 
actarray->proxy->actuators_geom_count == actarray->proxy->actuators_count)
    {
      min = actarray->proxy->actuators_geom[ii].min;
      max = actarray->proxy->actuators_geom[ii].max;
    }
    // now limit and scale the value to the actuator bar
    if (value > max) value = max;
    if (value < min) value = min;
    value = 2*(value-min)/(max-min) -1;
    rtk_fig_t * fig = actarray->actuator_fig[ii];
    rtk_fig_show(fig, 1);
    rtk_fig_clear(fig);
    rtk_fig_origin(actarray->actuator_fig[ii], ARRAY_SPACING*ii 
+ARRAY_X_OFFSET, 0, 0);
    rtk_fig_color_rgb32(fig, COLOR_ACTARRAY_DATA);
    rtk_fig_line(fig, 0, -1, 0, 1);
    rtk_fig_ellipse(actarray->actuator_fig[ii], 0, value, 0, 0.2, 0.2, 1);
  }

}


// Move the actarray
void actarray_move(actarray_t *actarray)
{
  double ox, oy, oa, min, max;
  double value;

  int ii;
  for(ii = 0; ii < actarray->fig_count; ++ii)
  {
    rtk_fig_get_origin(actarray->actuator_fig_cmd[ii], &ox, &oy, &oa);
    value = oy;

    min = -1;
    max = 1;
    if (actarray->proxy->actuators_geom && 
actarray->proxy->actuators_geom_count == actarray->proxy->actuators_count)
    {
      min = actarray->proxy->actuators_geom[ii].min;
      max = actarray->proxy->actuators_geom[ii].max;
    }
    // now limit and scale the value to the actuator bar
    value = ((oy+1)/2)*(max-min)+min;
    if (value > max) value = max;
    if (value < min) value = min;

    if (actarray->lastvalue[ii] != value)
    {
      if (playerc_actarray_position_cmd(actarray->proxy, ii, value) != 0)
        PRINT_ERR1("libplayerc error: %s", playerc_error_str());
      actarray->lastvalue[ii] = value;
    }
  }
}





Index: pv_dev_ptz.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/pv_dev_ptz.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** pv_dev_ptz.c        17 Sep 2007 02:18:50 -0000      1.1
--- pv_dev_ptz.c        9 Jan 2008 11:45:37 -0000       1.2
***************
*** 99,102 ****
--- 99,103 ----
  
    // Destroy menu items
+   rtk_menuitem_destroy(ptz->command_item);
    rtk_menuitem_destroy(ptz->subscribe_item);
    rtk_menu_destroy(ptz->menu);

Index: playerv.c
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/playerv.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -C2 -d -r1.54 -r1.55
*** playerv.c   7 Dec 2007 01:50:15 -0000       1.54
--- playerv.c   9 Jan 2008 11:45:37 -0000       1.55
***************
*** 77,80 ****
--- 77,81 ----
  
  playerv can visualize data from the following kinds of devices:
+ - @ref interface_actarray
  - @ref interface_blobfinder
  - @ref interface_bumper

Index: Makefile.am
===================================================================
RCS file: /cvsroot/playerstage/code/player/utils/playerv/Makefile.am,v
retrieving revision 1.47
retrieving revision 1.48
diff -C2 -d -r1.47 -r1.48
*** Makefile.am 21 Nov 2007 09:34:19 -0000      1.47
--- Makefile.am 9 Jan 2008 11:45:37 -0000       1.48
***************
*** 16,19 ****
--- 16,20 ----
                    opt.c \
                    opt.h \
+                   pv_dev_actarray.c \
                    pv_dev_aio.c \
                    pv_dev_blobfinder.c \


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to