Ask Your Question

Wararray's profile - activity

2017-01-17 15:49:04 -0600 received badge  Enthusiast
2017-01-09 05:15:35 -0600 answered a question hector quadrotor motor pwm

So, I took the phoenixinwater1 and did some changes. I took out the "stop" message command and put it in more some common form (like the main). Also, I insert some missing functions, as rosinit. For me, is working now. This code, of course, has no controlling action, but after this changes you really can see it fly by PWM data. Hope it help. there goes the code. (Ps.: I called the program file "teste" because I was not sure if it would run properly. Sorry about that.)

#include "hector_uav_msgs/MotorPWM.h"
#include "ros/ros.h"
#include <stdint.h>
#include <vector>

std::vector<unsigned char> pwmsHigh (4, 225); // MAX POWER
std::vector<unsigned char> pwmsLow (4, 0); // MIN POWER

int main(int argc, char *argv[])
{

ros::init(argc, argv, "teste");
ros::NodeHandle n;
ros::Publisher motor_commander_1 = n.advertise<hector_uav_msgs::MotorPWM>("/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();

  ros::Rate loop_rate(50);
  loop_rate.sleep();
}
return 0;
}

Hope it helps!

2017-01-09 04:59:57 -0600 received badge  Supporter (source)