32 serialInterface1(
"/dev/teensy1"),
33 serialInterface2(
"/dev/teensy2")
45 NUM_MOTORS { _num_motors }
104 std::vector<double> commands_port_1(_pos.begin(), _pos.begin() + this->num_motors_port_1);
105 std::vector<double> commands_port_2(_pos.begin() + this->num_motors_port_1, _pos.end());
120 std::vector<double> commands_port_1(_vel.begin(), _vel.begin() + this->num_motors_port_1);
121 std::vector<double> commands_port_2(_vel.begin() + this->num_motors_port_1, _vel.end());
136 std::vector<double> commands_port_1(_torque.begin(), _torque.begin() + this->num_motors_port_1);
137 std::vector<double> commands_port_2(_torque.begin() + this->num_motors_port_1, _torque.end());
194 if ((!_msg->position.empty()) && (_msg->position.size() == this->NUM_MOTORS))
199 else if ((!_msg->velocity.empty()) && (_msg->velocity.size() == this->NUM_MOTORS))
204 else if ((!_msg->effort.empty()) && (_msg->effort.size() == this->NUM_MOTORS))
210 ROS_ERROR(
"[MotorInterface::OnJointStateCmdMsg] Message failed to match specifications!");
217 ros::Rate loop_rate(10000);
230 static const double timeout = 0.0001;
240 static const double timeout = 0.0001;
252 std_srvs::Empty::Response &_res)
262 if (!ros::isInitialized())
269 "motor_interface_node",
270 ros::init_options::NoSigintHandler
274 this->
rosNode.reset(
new ros::NodeHandle(
"motor_interface_node"));
276 ros::AdvertiseServiceOptions shutdown_aso =
277 ros::AdvertiseServiceOptions::create<std_srvs::Empty>(
278 "/my_robot/motor_interface/shutdown",
284 ros::SubscribeOptions joint_state_cmd_so =
285 ros::SubscribeOptions::create<sensor_msgs::JointState>(
286 "/my_robot/joint_state_cmd",
294 ros::AdvertiseOptions joint_state_ao =
295 ros::AdvertiseOptions::create<sensor_msgs::JointState>(
296 "/my_robot/joint_state",
298 ros::SubscriberStatusCallback(),
299 ros::SubscriberStatusCallback(),
int num_motors_port_2
The number of motors interfaced by the second Teensy.
void InitRosQueueThreads()
The InitRosQueueThreads function is called to initialize the ROS Publish and Process Queue Threads.
std::thread rosPublishQueueThread
Thread running the rosPublishQueue.
std::thread rosProcessQueueThread
Thread running the rosProcessQueue.
void ProcessSerialMessages()
Checks if there are any incomming messages from the serial ports. If there are new replies these are ...
void RosProcessQueueThread()
The RosProcessQueueThread function is a ROS helper function that processes messages.
SerialCommunication serialInterface2
The serial interface used to communicate with the second Teensy.
void SerialProcessQueueThread()
The SerialProcessQueueThread function is a helper function that processes serial messages.
void RosPublishQueueThread()
The RosPublishQueueThread function is a ROS helper function that publish state messages.
const int NUM_MOTORS
The number of motors to interface with.
void SetJointPositions(const std::vector< double > &_pos)
Set the position of the joints.
void OnJointStateCmdMsg(const sensor_msgs::JointStateConstPtr &_msg)
The OnGenCoordMsg function handles an incoming generalized coordinates message from ROS.
virtual ~MotorInterface()
Destructor.
void SetJointTorques(const std::vector< double > &_torque)
Set the torque of the joints.
static constexpr int MAX_NUM_MOTORS_PER_PORT
The maximum numbers of motors to be interfaced with by one Teensy.
ros::CallbackQueue rosPublishQueue
ROS callbackque that helps publish messages.
ros::Publisher jointStatePub
ROS Joint State Publisher.
void InitRos()
The InitRos function is called to initialize ROS.
sensor_msgs::JointState jointStateMsg
Joint State Message.
std::thread serialProcessQueueThread
Thread running the serialProcessQueue.
ros::Subscriber jointStateCmdSub
ROS Joint State Command Subscriber.
ros::ServiceServer shutdownService
ROS Shutdown Service.
MotorInterface()
Default Constructor.
SerialCommunication serialInterface1
The serial interface used to communicate with the first Teensy.
bool Shutdown(const std_srvs::Empty::Request &_req, std_srvs::Empty::Response &_res)
The Shutdown function handles an incoming shutdown service request.
ros::CallbackQueue rosProcessQueue
ROS callbackque that helps process messages.
std::unique_ptr< ros::NodeHandle > rosNode
Node used for ROS transport.
int num_motors_port_1
The number of motors interfaced by the first Teensy.
void SetJointVelocities(const std::vector< double > &_vel)
Set the velocity of the joints.
void SetNumberOfMotors(const int &_number_of_motors)
Set the number of motors for the port after creating the constructor.
void InitLibSerial()
The InitLibSerial function initializes the serial port to the correct input and sets baud rate,...
void SendMessage(const ControlMode &_control_mode, const std::vector< double > &_state)
The SendMessage function handles the sending of joint state command messages to the motors.
bool IsNewDataAvailable()
The IsNewDataAvailable function checks if there is available data on the serial port.
void SetPort(const std::string &_port)
Set the port for the Teensy communication after creating the constructor.
Eigen::Matrix< Eigen::VectorXd, 3, 1 > ReceiveMessage()
The ReceiveMessage function listens for serial messages of incoming joint state data from the motors ...