Ask Your Question

Revision history [back]

Hey mate, I was just messing around with it before and here is what I have got so far:

#include "hector_uav_msgs/MotorPWM.h"
#include <stdint.h>
#include <inttypes.h>
#include <vector>
std::vector<unsigned char> pwmsHigh (4, 255); // MAX POWER
std::vector<unsigned char> pwmsLow (4, 0); // MIN POWER
(in main)
ros::Publisher motor_commander_1 = n.advertise<hector_uav_msgs::MotorPWM>("uav1/motor_pwm", 100);   
while (ros::ok()) // Check for ctrl+c and ROS
{
  hector_uav_msgs::MotorPWM msg1;
  msg1.pwm = pwmsHigh;
  motor_commander_1.publish(msg1); // Publish msg
  sleep(2);
  hector_uav_msgs::MotorPWM msg1Stop;   
  motor_commander_1.publish(msg1Stop); // Publish msg
  sleep(2);
  ros::spinOnce();
  loop_rate.sleep();
}

As a disclaimer, I was getting an error for losing commands in the Gazebo window... but this will get your quad moving :) I mainly used the hector_quad_rotor package description page and their github for this