Exponents in RMS

So, I tried googling and searching the forums for this, but I can’t find anything. I am trying to drive my robot as an exponential speed of the controller value. I want my robot the drive at the speed at the controller value^3, so it matches this graph: image This is to give my driver greater control over the robot. How would I do this in RMS python for V5, so it is neater than this:

motor_1.spin(vex.DirectionType.FWD, (con.axis1.position(vex.PercentUnits.PCT) * con.axis1.position(vex.PercentUnits.PCT) * con.axis1.position(vex.PercentUnits.PCT)), vex.VelocityUnits.PCT)

Any help would be nice. Thankyou :slight_smile:

1 Like

Looking at google, you should be able to use python’s exponent operator, **
Example:
3 ** 3 = 27

1 Like

so I do: motor_1.spin(vex.DirectionType.FWD, (con.axis1.position(vex.PercentUnits.PCT)**3, vex.VelocityUnits.PCT)?

1 Like

I believe that is correct.
Edit:
Actually you might have an extra parentheses in there.

1 Like

THX :slight_smile:
<20 Charactors>

1 Like

motor_1.spin(vex.DirectionType.FWD, (con.axis1.position(vex.PercentUnits.PCT)**3), vex.VelocityUnits.PCT)?

1 Like

Be sure to divide the result of position ** 3 by 100 ** 2 or it will go out of the range that spin wants (-100 to 100) by the time you’ve moved the joystick even 5% (5 * 5 * 5 = 125).

3 Likes

So I do motor_1.spin(vex.DirectionType.FWD, (con.axis1.position(vex.PercentUnits.PCT)**3)/100, vex.VelocityUnits.PCT)

1 Like

Almost there. Keep track of what the maximum values can be: 100 * 100 * 100 / 100 is still 10,000, when you wanted it to be 100 at max. To set up the algebra problem:

100 * 100 * 100 / x = 100
2 Likes

motor_1.spin(vex.DirectionType.FWD, ((con.axis1.position(vex.PercentUnits.PCT)/100)**3)100, vex.VelocityUnits.PCT)?

1 Like

Needs a * between the ...**3) and the 100,... and it should work

1 Like

motor_1.spin(vex.DirectionType.FWD, ((con.axis1.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT) ?

1 Like

Like that, yep. That should give you a range of -100 to 100 like spin wants for its velocity domain.

2 Likes

Thankyou :innocent::innocent::innocent::innocent::innocent:

1 Like

I’ve tried that and it does not seem to work. What is the problem? Thank you in advance.

        Right_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Left_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Right_Back.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Left_Back.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)

image

EDITS:

Full Code
# β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘Robotics β–’β–’β–’β–’β–‘β–‘β–‘β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ Is The  β–’β–’β–’β–’β–’β–‘β–’β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘  Best   β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–‘β–’β–’β–’β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–’β–’β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–’β–’β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–’β–’β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–’β–’β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–’β–‘β–‘β–‘β–‘β–‘β–‘β–“β–“
# β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
# _______β–’__________β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
# ______β–’_______________β–’β–’β–’β–’β–’β–’β–’β–’
# _____β–’________________β–’β–’β–’β–’β–’β–’β–’β–’
# ____β–’___________β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’β–’
# ___β–’
# __β–’______β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
# _β–’______β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“
# β–’β–’β–’β–’___β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“
# β–’β–’β–’β–’__β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“β–’β–“
# β–’β–’β–’__β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
# β–’β–’



# VEX V5 Python Project with Competition Template
import sys
import vex
from vex import *

#region config
brain        = vex.Brain()
Right_Front  = vex.Motor(vex.Ports.PORT1, vex.GearSetting.RATIO18_1, True)
Right_Back   = vex.Motor(vex.Ports.PORT2, vex.GearSetting.RATIO18_1, True)
Left_Front   = vex.Motor(vex.Ports.PORT3, vex.GearSetting.RATIO18_1, False)
Left_Back    = vex.Motor(vex.Ports.PORT4, vex.GearSetting.RATIO18_1, False)
Tilt         = vex.Motor(vex.Ports.PORT7, vex.GearSetting.RATIO18_1, False)
Intake_Left  = vex.Motor(vex.Ports.PORT10, vex.GearSetting.RATIO18_1, True)
Intake_Right = vex.Motor(vex.Ports.PORT20, vex.GearSetting.RATIO18_1, False)
Autton_1     = vex.Limit(brain.three_wire_port.a)
Autton_2     = vex.Limit(brain.three_wire_port.b)
Autton_3     = vex.Limit(brain.three_wire_port.c)
Autton_4     = vex.Limit(brain.three_wire_port.d)
Autton_5     = vex.Limit(brain.three_wire_port.e)
Autton_6     = vex.Limit(brain.three_wire_port.f)
Autton_7     = vex.Limit(brain.three_wire_port.g)
Autton_8     = vex.Limit(brain.three_wire_port.h)
con          = vex.Controller(vex.ControllerType.PRIMARY)
#endregion config

Right = None
Left = None
Drive_Speed = None
Speed = None

def Drive(Right, Left, Drive_Speed):
  Right_Front.set_velocity(Drive_Speed, vex.VelocityUnits.PCT)
  Right_Back.set_velocity(Drive_Speed, vex.VelocityUnits.PCT)
  Left_Front.set_velocity(Drive_Speed, vex.VelocityUnits.PCT)
  Left_Back.set_velocity(Drive_Speed, vex.VelocityUnits.PCT)
  Right_Front.start_rotate_for(vex.DirectionType.FWD, Right, vex.RotationUnits.REV)
  Right_Back.start_rotate_for(vex.DirectionType.FWD, Right, vex.RotationUnits.REV)
  Left_Front.start_rotate_for(vex.DirectionType.FWD, Left, vex.RotationUnits.REV)
  Left_Back.rotate_for(vex.DirectionType.FWD, Left, vex.RotationUnits.REV)

def Turn_Intake(Speed):
  Intake_Left.spin(vex.DirectionType.FWD, Speed, vex.VelocityUnits.PCT)
  Intake_Right.spin(vex.DirectionType.FWD, Speed, vex.VelocityUnits.PCT)
  
  
# Creates a competition object that allows access to Competition methods.
competition = vex.Competition()

def pre_auton():
    # All activities that occur before competition start
    # Example: setting initial positions
    pass


# Autton_5 is Red Procted
# Autton_6 is Red UnProcted
# Autton_7 is Blue Procted
# Autton_8 is Blue UnProcted

def autonomous():
  if Autton_5.pressing():
      Drive(1, 1, 50)
      Drive(-1, -1, 50)
  elif Autton_6.pressing():
      Drive(1, 1, 50)
      Drive(-1, -1, 50)
  elif Autton_7.pressing():
      Drive(1, 1, 50)
      Drive(-1, -1, 50)
  elif Autton_8.pressing():
      Drive(1, 1, 50)
      Drive(-1, -1, 50)
  elif Autton_1.pressing():
      #   Turn_Intake(None)
#   Drive(None, None, None)
#   Turn_Intake(None)
#   Drive(None, None, None)
#   Drive(None, None, None)
#   sys.sleep(1)
#   Drive(None, None, None) 
#   Drive(None, None, None)
#   Drive(None, None, None)
#   Turn_Intake(None)
#   Drive(None, None, None)
#   Drive(None, None, None)
#   Drive(None, None, None)
    brain.screen.print_line(1, 'No Jumper in Programed Port!')
    con.screen.set_cursor(1, 1)
    con.screen.print_('No Jumper in Programed Port!')
  elif Autton_2.pressing():
      brain.screen.print_line(1, 'No Jumper in Programed Port!')
      con.screen.set_cursor(1, 1)
      con.screen.print_('No Jumper in Programed Port!')
  elif Autton_3.pressing():
      brain.screen.print_line(1, 'No Jumper in Programed Port!')
      con.screen.set_cursor(1, 1)
      con.screen.print_('No Jumper in Programed Port!')
  elif Autton_4.pressing():
      brain.screen.print_line(1, 'No Jumper in Programed Port!')
      con.screen.set_cursor(1, 1)
      con.screen.print_('No Jumper in Programed Port!')
  else:
      brain.screen.print_line(1, 'No Jumper In The Robot!')
      con.screen.set_cursor(1, 1)
      con.screen.print_('No Jumper!')
      pass
  pass


def drivercontrol():
    # Place drive control code here, inside the loop
    
    # This code will run onece:
    Intake = 0
    
    
    while True:
        # This code will repete
        # This is the main loop for the driver control.

        
        # Drive the robot using tank drive

        con.set_deadband(10, vex.PercentUnits.PCT)
        # Right_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)*0.65), vex.VelocityUnits.PCT)
        # Right_Back.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)*0.65), vex.VelocityUnits.PCT)
        # Left_Front.spin(vex.DirectionType.FWD, (con.axis3.position(vex.PercentUnits.PCT)*0.65), vex.VelocityUnits.PCT)
        # Left_Back.spin(vex.DirectionType.FWD, (con.axis3.position(vex.PercentUnits.PCT)*0.65), vex.VelocityUnits.PCT)
        Right_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Left_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Right_Back.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        Left_Back.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
        # Move the tilt tray if the buttons get pushed
        if con.buttonA.pressing():
             Tilt.spin(vex.DirectionType.FWD, 30, vex.VelocityUnits.PCT)
        elif con.buttonB.pressing():
             Tilt.spin(vex.DirectionType.REV, 30, vex.VelocityUnits.PCT)
        else:
             Tilt.stop(vex.BrakeType.COAST)
             Tilt.spin(vex.DirectionType.REV, 0, vex.VelocityUnits.PCT)
             Tilt.stop
        #Spin the intake if the burrons are pushed
        if con.buttonL1.pressing():
             Intake_Left.spin(vex.DirectionType.FWD, 100, vex.VelocityUnits.RPM)
             
        elif con.buttonL2.pressing():
             Intake_Left.spin(vex.DirectionType.REV, 100, vex.VelocityUnits.RPM)
             
        else:
             Intake_Left.spin(vex.DirectionType.FWD, 0, vex.VelocityUnits.RPM)
             
             
        if con.buttonR1.pressing():
             
             Intake_Right.spin(vex.DirectionType.FWD, 100, vex.VelocityUnits.RPM)
        elif con.buttonR2.pressing():
             
             Intake_Right.spin(vex.DirectionType.REV, 100, vex.VelocityUnits.RPM)
        else:
             
             Intake_Right.spin(vex.DirectionType.FWD, 0, vex.VelocityUnits.RPM)
        sys.sleep(0.2)
    pass

# Do not adjust the lines below

# Set up (but don't start) callbacks for autonomous and driver control periods.
competition.autonomous(autonomous)
competition.drivercontrol(drivercontrol)

# Run the pre-autonomous function.
pre_auton()

# Robot Mesh Studio runtime continues to run until all threads and
# competition callbacks are finished.
Full debugger output
Compiling failed: Program has errors. See output for details.

Downloading vm/library.
Adding image: main
Traceback (most recent call last):
[File "main", line 160
](chrome-extension://ablgfcdjafdflgnbbbffcdginlaoembf/project.html?id=1#)Right_Front.spin(vex.DirectionType.FWD, (con.axis2.position(vex.PercentUnits.PCT)/100) ** 3)*100, vex.VelocityUnits.PCT)
^
SyntaxError: invalid syntax

Compiling failed: Program has errors. See output for details. Time: 36 ms
1 Like

You have more closing parentheses than opening parentheses on each of those four lines

1 Like
    Right_Front.spin(vex.DirectionType.FWD, ((con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
    Left_Front.spin(vex.DirectionType.FWD, ((con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
    Right_Back.spin(vex.DirectionType.FWD, ((con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)
    Left_Back.spin(vex.DirectionType.FWD, ((con.axis2.position(vex.PercentUnits.PCT)/100)**3)*100, vex.VelocityUnits.PCT)

Thank you so much!! (looks like I can’t copy and past)