36 #include <vesc_msgs/VescStateStamped.h> 41 using std::placeholders::_1;
48 duty_cycle_limit_(private_nh,
"duty_cycle", -1.0, 1.0), current_limit_(private_nh,
"current"),
49 brake_limit_(private_nh,
"brake"), speed_limit_(private_nh,
"speed"),
50 position_limit_(private_nh,
"position"), servo_limit_(private_nh,
"servo", 0.0, 1.0),
51 driver_mode_(MODE_INITIALIZING), fw_version_major_(-1), fw_version_minor_(-1)
55 if (!private_nh.
getParam(
"port", port))
57 ROS_FATAL(
"VESC communication port parameter required.");
112 ROS_FATAL(
"Unexpectedly disconnected from serial port.");
129 ROS_INFO(
"Connected to VESC with firmware version %d.%d",
142 assert(
false &&
"unknown driver mode");
148 if (packet->name() ==
"Values")
150 std::shared_ptr<VescPacketValues const> values =
153 vesc_msgs::VescStateStamped::Ptr state_msg(
new vesc_msgs::VescStateStamped);
155 state_msg->state.voltage_input = values->v_in();
156 state_msg->state.temperature_pcb = values->temp_pcb();
157 state_msg->state.current_motor = values->current_motor();
158 state_msg->state.current_input = values->current_in();
159 state_msg->state.speed = values->rpm();
160 state_msg->state.duty_cycle = values->duty_now();
161 state_msg->state.charge_drawn = values->amp_hours();
162 state_msg->state.charge_regen = values->amp_hours_charged();
163 state_msg->state.energy_drawn = values->watt_hours();
164 state_msg->state.energy_regen = values->watt_hours_charged();
165 state_msg->state.displacement = values->tachometer();
166 state_msg->state.distance_traveled = values->tachometer_abs();
167 state_msg->state.fault_code = values->fault_code();
171 else if (packet->name() ==
"FWVersion")
173 std::shared_ptr<VescPacketFWVersion const> fw_version =
263 std_msgs::Float64::Ptr servo_sensor_msg(
new std_msgs::Float64);
264 servo_sensor_msg->data = servo_clipped;
270 const boost::optional<double>& min_lower,
271 const boost::optional<double>& max_upper) :
278 if (min_lower && param_min < *min_lower)
282 ") is less than the feasible minimum (" << *min_lower <<
").");
284 else if (max_upper && param_min > *max_upper)
288 ") is greater than the feasible maximum (" << *max_upper <<
").");
304 if (min_lower && param_max < *min_lower)
308 ") is less than the feasible minimum (" << *min_lower <<
").");
310 else if (max_upper && param_max > *max_upper)
314 ") is greater than the feasible maximum (" << *max_upper <<
").");
330 <<
") is less than parameter " <<
name <<
"_min (" << *
lower <<
").");
336 std::ostringstream oss;
337 oss <<
" " <<
name <<
" limit: ";
339 else oss <<
"(none) ";
341 else oss <<
"(none)";
349 ROS_INFO_THROTTLE(10,
"%s command value (%f) below minimum limit (%f), clipping.",
355 ROS_INFO_THROTTLE(10,
"%s command value (%f) above maximum limit (%f), clipping.",
CommandLimit current_limit_
void dutyCycleCallback(const std_msgs::Float64::ConstPtr &duty_cycle)
int fw_version_major_
firmware major version reported by vesc
ros::Subscriber servo_sub_
void publish(const boost::shared_ptr< M > &message) const
CommandLimit speed_limit_
ros::Subscriber brake_sub_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void vescPacketCallback(const std::shared_ptr< VescPacket const > &packet)
boost::optional< double > lower
void servoCallback(const std_msgs::Float64::ConstPtr &servo)
void setPosition(double position)
CommandLimit position_limit_
driver_mode_t driver_mode_
driver state machine mode (state)
void positionCallback(const std_msgs::Float64::ConstPtr &position)
ros::Subscriber position_sub_
void setDutyCycle(double duty_cycle)
void connect(const std::string &port)
void currentCallback(const std_msgs::Float64::ConstPtr ¤t)
CommandLimit duty_cycle_limit_
void setCurrent(double current)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
virtual const char * what() const
int fw_version_minor_
firmware minor version reported by vesc
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void brakeCallback(const std_msgs::Float64::ConstPtr &brake)
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
void setBrake(double brake)
CommandLimit brake_limit_
ros::Publisher state_pub_
void setServo(double servo)
ros::Subscriber current_sub_
ros::Publisher servo_sensor_pub_
void speedCallback(const std_msgs::Float64::ConstPtr &speed)
void setSpeed(double speed)
VescDriver(ros::NodeHandle nh, ros::NodeHandle private_nh)
bool getParam(const std::string &key, std::string &s) const
ros::Subscriber duty_cycle_sub_
#define ROS_INFO_THROTTLE(rate,...)
ROSCPP_DECL void shutdown()
boost::optional< double > upper
CommandLimit(const ros::NodeHandle &nh, const std::string &str, const boost::optional< double > &min_lower=boost::optional< double >(), const boost::optional< double > &max_upper=boost::optional< double >())
CommandLimit servo_limit_
void timerCallback(const ros::TimerEvent &event)
void vescErrorCallback(const std::string &error)
double clip(double value)
ros::Subscriber speed_sub_