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

📄 gz_truth.c

📁 机器人人3D仿真工具,可以加入到Simbad仿真环境下应用。
💻 C
字号:
/* *  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: Truth interface * Author: Chris Jones * Date: 16 Nov 2003 * CVS: $Id: gz_truth.c,v 1.7 2006/03/12 17:38:56 natepak Exp $ */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <math.h>#include "gazebo.h"// Create an interfacegz_truth_t *gz_truth_alloc(){  gz_truth_t *self;  self = calloc(1, sizeof(gz_truth_t));  self->iface = gz_iface_alloc();  return self;}// Destroy an interfacevoid gz_truth_free(gz_truth_t *self){  gz_iface_free(self->iface);  free(self);  return;}// Create the interfaceint gz_truth_create(gz_truth_t *self, gz_server_t *server, const char *id,                    const char *model_type, int model_id, int parent_model_id){  if (gz_iface_create(self->iface, server, "truth", id, sizeof(gz_truth_data_t)) != 0)    return -1;  self->data = self->iface->mmap;  strncpy(self->data->head.model_type, model_type, sizeof(self->data->head.model_type));  self->data->head.model_id = (int) model_id;  self->data->head.parent_model_id = (int) parent_model_id;  return 0;}// Destroy the interface (server)int gz_truth_destroy(gz_truth_t *self){  self->data = NULL;  return gz_iface_destroy(self->iface);}// Open an existing interfaceint gz_truth_open(gz_truth_t *self, gz_client_t *client, const char *id){  if (gz_iface_open(self->iface, client, "truth", id, sizeof(gz_truth_data_t)) != 0)    return -1;  self->data = self->iface->mmap;  return 0;}  // Close the interfaceint gz_truth_close(gz_truth_t *self){  self->data = NULL;  return gz_iface_close(self->iface);}// Lock the interface.int gz_truth_lock(gz_truth_t *self, int blocking){  return gz_iface_lock(self->iface, blocking);}// Unlock the interfacevoid gz_truth_unlock(gz_truth_t *self){  return gz_iface_unlock(self->iface);}// Tell clients that new data is availableint gz_truth_post(gz_truth_t *self){  return gz_iface_post(self->iface);}void gz_truth_euler_from_quatern(gz_truth_t *self, double *e, double *q){  double s;  // Normalize the quaternion  s = sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);  q[0] = q[0] / s;  q[1] = q[1] / s;  q[2] = q[2] / s;  q[3] = q[3] / s;  e[0] = atan2(2 * (q[2]*q[3] + q[0]*q[1]), (q[0]*q[0] - q[1]*q[1] - q[2]*q[2] + q[3]*q[3]));  e[1] = asin(-2 * (q[1]*q[3] - q[0] * q[2]));  e[2] = atan2(2 * (q[1]*q[2] + q[0] * q[3]), (q[0]*q[0] + q[1]*q[1] - q[2]*q[2] - q[3]*q[3]));}void gz_truth_quatern_from_euler(gz_truth_t *self, double *q, double *e){  double s;  double phi, the, psi;  phi = e[0] / 2;  the = e[1] / 2;  psi = e[2] / 2;  q[0] = cos(phi) * cos(the) * cos(psi) + sin(phi) * sin(the) * sin(psi);  q[1] = sin(phi) * cos(the) * cos(psi) - cos(phi) * sin(the) * sin(psi);  q[2] = cos(phi) * sin(the) * cos(psi) + sin(phi) * cos(the) * sin(psi);  q[3] = cos(phi) * cos(the) * sin(psi) - sin(phi) * sin(the) * cos(psi);  // Normalize the quaternion  s = sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]);  q[0] = q[0] / s;  q[1] = q[1] / s;  q[2] = q[2] / s;  q[3] = q[3] / s;}

⌨️ 快捷键说明

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