package com.rmrobotics.library;

import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.Range;

public class Motor {

    private static final double MAX_POWER = 1.0;
    private static final double MIN_POWER = 0.1;

    private DcMotor parent;
    private DcMotor.Direction defaultDirection;
    private double minPower;
    private double maxPower;
    private double desiredPower;
    private double currentPower;

    public Motor (DcMotor dc, DcMotor.Direction d, double min, double max){
        parent = dc;
        defaultDirection = d;
        minPower = min;
        maxPower = max;
    } //Todo add string to send in DbgLog confirming motor settings once configured

    public void setDesiredPower(double d){
        desiredPower = d;
    }

    public void updateCurrentPower(){
        /**
         * let it be zero if it needs to be
         * absolute value and switch direction if needed
         * clip to be within range
         *
         */

        if(defaultDirection== DcMotor.Direction.REVERSE){
            desiredPower = -desiredPower;
            minPower = -minPower;
            maxPower=-maxPower;
        }
        desiredPower = Range.clip(desiredPower, minPower, maxPower);

        currentPower =  desiredPower;

    }

    public void setCurrentPower(){
        parent.setPower(currentPower);
    }



}

@@ -1002,52 +1002,294 @@
 f(de
-faultDirection== DcMotor.Direction.REVERSE)%7B
+siredPower%3C0)%7B%0A            if(defaultDirection = DcMotor.Direction.FORWARDS;)%7B%0A                defaultDirection = DcMotor.Direction.REVERSE;%0A            %7Delse if (defaultDirection = DcMotor.Direction.REVERSE)%7B%0A                defaultDirection = DcMotor.Direction.FORWARDS;%0A            %7D
 %0A   
@@ -1312,17 +1312,25 @@
 Power = 
--
+Math.abs(
 desiredP
@@ -1329,24 +1329,25 @@
 desiredPower
+)
 ;%0A          
@@ -1363,17 +1363,25 @@
 r = 
--
+Math.abs(
 minPower
 ;%0A  
@@ -1372,24 +1372,25 @@
 abs(minPower
+)
 ;%0A          
@@ -1404,17 +1404,25 @@
 wer=
--
+Math.abs(
 maxPower
 ;%0A  
@@ -1413,24 +1413,25 @@
 abs(maxPower
+)
 ;%0A        %7D%0A

Fix motor class