sensor question

I have looked at the forms and i cant find what i need.I would like to know how to setup (P loops) and potentiometers for autonomous.

i have 2 potentiometers on my arm ( one one each side). i want to have a set point like middle or top if its possible. I have never used potentiometers on my robot before.

please help:confused::confused:

There are a bunch of threads on this topic, here’s an old one to get you started, search on things like ā€œpotentiometerā€ and ā€œpositionā€.

https://vexforum.com/t/preset-arm-heights-in-easyc-v4/20223/1

Are you an EasyC or ROBOTC programmer?

Edit:

See this also
https://vexforum.com/showthread.php?p=332277#post332277

I am using easyc

thanks for the info and one more thing, can lock your motors? or does the pid control do that.

lets say that i have a shovel with two 393 and 2 Potentiometers (one on each side), they are programed on channel 5.

my question is when u let the button go, the shovel falls because of gravity or weight is there such a thing as lock or a stopper?

To accomplish this ā€œlocking,ā€ you’ll want PID (or some variant thereof).

Unfortunately there is no such code to ā€œbrakeā€ motors, but what you can do is run power to your motors in the opposite direction it is falling in. for instance, I had a scoop on my robot last year, and to keep it from falling i had a potentiometer on my scoop to tell the robot what side it was on. Then running slight power (15% or so) in the opposite direction it was falling in.
Hope this helps!

Mark Team number 2114B

EDIT: I forgot to mention that I program with RobotC not easyC. Just thought I mention this and you would know how to program it.

do you have any sample code or file i can look at? like i said before i have never programed Potentiometers before.:o

SPOTBOTS

Not entirely true, my first reply to your question linked to a thread with code, which if adapted, does exactly what you want to do. EasyC also ships with examples such as ā€œPID Interrupt service routineā€ which, again, can be adapted to your needs. Try writing some code and then post here if it does not work and we can offer more help.

That’s not entirely true. The motors do have a brake mode as described in their specs: ā€œPWM Input: 1-2ms will give full reverse to full forward, 1.5ms is neutral, 200ms for brake mode (like neutral, but motor terminals shunted together). Brake mode may not be supported by your compilerā€

However, neither RobotC nor EasyC support it so basically you can’t. It would be wonderful if they would add support for it (or if PROS would get on it)

For ports 2 through 9, it’s a master processor problem, nothing that EasyC, ROBOTC or PROS can do. For ports 1 & 10 it may be possible, I think there is control of all 4 FETs (for each H bridge) from the user processor.

Interestingly brake mode is a function in the new VEX-IQ smart motors.

So in easy c you want to set up a couple of variables:
-pot value
-what value you want it to be (the controller value) This is the Target
-output
-error
-kp
this should be in a continuous while loop.

assign error= pot - target

assign output = kp*error

if output > 127
assign output = 127
if output < -127
assign output= -127

set the motor to the output ( you may have to invert the value for one or more of the motors.)

Then you have the adjust the kp value. you want the arm to go slightly past the set point than come back with a minimum of oscilation. I would start with a kp of 10. A smaller kp will give you more of a slowdown near the setpoint. A larger kp will give you more oscillation and may overshoot the set point or target.

so am i doing this right

what i did is just move my stuff in autonomous temperately so i can have a fresh start

please correct me if i am wrong in operator control
6975x.zip (55 KB)

Ok, for the benefit of others, here is what you had in Operator control.

#include "Main.h"

void OperatorControl ( unsigned long ulTime )
{
      int ch7 = 0; 
      int ch9 = 0; 
      int pot3 = 0; 
      int pot4 = 0; 

      if ( ch7 == 0 )
        {
        SetMotor ( 7 , 0 ) ;
        }
      else if ( ch7 == 1 )
        {
        SetMotor ( 1 , -127 ) ;
        }
      else if ( ch7 == -1 )
        {
        SetMotor ( 1 , 127 ) ;
        }
}

and part of the controller configuration.

easyC V4 for Cortex                                                                                1
      
     Controller configuration for project: 6975x
     Date: 04/30/2013    Time: 18:10
      
     -----------------------------------------------------------------------
     ANALOG INPUTS:
     Input #1    pot1 arm right
     Input #2    pot2 arm left
     Input #3    pot3 frontloader right
     Input #4    pot4 frontloader left
     Input #5    
     Input #6    
     Input #7    
     Input #8    
     -----------------------------------------------------------------------
     MOTORS:
     Motor #1  Type: Big IME HS    Description: whee left back
     Motor #2  Type: Big IME HS    Description: wheel right back
     Motor #3  Type: Big IME HS    Description: wheel left front
     Motor #4  Type: Big IME HS    Description: wheel right front
     Motor #5  Type: Big IME HS    Description: Arm Right Right
     Motor #6  Type: Big IME HS    Description: Arm Right Left
     Motor #7  Type: Big IME HS    Description: front loader left
     Motor #8  Type: Big IME HS    Description: Arm Left Left
     Motor #9  Type: Big IME HS    Description: Front Loader Right
     Motor #10  Type: Big IME HS    Description: Arm Left Right
     -----------------------------------------------------------------------

You are sort of on the right lines but far from the final solution. You will need to use SetMotor and also read the value of your potentiometer into one of your variables. I’m not sure how to talk you through this, for a competition this coming weekend you may just want to run with what you had before and ignore the potentiometer code until later, anyway, this is what you are aiming for, a simple P controller using the right arm pot as the feedback, it assumes increasing motor command for motors 5 and 10 will cause the pot’s value to increase, if this is not the case then you will quickly lose control so having a way of stopping the robot.

#include "Main.h"

void OperatorControl ( unsigned long ulTime )
{
      int pot1 = 0; 
      int pot2 = 0; 
      int pot3 = 0; 
      int pot4 = 0; 
      int motorDrive;
      int positionError; 
      int targetValue; 
      float propConst = 0.3; 

      targetValue = GetAnalogInputHR ( 1 ) ; // Initial position

      while ( 1 ) // Insert Your RC Code Below
        {
        // calculate drive
        pot1 = GetAnalogInputHR ( 1 ) ; // get the potentiometer value
        positionError = targetValue - pot1 ; // calculate the error
        motorDrive = (int)( (float)positionError * propConst) ; // motor drive is error * constant
      
        // Limit the motor value to +/- 127 
        if ( motorDrive > 127 )
            {
            motorDrive = 127 ;
            }
        if ( motorDrive  < -127 )
            {
            motorDrive = -127 ;
            }

        // Now send to the motors 
        SetMotor ( 5 , motorDrive  ) ;
        SetMotor ( 6 , -motorDrive ) ; // set reversed
        SetMotor ( 10 , motorDrive ) ;
        SetMotor ( 8 , -motorDrive ) ; // set reversed


        // User input 
        // you need to determine the limits yourself 
        if ( ( GetJoystickAnalog( 1, 2 )  > 10) || (GetJoystickAnalog( 1, 2 )  < -10) )
            {
            targetValue = targetValue + (GetJoystickAnalog( 1, 2 ) / 2) ;
            if ( targetValue > 2000 )
                {
                targetValue = 2000 ;
                }
            if ( targetValue < 400 )
                {
                targetValue = 400 ;
                }
            }

        Wait ( 25 ) ;
        }
}

It’s pretty much what I linked you to before and what ajo518 outlined below. Start with this and ask specific questions if you don’t understand it. This code is untested and is arm control only.

I’m working with SPOTBOTS on the robot, and we’ve gotten everything written that you had there, but it’s failing to compile with the error:
errors.JPG
6975x.zip (22 KB)

Thank u guys for all of your help and support i got it setup and i am just trying to convert it to digital because you had it setup to my lift :p. anyway thank you so much. i have a basic understanding of how it works, now because of guys.:smiley:

There was a typo on GetJoystickAnalog (you had getJoystickAnalog).

Glad you made progress. Understanding how the code is supposed to work is the most important thing, just typing it in and blindly hoping that it works doesn’t help you much, if you have more questions just post. You may also need to play with the proportional constant, I threw 0.3 in there but it may need adjusting, too big and the arm will oscillate, too small and the arm will not be able to get close to the target.

yeah it was oscillating, and i had my finger was on it and pinched the crap out of me. like i said i was converting it to digital and this is my error.i switched the GetJoystickAnalog with GetJoystickDigital. what would i need to do with that error?

You cannot just replace GetJoystickAnalog with GetJoystickDigital

The analog joystick returns a value in the range -127 to +127, GetJoystickDigital returns a value of 0 (not pressed) or 1 (pressed). If you want to use two buttons to raise or lower the arm then you would need code something like this.

    // User input 
    // you need to determine the limits your self 
    if ( GetJoystickDigital( 1, 5, 2 ) == 1 )
        {
        targetValue = targetValue + 5 ; // adjust value to suit the desired speed
        }
    else if ( GetJoystickDigital( 1, 5, 1 ) == 1 )
        {
        targetValue = targetValue - 5 ; // adjust value to suit the desired speed
        }
    if ( targetValue > 2000 )
        {
        targetValue = 2000 ;
        }
    if ( targetValue < 400 )
        {
        targetValue = 400 ;
        }

This uses button 5 up to increase targetValue and button 5 down to lower targetValue.

Alternatively, you could simply set targetValue to a known position by pressing a button. Something like this.


    if ( GetJoystickDigital( 1, 8, 2 ) )
        {
        targetValue = 1800 ;
        }
    else if ( GetJoystickDigital( 1, 8,1 ) )
        {
        targetValue = 800 ;
        }

As well as tuning the value of propConst, you need to set the range of your potentiometer, again, I just put values in (400 and 2000) that were from another project.

Hey guys i have came a long way and i have only 2 errors out of 91 lines of c code and i can not figure it out.

Either misplaced ā€œ;ā€ or ā€œ)ā€ or ā€œ}ā€

Cur and paste the EasyC code so I can see it.

Instructions here.
https://vexforum.com/showpost.php?p=329490&postcount=15