/* Copyright 2015 The MathWorks, Inc. */
#ifndef _SLROS_GENERIC_PARAM_H_
#define _SLROS_GENERIC_PARAM_H_
#include <iostream>
#include <string>
#include <ros/console.h>
#include <ros/ros.h>
extern ros::NodeHandle * SLROSNodePtr; ///< The global node handle that is used by all ROS entities in the model
// Namespace for parameter parsing code
namespace param_parser
{
/**
* Parse a scalar parameter value. This function is templatized by the
* expected data type of the ROS parameter.
* This function is needed, since the standard ROS C++ parameter parsing
* does not strictly enforce data type consistency.
*
* @param[in] xmlValue The value of the parameter as XML-RPC data structure
* @param[out] paramValue The value of the parameter as scalar data type
* @retval TRUE if parameter with given type was parsed successfully. The
* value of the parameter will be returned in @c paramValue.
* @retval FALSE if parameter type did not match content in XML-RPC data structure
*/
template <class T>
bool getScalar(const XmlRpc::XmlRpcValue& xmlValue, T& paramValue)
{
if (xmlValue.getType() != getXmlRpcType(paramValue))
return false;
// Setting the output parameter value via overloaded conversion operator.
// Since the operator is defined as non-const, using const_cast here to
// avoid compiler warnings.
// Since the conversion operator does not modify the xmlValue object,
// the const_cast is safe.
paramValue = const_cast<XmlRpc::XmlRpcValue&>(xmlValue);
return true;
}
/**
* Generic template function for getting enumerated XML-RPC data type.
* See the specialized templates for handling specific data types.
*
* @param[in] paramValue The parameter value. The contents of the variable do
* not matter, but its data type is crucial for calling the correct template
* specialization.
*
* @return XML-RPC data type enumeration corresponding to the input parameter type
*/
template <class T>
XmlRpc::XmlRpcValue::Type getXmlRpcType(const T& paramValue)
{
return XmlRpc::XmlRpcValue::TypeInvalid;
}
/**
* Specialized template function for handling integer parameters.
*
* @param[in] paramValue The parameter value.
* @return integer XML-RPC data type enumeration
*/
template <>
inline XmlRpc::XmlRpcValue::Type getXmlRpcType<int>(const int& paramValue)
{
return XmlRpc::XmlRpcValue::TypeInt;
}
/**
* Specialized template function for handling double parameters.
*
* @param[in] paramValue The parameter value.
* @return double XML-RPC data type enumeration
*/
template <>
inline XmlRpc::XmlRpcValue::Type getXmlRpcType<double>(const double& paramValue)
{
return XmlRpc::XmlRpcValue::TypeDouble;
}
/**
* Specialized template function for handling boolean parameters.
*
* @param[in] paramValue The parameter value.
* @return boolean XML-RPC data type enumeration
*/
template <>
inline XmlRpc::XmlRpcValue::Type getXmlRpcType<bool>(const bool& paramValue)
{
return XmlRpc::XmlRpcValue::TypeBoolean;
}
/**
* Specialized template function for handling string parameters.
*
* @param[in] paramValue The parameter value.
* @return string XML-RPC data type enumeration
*/
template <>
inline XmlRpc::XmlRpcValue::Type getXmlRpcType<std::string>(const std::string& paramValue)
{
return XmlRpc::XmlRpcValue::TypeString;
}
}
/**
* Base class for getting ROS parameters in C++.
*
* This class is used by derived classes used for handling scalar and array
* parameter values.
*/
class SimulinkParameterGetterBase
{
public:
void initialize(const std::string& pName);
void initialize_error_codes(uint8_t codeSuccess, uint8_t codeNoParam, uint8_t codeTypeMismatch, uint8_t codeArrayTruncate);
protected:
ros::NodeHandle* nodePtr; ///< Pointer to node handle (node will be used to connect to parameter server)
std::string paramName; ///< The name of the parameter
bool hasValidValue; ///< Indicates if a valid value has been received yet. If TRUE, this last value will be stored in lastValidValue.
uint8_t errorCodeSuccess; ///< Returned if parameter was retrieved successfully.
uint8_t errorCodeNoParam; ///< Returned if parameter does not exist on server.
uint8_t errorCodeTypeMismatch; ///< Returned if parameter data type did not match.
uint8_t errorCodeArrayTruncate; ///< Returned if received array was truncated.
};
/**
* Class for getting scalar ROS parameters in C++.
*
* This class is used by code generated from the Simulink ROS
* parameter blocks and is templatized by the expected C++ data type
* for the parameter value.
*/
template <class CppParamType, class ROSCppParamType>
class SimulinkParameterGetter : public SimulinkParameterGetterBase
{
public:
void set_initial_value(const CppParamType initValue);
uint8_t get_parameter(CppParamType* dataPtr);
private:
CppParamType initialValue; ///< The default value that should be returned by get_parameter if one of the error conditions occurs
CppParamType lastValidValue; ///< The last valid value that was received from the parameter server
uint8_t process_received_data(CppParamType* dataPtr, bool paramRetrieved);
};
/**
* Set initial value for returned parameter value.
*
* This initial value will be returned if the parameter does not exist or does not have the correct data type when the node is started.
* @param[in] initValue The initial value.
*/
template <class CppParamType, class ROSCppParamType>
void SimulinkParameterGetter<CppParamType,ROSCppParamType>::set_initial_value(const CppParamType initValue)
{
initialValue = initValue;
lastValidValue = initValue;
}
/**
* Get the value for a named parameter from the parameter server.
* @param[out] dataPtr Pointer to initialized data variable. The retrieved parameter value will be written to this location
* @return Error code (=0 if value was read successfully, >0 if an error occurred)
*/
template <class CppParamType, class ROSCppParamType>
uint8_t SimulinkParameterGetter<CppParamType,ROSCppParamType>::get_parameter(CppParamType* dataPtr)
{
XmlRpc::XmlRpcValue xmlValue;
ROSCppParamType paramValue;
bool paramRetrieved = false;
// Get parameter as XmlRpcValue and then parse it through our own function
if (nodePtr->getParam(paramName, xmlValue))
{
paramRetrieved = param_parser::getScalar(xmlValue, paramValue);
}
// Cast the returned value into the data type that Simulink is expecting
*dataPtr = static_cast<CppParamType>(paramValue);
const uint8_t errorCode = process_received_data(dataPtr, paramRetrieved);
return errorCode;
}
/**
* Determine value and error code for retrieved parameter
* @param[in,out] dataPtr Pointer to initialized data variable. The retrieved parameter value will be written to this location
* @param[in] paramRetrieved Return value from ROS function for getting a parameter value
* @return Error code (=0 if value was read successfully, >0 if an error occurred)
*/
template <class CppParamType, class ROSCppParamType>
uint8_t SimulinkParameterGetter<CppParamType,ROSCppParamType>::process_received_data(CppParamType* dataPtr, bool paramRetrieved)
{
// By default, assume that parameter can be retrieved successfully
uint8_t errorCode = errorCodeSuccess;
if (!paramRetrieved)
{
// An error code of "errorCodeNoParam" means that the parameter does not exist and
// "errorCodeTypeMismatch" means that it exists, but the data types don
没有合适的资源?快使用搜索试试~ 我知道了~
matlab2016B robotics toolbox
共3315个文件
m:3095个
png:148个
mat:14个
需积分: 43 60 下载量 31 浏览量
2017-10-03
21:14:07
上传
评论 2
收藏 21.85MB RAR 举报
温馨提示
资源为Matlab 2016B版本的robotics toolbox工具箱,使用时只需解压至matlab的toolbox安装路径即可使用!
资源推荐
资源详情
资源评论
收起资源包目录
matlab2016B robotics toolbox (3315个子文件)
ex_multiple_topics.bag 23.64MB
rosbagWithSensorData.bag 2.32MB
linuxUDP.c 6KB
csleepfun_linux.c 2KB
csleepfun_mac.c 777B
ctimefun_mac.c 760B
ctimefun_linux.c 717B
ctimefun_windows.c 520B
csleepfun_windows.c 470B
roundtolong.c 279B
slros_generic_param.cpp 1KB
libssh2.dll 172KB
slros_generic_param.h 18KB
slros_msgconvert_utils.h 18KB
slros_generic_pubsub.h 4KB
ctimefun.h 566B
csleepfun.h 406B
roundtolong.h 336B
slros_generic.h 267B
functionSignatures.json 8KB
ROSMsgConsts.m 462KB
FaceDetected.m 110KB
exampleHelperWGPR2Kinect.m 95KB
RigidBodyTree.m 56KB
VectorFieldHistogram.m 53KB
OccupancyGrid.m 53KB
ExampleHelperRobotSimulator.m 42KB
NetworkIntrospection.m 37KB
TurtlebotSensorState.m 36KB
RawTurtlebotSensorState.m 35KB
DVL.m 33KB
DeviceDiagnostics.m 31KB
TransformationTree.m 31KB
Net.m 29KB
Parsing.m 28KB
Navdata.m 28KB
PointCloud2.m 28KB
DeviceInfo.m 27KB
rosdevice.m 27KB
BagSelection.m 26KB
PRM.m 26KB
DeviceSensorALL.m 26KB
ImageMarker2.m 25KB
ParameterTree.m 25KB
navdata_pwm.m 25KB
ActuatorStatistics.m 24KB
MonteCarloLocalization.m 24KB
GPSFix.m 24KB
Duration.m 24KB
Subscriber.m 24KB
GatewayInfo.m 23KB
RobotState.m 23KB
OccupancyGridBase.m 23KB
navdata_vision.m 23KB
DeviceParameterSpecifier.m 22KB
SimpleActionClient.m 22KB
Time.m 21KB
Rate.m 21KB
RobotMsg.m 21KB
navdata_references.m 21KB
RoombaSensorState.m 21KB
PlannerGraph.m 20KB
PR2GripperSensorRawData.m 20KB
ArraySizeManager.m 20KB
Message.m 20KB
navdata_vision_detect.m 20KB
BinaryOccupancyGrid.m 20KB
BagParser.m 20KB
navdata_kalman_pressure.m 20KB
navdata_magneto.m 20KB
Image.m 19KB
Marker.m 19KB
PickupGoal.m 19KB
CollisionObject.m 19KB
navdata_raw_measures.m 19KB
GeneralStatus.m 19KB
MotorTraceSample.m 19KB
PlanningScene.m 19KB
ActionIntrospection.m 19KB
Object.m 19KB
SegwayStatus.m 19KB
NavigationSolution.m 19KB
JTCartesianControllerState.m 19KB
LandmarkDetected.m 19KB
SEAJointState.m 19KB
JointCommand.m 18KB
NetworkAddressSpecifier.m 18KB
SensorState.m 18KB
Joint.m 18KB
ServiceClient.m 18KB
JointControllerState.m 18KB
CalibratedInstallationParameters.m 18KB
Node.m 18KB
ImageMarker.m 18KB
InverseKinematics.m 18KB
GNSSAuxStatus.m 18KB
ParticleFilter.m 17KB
GNSSStatus.m 17KB
GPSStatus.m 17KB
GetParameter.m 17KB
共 3315 条
- 1
- 2
- 3
- 4
- 5
- 6
- 34
资源评论
qq_40262448
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功