⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p2os.cc

📁 机器人仿真软件
💻 CC
📖 第 1 页 / 共 5 页
字号:
    cam_packet.Build(cam_command, (int)cam_command[2]+3);    this->SendReceive(&cam_packet);  }  else  {    printf("Activating CMUcam color tracking (MANUAL-mode)...\n");    //printf("      RED: %d %d    GREEN: %d %d    BLUE: %d %d\n",    //                   rmin, rmax, gmin, gmax, bmin, bmax);    cam_command[0] = TTY3;    cam_command[1] = ARGSTR;    sprintf((char*)&cam_command[3], "TC %d %d %d %d %d %d\r",             rmin, rmax, gmin, gmax, bmin, bmax);    cam_command[2] = strlen((char *)&cam_command[3]);    cam_packet.Build(cam_command, (int)cam_command[2]+3);    this->SendReceive(&cam_packet);  }  cam_command[0] = GETAUX2;  cam_command[1] = ARGINT;  cam_command[2] = CMUCAM_MESSAGE_LEN * 2 -1; // Guarantee 1 full message  cam_command[3] = 0;  cam_packet.Build(cam_command, 4);  this->SendReceive(&cam_packet);}/****************************************************************** Start Tracking - with last config****************************************************************/void P2OS::CMUcamStartTracking(bool doLock){   P2OSPacket cam_packet;   unsigned char cam_command[50];    // Then start it up with current values.    cam_command[0] = TTY3;    cam_command[1] = ARGSTR;    sprintf((char*)&cam_command[3], "TC\r");    cam_command[2] = strlen((char *)&cam_command[3]);    cam_packet.Build(cam_command, (int)cam_command[2]+3);    this->SendReceive(&cam_packet,false);}/****************************************************************** Stop Tracking - This should be done before any new command** are issued to the CMUcam.****************************************************************/void P2OS::CMUcamStopTracking(bool doLock){  P2OSPacket cam_packet;  unsigned char cam_command[50];  // First we must STOP tracking.  Just send a return.  cam_command[0] = TTY3;  cam_command[1] = ARGSTR;  sprintf((char*)&cam_command[3], "\r");  cam_command[2] = strlen((char *)&cam_command[3]);  cam_packet.Build(cam_command, (int)cam_command[2]+3);  this->SendReceive(&cam_packet,doLock);}/* toggle sonars on/off, according to val */voidP2OS::ToggleSonarPower(unsigned char val){  unsigned char command[4];  P2OSPacket packet;  command[0] = SONAR;  command[1] = ARGINT;  command[2] = val;  command[3] = 0;  packet.Build(command, 4);  SendReceive(&packet,false);}/* toggle motors on/off, according to val */voidP2OS::ToggleMotorPower(unsigned char val){  unsigned char command[4];  P2OSPacket packet;  command[0] = ENABLE;  command[1] = ARGINT;  command[2] = val;  command[3] = 0;  packet.Build(command, 4);  SendReceive(&packet,false);}///////////////////////////////////////////////////////  Actarray stuff/////////////////////////////////////////////////////// Ticks to degrees from the ARIA softwareinline double P2OS::TicksToDegrees (int joint, unsigned char ticks){  if ((joint < 0) || (joint >= sippacket->armNumJoints))    return 0;  double result;  int pos = ticks - sippacket->armJoints[joint].centre;  result = 90.0 / static_cast<double> (sippacket->armJoints[joint].ticksPer90);  result = result * pos;  if ((joint >= 0) && (joint <= 2))    result = -result;  return result;}// Degrees to ticks from the ARIA softwareinline unsigned char P2OS::DegreesToTicks (int joint, double degrees){  double val;  if ((joint < 0) || (joint >= sippacket->armNumJoints))    return 0;  val = static_cast<double> (sippacket->armJoints[joint].ticksPer90) * degrees / 90.0;  val = round (val);  if ((joint >= 0) && (joint <= 2))    val = -val;  val += sippacket->armJoints[joint].centre;  if (val < sippacket->armJoints[joint].min)    return sippacket->armJoints[joint].min;  else if (val > sippacket->armJoints[joint].max)    return sippacket->armJoints[joint].max;  else    return static_cast<int> (round (val));}inline double P2OS::TicksToRadians (int joint, unsigned char ticks){  double result = DTOR (TicksToDegrees (joint, ticks));  return result;}inline unsigned char P2OS::RadiansToTicks (int joint, double rads){  unsigned char result = static_cast<unsigned char> (DegreesToTicks (joint, RTOD (rads)));  return result;}inline double P2OS::RadsPerSectoSecsPerTick (int joint, double speed){  double degs = RTOD (speed);  double ticksPerDeg = static_cast<double> (sippacket->armJoints[joint].ticksPer90) / 90.0f;  double ticksPerSec = degs * ticksPerDeg;  double secsPerTick = 1000.0f / ticksPerSec;  if (secsPerTick > 127)    return 127;  else if (secsPerTick < 1)    return 1;  return secsPerTick;}inline double P2OS::SecsPerTicktoRadsPerSec (int joint, double msecs){  double ticksPerSec = 1.0 / (static_cast<double> (msecs) / 1000.0);  double ticksPerDeg = static_cast<double> (sippacket->armJoints[joint].ticksPer90) / 90.0f;  double degs = ticksPerSec / ticksPerDeg;  double rads = DTOR (degs);  return rads;}void P2OS::ToggleActArrayPower (unsigned char value, bool lock){  unsigned char command[4];  P2OSPacket packet;  command[0] = ARM_POWER;  command[1] = ARGINT;  command[2] = value;  command[3] = 0;  packet.Build (command, 4);  SendReceive (&packet, lock);}void P2OS::SetActArrayJointSpeed (int joint, double speed){  unsigned char command[4];  P2OSPacket packet;  command[0] = ARM_SPEED;  command[1] = ARGINT;  command[2] = static_cast<int> (round (speed));  command[3] = joint;  packet.Build (command, 4);  SendReceive (&packet);}///////////////////////////////////////////////////////  End actarray stuff/////////////////////////////////////////////////////intP2OS::ProcessMessage(MessageQueue * resp_queue,                     player_msghdr * hdr,                     void * data){  // Look for configuration requests  if(hdr->type == PLAYER_MSGTYPE_REQ)    return(this->HandleConfig(resp_queue,hdr,data));  else if(hdr->type == PLAYER_MSGTYPE_CMD)    return(this->HandleCommand(hdr,data));  else    return(-1);}intP2OS::HandleConfig(MessageQueue* resp_queue,                   player_msghdr * hdr,                   void * data){  int joint = 0;  double newSpeed = 0.0f;  // check for position config requests  if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                           PLAYER_POSITION2D_REQ_SET_ODOM,                           this->position_id))  {    if(hdr->size != sizeof(player_position2d_set_odom_req_t))    {      PLAYER_WARN("Arg to odometry set requests wrong size; ignoring");      return(-1);    }    player_position2d_set_odom_req_t* set_odom_req =            (player_position2d_set_odom_req_t*)data;    this->sippacket->x_offset = ((int)rint(set_odom_req->pose.px*1e3)) -            this->sippacket->xpos;    this->sippacket->y_offset = ((int)rint(set_odom_req->pose.py*1e3)) -            this->sippacket->ypos;    this->sippacket->angle_offset = ((int)rint(RTOD(set_odom_req->pose.pa))) -            this->sippacket->angle;    this->Publish(this->position_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_POSITION2D_REQ_SET_ODOM);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_POSITION2D_REQ_MOTOR_POWER,                                this->position_id))  {    /* motor state change request     *   1 = enable motors     *   0 = disable motors (default)     */    if(hdr->size != sizeof(player_position2d_power_config_t))    {      PLAYER_WARN("Arg to motor state change request wrong size; ignoring");      return(-1);    }    player_position2d_power_config_t* power_config =            (player_position2d_power_config_t*)data;    this->ToggleMotorPower(power_config->state);    this->Publish(this->position_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_POSITION2D_REQ_MOTOR_POWER);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_POSITION2D_REQ_RESET_ODOM,                                this->position_id))  {    /* reset position to 0,0,0: no args */    if(hdr->size != 0)    {      PLAYER_WARN("Arg to reset position request is wrong size; ignoring");      return(-1);    }    ResetRawPositions();    this->Publish(this->position_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_POSITION2D_REQ_RESET_ODOM);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_POSITION2D_REQ_GET_GEOM,                                this->position_id))  {    /* Return the robot geometry. */    if(hdr->size != 0)    {      PLAYER_WARN("Arg get robot geom is wrong size; ignoring");      return(-1);    }    player_position2d_geom_t geom;    // TODO: Figure out this rotation offset somehow; it's not    //       given in the Saphira parameters.  For now, -0.1 is    //       about right for a Pioneer 2DX.    geom.pose.px = -0.1;    geom.pose.py = 0.0;    geom.pose.pa = 0.0;    // get dimensions from the parameter table    geom.size.sl = PlayerRobotParams[param_idx].RobotLength / 1e3;    geom.size.sw = PlayerRobotParams[param_idx].RobotWidth / 1e3;    this->Publish(this->position_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK,                  PLAYER_POSITION2D_REQ_GET_GEOM,                  (void*)&geom, sizeof(geom), NULL);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_POSITION2D_REQ_VELOCITY_MODE,                                this->position_id))  {    /* velocity control mode:     *   0 = direct wheel velocity control (default)     *   1 = separate translational and rotational control     */    if(hdr->size != sizeof(player_position2d_velocity_mode_config_t))    {      PLAYER_WARN("Arg to velocity control mode change request is wrong "                  "size; ignoring");      return(-1);    }    player_position2d_velocity_mode_config_t* velmode_config =            (player_position2d_velocity_mode_config_t*)data;    if(velmode_config->value)      direct_wheel_vel_control = false;    else      direct_wheel_vel_control = true;    this->Publish(this->position_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_POSITION2D_REQ_VELOCITY_MODE);    return(0);  }  // check for sonar config requests  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_SONAR_REQ_POWER,                                this->sonar_id))  {    /*     * 1 = enable sonars     * 0 = disable sonar     */    if(hdr->size != sizeof(player_sonar_power_config_t))    {      PLAYER_WARN("Arg to sonar state change request wrong size; ignoring");      return(-1);    }    player_sonar_power_config_t* sonar_config =            (player_sonar_power_config_t*)data;    this->ToggleSonarPower(sonar_config->state);    this->Publish(this->sonar_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_SONAR_REQ_POWER);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_SONAR_REQ_GET_GEOM,                                this->sonar_id))  {    /* Return the sonar geometry. */    if(hdr->size != 0)    {      PLAYER_WARN("Arg get sonar geom is wrong size; ignoring");      return(-1);    }    player_sonar_geom_t geom;    geom.poses_count = PlayerRobotParams[param_idx].SonarNum;    for(int i = 0; i < PlayerRobotParams[param_idx].SonarNum; i++)    {      sonar_pose_t pose = PlayerRobotParams[param_idx].sonar_pose[i];      geom.poses[i].px = pose.x / 1e3;      geom.poses[i].py = pose.y / 1e3;      geom.poses[i].pa = DTOR(pose.th);    }    this->Publish(this->sonar_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_SONAR_REQ_GET_GEOM,                  (void*)&geom, sizeof(geom), NULL);    return(0);  }  // check for blobfinder requests  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                             PLAYER_BLOBFINDER_REQ_SET_COLOR,                             this->blobfinder_id))  {    // Set the tracking color (RGB max/min values)    if(hdr->size != sizeof(player_blobfinder_color_config_t))    {      puts("Arg to blobfinder color request wrong size; ignoring");      return(-1);    }    player_blobfinder_color_config_t* color_config =            (player_blobfinder_color_config_t*)data;    CMUcamTrack(color_config->rmin,                color_config->rmax,                color_config->gmin,                color_config->gmax,                color_config->bmin,                color_config->bmax);    this->Publish(this->blobfinder_id, resp_queue,                  PLAYER_MSGTYPE_RESP_ACK, PLAYER_BLOBFINDER_REQ_SET_COLOR);    return(0);  }  else if(Message::MatchMessage(hdr,PLAYER_MSGTYPE_REQ,                                PLAYER_BLOBFINDER_REQ_SET_IMAGER_PARAMS,                                this->blobfinder_id))  {    // Set the imager control params    if(hdr->size != si

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -