ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

hector quadrotor motor pwm

asked 2015-09-21 17:02:45 -0500

lonewolf gravatar image

I am using hector quadrotor model inorder to simulate a neural network. The idea is simulate a neural network created in the paper http://flyingmachinearena.org/wp-cont... . I know I will be able to spin it using /cmd_val angular velocity z.But I am not sure how to flip it. I wanted to make use of the /motor_pwm to do this. But I have been unable to get it to work. I tried writing an array of four values liike [100 100 60 100].

Can anyone help me as to how motor_pwm can be used to move the quadrotor.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-05-21 09:39:12 -0500

phoenixinwater gravatar image

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

edit flag offensive delete link more
0

answered 2017-01-09 05:08:53 -0500

Wararray gravatar image

updated 2017-01-09 05:35:41 -0500

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!

edit flag offensive delete link more

Comments

Can please you shed some light on how you were able to get this working? Trying to achieve a similar task, and publishing to the /motor_pwm topic gives me "Command timed out. Disabled motors.". Were you just running the quadrotor outdoor demo in gazebo? Did you also need to run the gazebo plugins?

rlee3359 gravatar image rlee3359  ( 2017-02-20 03:39:47 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-09-21 17:02:45 -0500

Seen: 866 times

Last updated: Jan 09 '17