Go Down

Topic: Rov Thruster setup (Read 181 times) previous topic - next topic

psathammer

Jan 11, 2019, 10:00 pm Last Edit: Jan 11, 2019, 11:03 pm by psathammer
Hi
I'm trying to learn about arduino and make my own ROV
I wan't to build a vectorized setup with the thruster
I found cone by searching and manage to get it to work. But the calculated output is not looking correct. When I puch the joystick forward it gives not same value on all thrusters as it should. It will go in circles as it is now.
Can anyone point me in the right direction or help me with the code?

The code for topside is this for now
Code: [Select]
*///Setting a global deadband for use when mapping values
  const int DbH = 510;
  const int DbL = 490;
 
 
void setup() {
  Serial.begin(9600);
 
}

void loop() {
 
  //Reads analog value from the joystick
  int joyval_fa = analogRead(A0); //Forward/Aft
  int joyval_tr = analogRead(A1); //Turn
  int joyval_lat = analogRead(A2); //Lateral
  int joyval_vertical = analogRead(A3); //vertical
 
  //Converts analog value to -400 to 400. And setting a preset
  //deaband defind before
  int ForwardAft_1 = map(joyval_fa,DbH,1023,0,400);
  int ForwardAft_2 = map(joyval_fa,DbL,0,0,-400);
  int ForwardAft = (ForwardAft_1 + ForwardAft_2);
  int Turn_1 = map(joyval_tr,DbH,1023,0,400);
  int Turn_2 = map(joyval_tr,DbL,0,0,-400);
  int Turn = (Turn_1 + Turn_2);
  int Lateral_1 = map(joyval_lat,DbH,1023,0,400);
  int Lateral_2 = map(joyval_lat,DbL,0,0,-400);
  int Lateral = (Lateral_1 + Lateral);

  float fwd_factor = 1;
  float Turn_factor = 1;
  float Lateral_factor = 1;

  int base_command = 0; // Value that will set motors to stopped
  //Calculating thruster output
  int frontLeftThruster = base_command - fwd_factor*ForwardAft - Turn_factor*Turn - Lateral_factor*Lateral;
  int backLeftThruster = base_command + fwd_factor*ForwardAft - Turn_factor*Turn+ Lateral_factor*Lateral;
  int backRightThruster = base_command + fwd_factor*ForwardAft + Turn_factor*Turn - Lateral_factor*Lateral;
  int frontRightThruster = base_command - fwd_factor*ForwardAft + Turn_factor*Turn + Lateral_factor*Lateral;


And this is the output it gives when you go forward with the joystick
Code: [Select]

FwdPort: -567 FwdStbd: -685 AftPort: 585 AftStbd: 667
FwdPort: -564 FwdStbd: -686 AftPort: 582 AftStbd: 668
FwdPort: -560 FwdStbd: -690 AftPort: 578 AftStbd: 672
FwdPort: -559 FwdStbd: -697 AftPort: 577 AftStbd: 679
FwdPort: -552 FwdStbd: -704 AftPort: 570 AftStbd: 686
FwdPort: -553 FwdStbd: -713 AftPort: 571 AftStbd: 695
FwdPort: -551 FwdStbd: -721 AftPort: 569 AftStbd: 703
FwdPort: -553 FwdStbd: -729 AftPort: 571 AftStbd: 711
FwdPort: -557 FwdStbd: -733 AftPort: 575 AftStbd: 715
FwdPort: -558 FwdStbd: -736 AftPort: 576 AftStbd: 718
FwdPort: -557 FwdStbd: -733 AftPort: 575 AftStbd: 715
FwdPort: -558 FwdStbd: -732 AftPort: 576 AftStbd: 714
FwdPort: -561 FwdStbd: -733 AftPort: 579 AftStbd: 715
FwdPort: -562 FwdStbd: -736 AftPort: 584 AftStbd: 714
FwdPort: -563 FwdStbd: -731 AftPort: 581 AftStbd: 713
FwdPort: -562 FwdStbd: -728 AftPort: 580 AftStbd: 710
FwdPort: -566 FwdStbd: -732 AftPort: 584 AftStbd: 714
FwdPort: -566 FwdStbd: -736 AftPort: 588 AftStbd: 714
FwdPort: -567 FwdStbd: -731 AftPort: 585 AftStbd: 713
FwdPort: -566 FwdStbd: -732 AftPort: 584 AftStbd: 714
FwdPort: -566 FwdStbd: -732 AftPort: 584 AftStbd: 714
FwdPort: -568 FwdStbd: -734 AftPort: 586 AftStbd: 716
FwdPort: -568 FwdStbd: -734 AftPort: 586 AftStbd: 716
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -571 FwdStbd: -731 AftPort: 585 AftStbd: 717
FwdPort: -568 FwdStbd: -734 AftPort: 586 AftStbd: 716
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -567 FwdStbd: -731 AftPort: 585 AftStbd: 713
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -572 FwdStbd: -734 AftPort: 590 AftStbd: 716
FwdPort: -570 FwdStbd: -736 AftPort: 592 AftStbd: 714
FwdPort: -572 FwdStbd: -734 AftPort: 590 AftStbd: 716
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -569 FwdStbd: -733 AftPort: 587 AftStbd: 715
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -571 FwdStbd: -735 AftPort: 589 AftStbd: 717
FwdPort: -572 FwdStbd: -734 AftPort: 586 AftStbd: 720
FwdPort: -571 FwdStbd: -739 AftPort: 593 AftStbd: 717
FwdPort: -573 FwdStbd: -737 AftPort: 591 AftStbd: 719
FwdPort: -573 FwdStbd: -737 AftPort: 591 AftStbd: 719
FwdPort: -574 FwdStbd: -740 AftPort: 592 AftStbd: 722
FwdPort: -575 FwdStbd: -739 AftPort: 593 AftStbd: 721
FwdPort: -577 FwdStbd: -741 AftPort: 595 AftStbd: 723
FwdPort: -573 FwdStbd: -737 AftPort: 591 AftStbd: 719
FwdPort: -575 FwdStbd: -743 AftPort: 597 AftStbd: 721
FwdPort: -577 FwdStbd: -741 AftPort: 595 AftStbd: 723
FwdPort: -575 FwdStbd: -739 AftPort: 593 AftStbd: 721
FwdPort: -574 FwdStbd: -740 AftPort: 592 AftStbd: 722
FwdPort: -579 FwdStbd: -743 AftPort: 597 AftStbd: 725
FwdPort: -579 FwdStbd: -743 AftPort: 597 AftStbd: 725
FwdPort: -579 FwdStbd: -743 AftPort: 597 AftStbd: 725
FwdPort: -583 FwdStbd: -743 AftPort: 601 AftStbd: 725
FwdPort: -579 FwdStbd: -747 AftPort: 601 AftStbd: 725
FwdPort: -578 FwdStbd: -740 AftPort: 596 AftStbd: 722
FwdPort: -581 FwdStbd: -745 AftPort: 603 AftStbd: 723
FwdPort: -580 FwdStbd: -746 AftPort: 602 AftStbd: 724
FwdPort: -580 FwdStbd: -742 AftPort: 598 AftStbd: 724
FwdPort: -584 FwdStbd: -742 AftPort: 598 AftStbd: 728
FwdPort: -580 FwdStbd: -746 AftPort: 602 AftStbd: 724
FwdPort: -582 FwdStbd: -744 AftPort: 600 AftStbd: 726
FwdPort: -580 FwdStbd: -746 AftPort: 602 AftStbd: 724
FwdPort: -584 FwdStbd: -746 AftPort: 602 AftStbd: 728
FwdPort: -585 FwdStbd: -749 AftPort: 603 AftStbd: 731
FwdPort: -579 FwdStbd: -743 AftPort: 597 AftStbd: 725
FwdPort: -581 FwdStbd: -745 AftPort: 599 AftStbd: 727
FwdPort: -582 FwdStbd: -744 AftPort: 600 AftStbd: 726

I are also having some problem to zero the output. Tried with deadband, but it seems not to work properly
FwdPort: 21 FwdStbd: -19 AftPort: 23 AftStbd: -25
This is when all joysticks are in neutral

wildbill

Post the whole thing, there's nothing in what you posted that shows how you generated that output.

psathammer

Hi Wildbill
Here is the complete code.
The only thing i did not post in my first post, was the serial.print lines
Code: [Select]
*Surface controller software

*///Setting a global deadband for use when mapping values
  const int DbH = 510;
  const int DbL = 505;
 
 
void setup() {
  Serial.begin(9600);
 
}

void loop() {
 
  //Reads analog value from the joystick
  int joyval_fa = analogRead(A0); //Forward/Aft
  int joyval_tr = analogRead(A1); //Turn
  int joyval_lat = analogRead(A2); //Lateral
  int joyval_vertical = analogRead(A3); //vertical
 
  //Converts analog value to -400 to 400. And setting a preset
  //deaband defind before
  int ForwardAft_1 = map(joyval_fa,DbH,1023,0,400);
  int ForwardAft_2 = map(joyval_fa,DbL,0,0,-400);
  int ForwardAft = (ForwardAft_1 + ForwardAft_2);
  int Turn_1 = map(joyval_tr,DbH,1023,0,400);
  int Turn_2 = map(joyval_tr,DbL,0,0,-400);
  int Turn = (Turn_1 + Turn_2);
  constrain(Turn_1, 0, 400);
  constrain(Turn_2, 0, 400);
 
  int Lateral_1 = map(joyval_lat,DbH,1023,0,400);
  int Lateral_2 = map(joyval_lat,DbL,0,0,-400);
  int Lateral = (Lateral_1 + Lateral);

  float fwd_factor = 1;
  float Turn_factor = 1;
  float Lateral_factor = 1;

  int base_command = 0; // Value that will set motors to stopped
  //Calculating thruster output
  int frontLeftThruster = base_command - fwd_factor*ForwardAft - Turn_factor*Turn - Lateral_factor*Lateral;
  int backLeftThruster = base_command + fwd_factor*ForwardAft - Turn_factor*Turn+ Lateral_factor*Lateral;
  int backRightThruster = base_command + fwd_factor*ForwardAft + Turn_factor*Turn - Lateral_factor*Lateral;
  int frontRightThruster = base_command - fwd_factor*ForwardAft + Turn_factor*Turn + Lateral_factor*Lateral;

  // Code to output those values to the thrusters
  Serial.print("FwdPort: ");
  Serial.print(frontLeftThruster);
  Serial.print(" FwdStbd: ");
  Serial.print(frontRightThruster);
  Serial.print(" AftPort: ");
  Serial.print(backLeftThruster);
  Serial.print(" AftStbd: ");
  Serial.println(backRightThruster);

 
 
  delay(30);



Go Up