Home        Store        Docs        Blog

Thrusters moving without command


(Esteban) #1

Hi,

I recently installed the new ESC in an AUV, and noticed that the thrusters rotate about every 20 seconds slowly without giving any command. We are using arduino to drive the ESCs. Any idea of what may be causing this?


Basic ESC Control Issues
(TCIII) #2

@estelome,

Are you using PWM or I2C to control the Blue ESC?

Regards,
TCIII AVD


(Esteban) #3

We are using PWM.


(Daniel Heideman) #4

Hi @estelome,

When you say they turn without giving any command, are you giving the ESCs a 1500 µs neutral signal, or are you sending no PWM signal at all?

Sometimes when the ESCs receive a signal right at the edge of their deadband they will occasionally turn the thrusters slowly for a second or two. This is because the ESCs can sometimes interpret two pulses of the same length as slightly different values, most notably with one being barely neutral and one being just beyond the deadband.


(Esteban) #5

The ESCs are you giving a 1500 µs neutral signal


(Jacob) #6

Make a video of the problem please and put your code online for us to see. It is not clear what the problem is without these things.


(Adam) #7

Esteban,

Can you please clarify this:

Does this mean the thrusters rotate slowly for a short period about every 20 seconds, or they continuously rotate very slowly completing a revolution every 20 seconds?

Can you please also clarify which ESC you have? The integrated Blue ESC has been discontinued for over two years now, do you have that or the Basic ESC?

-Adam


(Esteban) #8

The thrusters rotate about every 20 seconds slowly for a short period of time (about 1 sec). We have de Basic ESC.


(Jacob) #9

Can you do this @estelome?


(Esteban) #10
#include <Motors.h>
#include <Servo.h>
#include <string.h>

#define VERTICAL_PIN_0 2
#define VERTICAL_PIN_1 3
#define VERTICAL_PIN_2 4
#define VERTICAL_PIN_3 5
#define HORIZONTAL_PIN_0 6
#define HORIZONTAL_PIN_1 7
#define HORIZONTAL_PIN_2 8
#define HORIZONTAL_PIN_3 9

#define PWM_RANGE 4
#define PWM_NEUTRAL 1500

Servo vertSpeedController[4];
Servo horizontalSpeedController[4];

bool verticalInitialized = false;
bool horizontalInitialized = false;
bool oldDesign = true;



int speedToMicroseconds(int speed){
  if(speed >= -100 && speed <= 100){
    return PWM_RANGE*speed + PWM_NEUTRAL;
  }
  else{
    return 0;
  }
}


void initializeVerticalMotors(){
	vertSpeedController[0].attach(VERTICAL_PIN_0);
	vertSpeedController[1].attach(VERTICAL_PIN_1);
	vertSpeedController[2].attach(VERTICAL_PIN_2);
	vertSpeedController[3].attach(VERTICAL_PIN_3);
	verticalInitialized = true;
}


void setVerticalMotorSpeed(int speed){
	if(verticalInitialized){
		int microseconds = speedToMicroseconds(speed);
		vertSpeedController[0].writeMicroseconds(microseconds);
		vertSpeedController[1].writeMicroseconds(microseconds);
		vertSpeedController[2].writeMicroseconds(microseconds);
		vertSpeedController[3].writeMicroseconds(microseconds);
	}
}


void initializeHorizontalMotors(char *old){
	if(strcmp(old, "old") == 0){
		oldDesign = true;
		
	}else{
		oldDesign = false;
	}
	horizontalSpeedController[0].attach(HORIZONTAL_PIN_0);
	horizontalSpeedController[1].attach(HORIZONTAL_PIN_1);
	if(!oldDesign){
		horizontalSpeedController[2].attach(HORIZONTAL_PIN_2);
		horizontalSpeedController[3].attach(HORIZONTAL_PIN_3);
	}
	horizontalInitialized = true;
}	
	
void setHorizontalMotorSpeed(int left_motor, int right_motor){
	if(horizontalInitialized){
		horizontalSpeedController[0].writeMicroseconds(speedToMicroseconds(left_motor));
		horizontalSpeedController[1].writeMicroseconds(speedToMicroseconds(right_motor));
	}
}
void setHorizontalMotorSpeed(int motor1, int motor2, int motor3, int motor4){
	if(horizontalInitialized){
		horizontalSpeedController[0].writeMicroseconds(speedToMicroseconds(motor1));
		horizontalSpeedController[1].writeMicroseconds(speedToMicroseconds(motor2));
		if(!oldDesign){
			horizontalSpeedController[2].writeMicroseconds(speedToMicroseconds(motor3));
			horizontalSpeedController[3].writeMicroseconds(speedToMicroseconds(motor4));
		}
		
	}
}

(Patrick José Pereira) #11

Hi,

To be able to be fully helpful, can you share the entire code ? The “main” and “setup” of arduino is not there.

If sharing the full code is not possible, please share a minimum version that can be compiled.


(Esteban) #12

Link to the video:

This is the moment the arduino turns on.

Code:

#include <Arduino.h>
#include <ros.h>
#include <geometry_msgs/Twist.h>
#include <std_msgs/Int32.h>
#include <std_msgs/Float32.h>
#include <rumarino_package/HorizontalMotors.h>
#include <Motors.h>
#include <Wire.h>
#include <MS5837.h>


std_msgs::Float32 depth;
MS5837 pressureSensor;


// Callback function for left motors
void setHorizontalMotors(const rumarino_package::HorizontalMotors&  motorIntensity)
{
   setHorizontalMotorSpeed(motorIntensity.rightMotor, motorIntensity.leftMotor);
}

// Callback function for simultaneous usage of motors
void setVerticalMotors(const std_msgs::Int32& motorIntensity)
{
    setVerticalMotorSpeed(motorIntensity.data);
}


ros::NodeHandle nh;

// Creates all the ROS subscriber objects 
ros::Subscriber<std_msgs::Int32> subVerticalMotors("vertical_motors", setVerticalMotors);
ros::Subscriber<std_msgs::Int32> subHorizontalMotors("horizontal_motors", setHorizontalMotors);

// Create the pressure sensor publisher 
ros::Publisher pubToPressureSensor("depth_current", &depth);


void setup() {
  // Initializes the node and prepares for publishing and subscribing.
  nh.initNode();
  nh.advertise(pubToPressureSensor);
  nh.subscribe(subVerticalMotors);
  nh.subscribe(subHorizontalMotors);

  // Initializes all the motors
  initializeVerticalMotors();
  initializeHorizontalMotors("old");

  Initializes wire (protocol to run)
  Wire.begin(); 

  // If pressure sensor does not initialize, throw error
  while(!pressureSensor.init())
  {
      nh.logerror("Pressure sensor cannot initialize.");
  }

}

void loop() 
{
  pressureSensor.read();

  depth.data = pressureSensor.depth()*(3.3);

  pubToPressureSensor.publish(&depth);

  nh.spinOnce();
}

(Patrick José Pereira) #13

Hi,

Try to add writeMicroseconds(1500) in initializeVerticalMotors() function. The output state of the Servo pins are not defined.


(Jacob) #14

@estelome, this code is complex, and the problem you are seeing is probably a bug in your code. Try to use our example sketch to determine if there is a problem with the thruster or esc.