📄 p2os.cc
字号:
/* * Player - One Hell of a Robot Server * Copyright (C) 2000 * Brian Gerkey, Kasper Stoy, Richard Vaughan, & 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 * *//* * $Id: p2os.cc,v 1.68 2006/04/12 22:01:42 gbiggs Exp $ * * the P2OS device. it's the parent device for all the P2 'sub-devices', * like gripper, position, sonar, etc. there's a thread here that * actually interacts with P2OS via the serial line. the other * "devices" communicate with this thread by putting into and getting * data out of shared buffers. *//** @ingroup drivers *//** @{ *//** @defgroup driver_p2os p2os * @brief ActivMedia mobile robotsMany robots made by ActivMedia, such as the Pioneer series and theAmigoBot, are controlled by a microcontroller that runs a special embeddedoperating system called P2OS (aka AROS, PSOS). The host computertalks to the P2OS microcontroller over a standard RS232 serial line.This driver offer access to the various P2OS-mediated devices, logicallysplitting up the devices' functionality.@par Compile-time dependencies- none@par ProvidesThe p2os driver provides the following device interfaces, some ofthem named:- "odometry" @ref interface_position2d - This interface returns odometry data, and accepts velocity commands.- "compass" @ref interface_position2d - This interface returns compass data (if equipped).- "gyro" @ref interface_position2d - This interface returns gyroscope data (if equipped).- @ref interface_power - Returns the current battery voltage (12 V when fully charged).- @ref interface_sonar - Returns data from sonar arrays (if equipped)- @ref interface_aio - Returns data from analog I/O ports (if equipped)- @ref interface_dio - Returns data from digital I/O ports (if equipped)- @ref interface_gripper - Controls gripper (if equipped)- @ref interface_actarray - Controls arm (if equipped) - This driver does not support the player_actarray_speed_cmd and player_actarray_brakes_config messages.- @ref interface_limb - Inverse kinematics interface to arm - This driver does not support the player_limb_setposition_cmd, player_limb_vecmove_cmd, player_limb_brakes_req and player_limb_speed_req messages. - The approach vector is forward along the gripper with the orientation vector up from the gripper's centre.- @ref interface_bumper - Returns data from bumper array (if equipped)- @ref interface_blobfinder - Controls a CMUCam2 connected to the AUX port on the P2OS board (if equipped).- @ref interface_sound - Controls the sound system of the AmigoBot, which can play back recorded wav files.@par Supported configuration requests- "odometry" @ref interface_position2d : - PLAYER_POSITION_SET_ODOM_REQ - PLAYER_POSITION_MOTOR_POWER_REQ - PLAYER_POSITION_RESET_ODOM_REQ - PLAYER_POSITION_GET_GEOM_REQ - PLAYER_POSITION_VELOCITY_MODE_REQ- @ref interface_sonar : - PLAYER_SONAR_POWER_REQ - PLAYER_SONAR_GET_GEOM_REQ- @ref interface_bumper : - PLAYER_BUMPER_GET_GEOM- @ref interface_blobfinder : - PLAYER_BLOBFINDER_SET_COLOR_REQ - PLAYER_BLOBFINDER_SET_IMAGER_PARAMS_REQ@par Configuration file options- port (string) - Default: "/dev/ttyS0"- use_tcp (boolean) - Defaut: 0 - Set to 1 if a TCP connection should be used instead of serial port (e.g. Amigobot with ethernet-serial bridge device attached)- tcp_remote_host (string) - Default: "localhost" - Remote hostname or IP address to connect to if using TCP- tcp_remote_port (integer) - Default: 8101 - Remote port to connect to if using TCP - Serial port used to communicate with the robot.- radio (integer) - Default: 0 - Nonzero if a radio modem is being used; zero for a direct serial link. (a radio modem is different from and older than the newer ethernet-serial bridge used on newer Pioneers and Amigos)- bumpstall (integer) - Default: -1 - Determine whether a bumper-equipped robot stalls when its bumpers are pressed. Allowed values are: - -1 : Don't change anything; the bumper-stall behavior will be determined by the BumpStall value stored in the robot's FLASH. - 0 : Don't stall. - 1 : Stall on front bumper contact. - 2 : Stall on rear bumper contact. - 3 : Stall on either bumper contact.- pulse (float) - Default: -1 - Specify a pulse for keeping the robot alive. Pioneer robots have a built-in watchdog in the onboard controller. After a timeout period specified in the robot's FLASH, if no commands have been received from the player server, the robot will stop. By specifying a positive value here, the Player server will send a regular pulse command to the robot to let it know the client is still alive. The value should be in seconds, with decimal places allowed (eg 0.5 = half a second). Note that if this value is greater than the Pioneer's onboard value, it will still time out. - Specifying a value of -1 turns off the pulse, meaning that if you do not send regular commands from your client program, the robot's onboard controller will time out and stop. - WARNING: Overriding the onboard watchdog is dangerous! Specifying -1 and writing your client appropriately is definitely the preffered option!- joystick (integer) - Default: 0 - Use direct joystick control- direct_wheel_vel_control (integer) - Default: 1 - Send direct wheel velocity commands to P2OS (as opposed to sending translational and rotational velocities and letting P2OS smoothly achieve them).- max_xspeed (length) - Default: 0.5 m/s - Maximum translational velocity- max_yawspeed (angle) - Default: 100 deg/s - Maximum rotational velocity- max_xaccel (length) - Default: 0 - Maximum translational acceleration, in length/sec/sec; nonnegative. Zero means use the robot's default value.- max_xdecel (length) - Default: 0 - Maximum translational deceleration, in length/sec/sec; nonpositive. Zero means use the robot's default value.- max_yawaccel (angle) - Default: 0 - Maximum rotational acceleration, in angle/sec/sec; nonnegative. Zero means use the robot's default value.- rot_kp (integer) - Default: -1 - Rotational PID setting; proportional gain. Negative means use the robot's default value. - Requires P2OS1.M or above- rot_kv (integer) - Default: -1 - Rotational PID setting; derivative gain. Negative means use the robot's default value. - Requires P2OS1.M or above- rot_ki (integer) - Default: -1 - Rotational PID setting; integral gain. Negative means use the robot's default value. - Requires P2OS1.M or above- trans_kp (integer) - Default: -1 - Translational PID setting; proportional gain. Negative means use the robot's default value. - Requires P2OS1.M or above- trans_kv (integer) - Default: -1 - Translational PID setting; derivative gain. Negative means use the robot's default value. - Requires P2OS1.M or above- trans_ki (integer) - Default: -1 - Translational PID setting; integral gain. Negative means use the robot's default value. - Requires P2OS1.M or above- max_yawdecel (angle) - Default: 0 - Maximum rotational deceleration, in angle/sec/sec; nonpositive. Zero means use the robot's default value.- use_vel_band (integer) - Default: 0 - Use velocity bands- limb_pos (3 floats) - Default: 0, 0, 0 - Position of the base of the arm from the robot centre in metres.- limb_links (5 floats) - Default: 0.06875, 0.16, 0, 0.13775, 0.11321 - Offset from previous joint to this joint in metres. e.g. the offset from joint 0 to joint 1 is 0.06875m, and from joint 1 to joint 2 is 0.16m.- limb_offsets (5 floats) - Default: 0, 0, 0, 0, 0 - Angular offset of each joint from desired position to actual position (calibration data). - Taken by commanding joints to 0rad with actarray interface, then measuring their actual angle.@par Example@verbatimdriver( name "p2os" provides ["odometry::position:0" "compass::position:1" "sonar:0" "power:0"])@endverbatim@author Brian Gerkey, Kasper Stoy, James McKenna*//** @} */#ifdef HAVE_CONFIG_H #include "config.h"#endif#include <fcntl.h>#include <signal.h>#include <sys/stat.h>#include <sys/types.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <math.h>#include <stdlib.h> /* for abs() */#include <netinet/in.h>#include <termios.h>#include <sys/socket.h>#include <netinet/tcp.h>#include <netdb.h>#include "p2os.h"Driver*P2OS_Init(ConfigFile* cf, int section){ return (Driver*)(new P2OS(cf,section));}void P2OS_Register(DriverTable* table){ table->AddDriver("p2os", P2OS_Init);}P2OS::P2OS(ConfigFile* cf, int section) : Driver(cf,section,true,PLAYER_MSGQUEUE_DEFAULT_MAXLEN){ // zero ids, so that we'll know later which interfaces were requested memset(&this->position_id, 0, sizeof(player_devaddr_t)); memset(&this->sonar_id, 0, sizeof(player_devaddr_t)); memset(&this->aio_id, 0, sizeof(player_devaddr_t)); memset(&this->dio_id, 0, sizeof(player_devaddr_t)); memset(&this->gripper_id, 0, sizeof(player_devaddr_t)); memset(&this->bumper_id, 0, sizeof(player_devaddr_t)); memset(&this->power_id, 0, sizeof(player_devaddr_t)); memset(&this->compass_id, 0, sizeof(player_devaddr_t)); memset(&this->gyro_id, 0, sizeof(player_devaddr_t)); memset(&this->blobfinder_id, 0, sizeof(player_devaddr_t)); memset(&this->sound_id, 0, sizeof(player_devaddr_t)); memset(&this->actarray_id, 0, sizeof(player_devaddr_t)); memset(&this->limb_id, 0, sizeof(player_devaddr_t)); this->position_subscriptions = this->sonar_subscriptions = this->actarray_subscriptions = 0; this->pulse = -1; // intialise members sippacket = NULL; // Do we create a robot position interface? if(cf->ReadDeviceAddr(&(this->position_id), section, "provides", PLAYER_POSITION2D_CODE, -1, NULL) == 0) { if(this->AddInterface(this->position_id) != 0) { this->SetError(-1); return; } } // Do we create a compass position interface? if(cf->ReadDeviceAddr(&(this->compass_id), section, "provides", PLAYER_POSITION2D_CODE, -1, "compass") == 0) { if(this->AddInterface(this->compass_id) != 0) { this->SetError(-1); return; } } // Do we create a gyro position interface? if(cf->ReadDeviceAddr(&(this->gyro_id), section, "provides", PLAYER_POSITION2D_CODE, -1, "gyro") == 0) { if(this->AddInterface(this->gyro_id) != 0) { this->SetError(-1); return; } } // Do we create a sonar interface? if(cf->ReadDeviceAddr(&(this->sonar_id), section, "provides", PLAYER_SONAR_CODE, -1, NULL) == 0) { if(this->AddInterface(this->sonar_id) != 0) { this->SetError(-1); return; } } // Do we create an aio interface? if(cf->ReadDeviceAddr(&(this->aio_id), section, "provides", PLAYER_AIO_CODE, -1, NULL) == 0) { if(this->AddInterface(this->aio_id) != 0) { this->SetError(-1); return; } } // Do we create a dio interface? if(cf->ReadDeviceAddr(&(this->dio_id), section, "provides", PLAYER_DIO_CODE, -1, NULL) == 0) { if(this->AddInterface(this->dio_id) != 0) { this->SetError(-1); return; } } // Do we create a gripper interface? if(cf->ReadDeviceAddr(&(this->gripper_id), section, "provides", PLAYER_GRIPPER_CODE, -1, NULL) == 0) { if(this->AddInterface(this->gripper_id) != 0) { this->SetError(-1); return; } } // Do we create a bumper interface? if(cf->ReadDeviceAddr(&(this->bumper_id), section, "provides", PLAYER_BUMPER_CODE, -1, NULL) == 0) { if(this->AddInterface(this->bumper_id) != 0) { this->SetError(-1); return; } } // Do we create a power interface? if(cf->ReadDeviceAddr(&(this->power_id), section, "provides", PLAYER_POWER_CODE, -1, NULL) == 0) { if(this->AddInterface(this->power_id) != 0) { this->SetError(-1); return; } } // Do we create a blobfinder interface? if(cf->ReadDeviceAddr(&(this->blobfinder_id), section, "provides", PLAYER_BLOBFINDER_CODE, -1, NULL) == 0) { if(this->AddInterface(this->blobfinder_id) != 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -