Go Down

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

#### psathammer

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

#1
##### Jan 12, 2019, 02:45 pm
Post the whole thing, there's nothing in what you posted that shows how you generated that output.

#### psathammer

#2
##### Jan 12, 2019, 10:29 pm
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