Skip to content

Commit

Permalink
Add velocity scaling and collision feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhrenov committed Jun 5, 2020
1 parent b4b6b57 commit e23f357
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(rvc_ros)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS serial roscpp sensor_msgs std_srvs message_generation)
find_package(catkin REQUIRED COMPONENTS serial roscpp sensor_msgs std_srvs std_msgs)
find_package(fmt)

## System dependencies are found with CMake's conventions
Expand Down
4 changes: 0 additions & 4 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
<exec_depend>std_msgs</exec_depend>
<build_depend>std_srvs</build_depend>
<exec_depend>std_srvs</exec_depend>
<build_depend>message_generation</build_depend>
<exec_depend>message_generation</exec_depend>
<build_depend>message_runtime</build_depend>
<exec_depend>message_runtime</exec_depend>
<build_depend>serial</build_depend>
<exec_depend>serial</exec_depend>

Expand Down
18 changes: 16 additions & 2 deletions rvc_ros_node.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// C/C++ Headers
#include <stdlib.h>
#include <string>
#include <algorithm>

// Utility library headers
#include <boost/algorithm/string.hpp>
Expand All @@ -10,6 +11,7 @@
// ROS Headers
#include <ros/ros.h>
#include <serial/serial.h>
#include <std_msgs/Float32.h>
#include <sensor_msgs/JointState.h>
#include <std_srvs/Empty.h>
#include <std_srvs/SetBool.h>
Expand All @@ -24,13 +26,20 @@ ros::Publisher pub;

// Relative movement subscriber callback
void move(const sensor_msgs::JointState &msg) {
ser->write(fmt::format("m {} {};", msg.position[0], msg.position[1]));
ser->write(fmt::format("m {0:.2f} {1:.2f};", msg.position[0], msg.position[1]));
}


// Absolute movement subscriber callback
void move_to(const sensor_msgs::JointState &msg) {
ser->write(fmt::format("M {} {};", msg.position[0], msg.position[1]));
ser->write(fmt::format("M {0:.2f} {1:.2f};", msg.position[0], msg.position[1]));
}


// Scale maximum velocity of device callback
void velocity_scale(const std_msgs::Float32 &msg) {
float scale = std::min(std::max(msg.data, 0.0f), 1.0f);
ser->write(fmt::format("V {0:.3f};", scale));
}


Expand Down Expand Up @@ -132,6 +141,10 @@ void publishPosition(const ros::TimerEvent &e) {
msg.position[0] = std::stod(results[0]);
msg.position[1] = std::stod(results[1]);

msg.effort.resize(2);
msg.effort[0] = std::stod(results[2]);
msg.effort[1] = std::stod(results[3]);

// Publish and increment sequence counter
pub.publish(msg);
s++;
Expand Down Expand Up @@ -178,6 +191,7 @@ int main(int argc, char **argv) {

ros::Subscriber move_sub = nh.subscribe("move_jr", 1000, &move);
ros::Subscriber move_to_sub = nh.subscribe("move_jp", 1000, &move_to);
ros::Subscriber velocity_scale_sub = nh.subscribe("velocity_scale", 1000, &velocity_scale);

ros::ServiceServer halt_serv = nh.advertiseService("halt", &halt);
ros::ServiceServer tap_serv = nh.advertiseService("tap", &tap);
Expand Down

0 comments on commit e23f357

Please sign in to comment.