Re: Problem with Judoka1 Reset Angle

Olivier Michel <[email protected]> Tue, 16 Mar 2004 09:23:36 +0100
Newsgroups gmane.comp.cybernetics.webot.contest
Organization Cyberbotics Ltd.
Message-ID <[email protected]>
Mike,

Thanks for reporting this problem. It comes from the fact that the 
judo_reset_supervisor controller retrieves the angle vector at the 
beginning of the simulation but after a few simulation steps. And since 
the initial angle for JUDOKA_1 is 0 1 0 0, the physics engine may switch 
it to something like 1 0 0 0.000002 in the very first simulation steps 
before the supervisor gets the value. Then, when you apply a rotation 
with the initial value, the angle vector is wrong... I fixed that by 
forcing the value of this vector to 0 1 0 in the supervisor program. 
That should correct the problem. Here is a fixed version of 
judo_reset_supervisor (source code: judo_reset_supervisor.c, Linux 
binary: judo_reset_supervisor.gz and Windows binary: 
judo_reset_supervisor.zip). Mike, please let me know if that fixes the 
problem.

-Olivier

Mike Jost wrote:

>Olivier,
>
>The reset angle for Judoka1 rotates the robot around the X axis instead of
>the Y axis.  The reset angle for Judoda0 is correct.
>
>Passing the reset string "stand me up 1  0.0  -0.5  1.57" for Judoka1 gives
>the attached screen capture Judoka1_Angle_1.57.jpg.
>Passing the reset string "stand me up 1  0.0  -0.5  3.14" for Judoka1 gives
>the attached screen capture Judoka1_Angle_3.14.jpg.
>
>Thanks,
>Mike Jost (FreeTime)
>  
>


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/webots-contest/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
judo_reset_supervisor.c (text/x-csrc, 4.4 KB)
/*****************************************************************************/
/* File:         judo_reset_supervisor.c                                     */
/* Version:      1.0                                                         */
/* Date:         10-Oct-03                                                   */
/* Description:  Supervisor for the Robot Judo Contest                       */
/* Author:       [email protected]                              */
/*                                                                           */
/* Copyright (c) 2003 Cyberbotics - www.cyberbotics.com                      */
/*****************************************************************************/

#include <device/robot.h>
#include <device/supervisor.h>
#include <device/receiver.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ROBOTS 2  /* number of robots */
#define SERVOS 22 /* number of servos in each robot */

static int verbose=1;
static NodeRef robot[ROBOTS];
static NodeRef servo[ROBOTS][SERVOS];
static float   robot_initial_position[ROBOTS][7];
static float   servo_initial_position[ROBOTS][SERVOS][7];
static float   robot_current_position[ROBOTS][7];
static float   servo_current_position[ROBOTS][SERVOS][7];
static char   *servo_name[SERVOS]={
  "back_1","back_2","left_hip_1","left_hip_2","left_hip_3","left_knee",
  "left_ankle_1","left_ankle_2","left_shoulder_1","left_shoulder_2",
  "left_elbow","neck","neck_tilt","right_hip_1","right_hip_2","right_hip_3",
  "right_knee","right_ankle_1","right_ankle_2","right_shoulder_1",
  "right_shoulder_2","right_elbow"};
static DeviceTag receiver;

void reset() {
  receiver=robot_get_device("receiver");
}

int main() {
  int k,l,m;
  char name[32];
  const char *text;
  float x,z,alpha;

  robot_live(reset);
  receiver_enable(receiver,64);
  for(k=0;k<ROBOTS;k++) {
    sprintf(name,"JUDOKA_%d",k);
    robot[k] = supervisor_node_get_from_def(name);
    supervisor_field_get(robot[k],
			 SUPERVISOR_FIELD_TRANSLATION_AND_ROTATION,
			 (void *)robot_current_position[k],128);
    for(l=0;l<SERVOS;l++) {
      sprintf(name,"%s_%d",servo_name[l],k);
      servo[k][l]=supervisor_node_get_from_def(name);
      supervisor_field_get(servo[k][l],
			   SUPERVISOR_FIELD_TRANSLATION_AND_ROTATION,
			   (void *)servo_current_position[k][l],128);
    }
  }
  robot_step(128); /* get and save initial positions of robots and servos */
  for(k=0;k<ROBOTS;k++) {
    if (verbose>1) printf("SUPERVISOR robot %d: T:%g,%g,%g R:%g,%g,%g,%g\n",k,
			  robot_current_position[k][0],
			  robot_current_position[k][1],
			  robot_current_position[k][2],
			  robot_current_position[k][3],
			  robot_current_position[k][4],
			  robot_current_position[k][5],
			  robot_current_position[k][6]);
    for(m=0;m<7;m++)
     robot_initial_position[k][m]=robot_current_position[k][m];
    for(l=0;l<SERVOS;l++) {
      if (!supervisor_node_was_found(servo[k][l]))
       fprintf(stderr,"SUPERVISOR: servo %s_%d not found\n",servo_name[l],k);
      if (verbose>1) printf("SUPERVISOR  servo %s: T:%g,%g,%g R:%g,%g,%g,%g\n",
			    servo_name[l],
			    servo_current_position[k][l][0],
			    servo_current_position[k][l][1],
			    servo_current_position[k][l][2],
			    servo_current_position[k][l][3],
			    servo_current_position[k][l][4],
			    servo_current_position[k][l][5],
			    servo_current_position[k][l][6]);
      for(m=0;m<7;m++)
       servo_initial_position[k][l][m]=servo_current_position[k][l][m];
      // we have to correct the rotation angle which may have changed due
      // to physics simulation before the supervisor process starts
      // (bug reported by Mike Jost)
      servo_initial_position[k][l][3]=0;
      servo_initial_position[k][l][4]=1;
      servo_initial_position[k][l][5]=0;
    }
  }
  for(;;) { /* never ending loop */
    l = receiver_get_buffer_size(receiver);
    if (l) {
      text = receiver_get_buffer(receiver);
      if (strncmp(text,"stand me up ",12)==0) {
	if (sscanf(text,"stand me up %d %f %f %f",&k,&x,&z,&alpha)==4) {
	  robot_initial_position[k][0]=x;
	  robot_initial_position[k][2]=z;
	  robot_initial_position[k][6]=alpha;
	}
	supervisor_field_set(robot[k],
			     SUPERVISOR_FIELD_TRANSLATION_AND_ROTATION,
			     robot_initial_position[k]);
	for(l=0;l<SERVOS;l++)
	  supervisor_field_set(servo[k][l],
			       SUPERVISOR_FIELD_TRANSLATION_AND_ROTATION,
			       servo_initial_position[k][l]);
      }
    }
    robot_step(64);
  }
  return 0;
}
judo_reset_supervisor.gz (application/x-tar, 6.7 KB) - not displayed
judo_reset_supervisor.zip (application/zip, 5.9 KB) - not displayed