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

📄 truthwidget.cc

📁 机器人人3D仿真工具,可以加入到Simbad仿真环境下应用。
💻 CC
字号:
/* *  Gazebo - Outdoor Multi-Robot Simulator *  Copyright (C) 2003   *     Nate Koenig & Andrew Howard * *  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: Model for a TruthWidget * Author: Chris Jones * Date: 30 Nov 2003 * CVS: $Id: TruthWidget.cc,v 1.23 2006/03/12 17:38:57 natepak Exp $ *//// @addtogroup models/// @{/** @defgroup TruthWidget Truth WidgetThe TruthWidget is a magical device for querying and modifyingthe true pose of objects in the simulator.  It has no simulated body,but can be attached to other models to learn or change their pose.@par libgazebo interfacesThe TruthWidget supports the @ref gz_truth interface.@par Player driversPosition information is provided through the %gz_truth driver.@par AttributesThe following attributes are supported.@htmlinclude default_attr_include.html@par BodiesThis model does not have a physical representation.@par Example@verbatim<model:TruthWidget>  <id>truth1</id></model:TruthWidget>@endverbatim@par AuthorsChris Jones*//// @} #include <assert.h>#include <math.h>#include "gazebo.h"#include "World.hh"#include "WorldFile.hh"#include "ModelFactory.hh"#include "RayGeom.hh"#include "BoxGeom.hh"#include "CylinderGeom.hh"#include "Body.hh"#include "TruthWidget.hh"//////////////////////////////////////////////////////////////////////////////// Register this modelGZ_REGISTER_STATIC("TruthWidget", TruthWidget);//////////////////////////////////////////////////////////////////////////////// ConstructorTruthWidget::TruthWidget( World *world )    : Model( world ){  this->body = NULL;  return;}//////////////////////////////////////////////////////////////////////////////// DestructorTruthWidget::~TruthWidget(){  if (this->body)    delete this->body;  this->body = NULL;  return;}//////////////////////////////////////////////////////////////////////////////// Load the modelint TruthWidget::Load( WorldFile *file, WorldFileNode *node ){  // Create a dummy body to which to attach geoms  this->body = new Body(this->world, NULL, true);  this->AddBody(this->body, true);  return 0;}//////////////////////////////////////////////////////////////////////////////// Initialize the modelint TruthWidget::Init( WorldFile *file, WorldFileNode *node ){   // Initialize external interface  if (this->IfaceInit() != 0)    return -1;  return 0;}//////////////////////////////////////////////////////////////////////////////// Initialize the external interfaceint TruthWidget::IfaceInit(){  this->truth_iface = gz_truth_alloc();  if (gz_truth_create( this->truth_iface, this->world->gz_server, this->GetId(),                       "TruthWidget", this->GetIntId(), this->GetParentIntId()) != 0)    return -1;  return 0;}//////////////////////////////////////////////////////////////////////////////// Finalize the modelint TruthWidget::Fini(){  this->IfaceFini();  return 0;}//////////////////////////////////////////////////////////////////////////////// Finalize the external interfaceint TruthWidget::IfaceFini(){  gz_truth_destroy( this->truth_iface );  gz_truth_free( this->truth_iface );  this->truth_iface = NULL;  return 0;}//////////////////////////////////////////////////////////////////////////////// Update the modelvoid TruthWidget::Update( double /*step*/ ){  GzVector cmd_pos;  GzQuatern cmd_rot;  // Read commands from the truth interface  if (IfaceGetCmd(&cmd_pos, &cmd_rot))  {    printf("Commanded Pos[%f %f %f] Rot[%f %f %f %f]\n",        cmd_pos.x,cmd_pos.y,cmd_pos.z,cmd_rot.x,cmd_rot.y,cmd_rot.z,cmd_rot.u);    if (!GzVectorFinite(cmd_pos))      printf("Commanded Vector is not Finite\n");    if (!GzQuaternFinite(cmd_rot))      printf("Commanded Quatern is not Finite\n");    // TODO: Not quite right; SetModelPose uses parent-relative    // coordinates; should be world coordinates    if (this->parent)      this->world->SetModelPose(this->parent, GzPoseSet(cmd_pos, cmd_rot));  }  // Update the mmap interface with the new data  IfacePutData();    return;}//////////////////////////////////////////////////////////////////////////////// Get commands from the interfacebool TruthWidget::IfaceGetCmd(GzVector *pos, GzQuatern *rot){  bool cmd_new;    gz_truth_lock(this->truth_iface, 1);  if (this->truth_iface->data->cmd_new)  {    cmd_new = true;    this->truth_iface->data->cmd_new = 0;    *pos = GzVectorSet(this->truth_iface->data->cmd_pos[0],                       this->truth_iface->data->cmd_pos[1],                       this->truth_iface->data->cmd_pos[2]);    *rot = GzQuaternSet(this->truth_iface->data->cmd_rot[0],                        this->truth_iface->data->cmd_rot[1],                        this->truth_iface->data->cmd_rot[2],                        this->truth_iface->data->cmd_rot[3]);    if (rot->u==0 && rot->x==0 && rot->y==0 && rot->z==0)      rot->u = 1.0;  }  else    cmd_new = false;  gz_truth_unlock(this->truth_iface);  return cmd_new;}//////////////////////////////////////////////////////////////////////////////// Update the data in the interfacevoid TruthWidget::IfacePutData(){  GzPose pose;  gz_truth_lock(this->truth_iface, 1);  // Data timestamp  this->truth_iface->data->time = this->world->GetSimTime();  if (this->parent)  {    pose = this->parent->GetPose();    this->truth_iface->data->pos[0] = pose.pos.x;    this->truth_iface->data->pos[1] = pose.pos.y;    this->truth_iface->data->pos[2] = pose.pos.z;    this->truth_iface->data->rot[0] = pose.rot.u;    this->truth_iface->data->rot[1] = pose.rot.x;    this->truth_iface->data->rot[2] = pose.rot.y;    this->truth_iface->data->rot[3] = pose.rot.z;  }  gz_truth_unlock(this->truth_iface);  return;}

⌨️ 快捷键说明

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