Announcement

Collapse
No announcement yet.

Remote Programming Moto r Rotation

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote Programming Moto r Rotation

    My team is using RobotC Natural Language to program our remote. We currently have a rack and pinion lift - it is breaking if we go up too high or down too low. We want to set parameters so when we move up and down and stays within those
    boundaries using , We can't figure out the code because the motor needs to go up and down as well as be set to a limit of rotations. We want to use button up and down to assign this command. suggestions would be welcome.





  • #2
    You can use the built-in encoder to do the bounds check. One way is to keep the code as usual with buttons directly setting the motor speed - unless already at the limit. Another would be to use the buttons to update a variable target and use setMotorTarget.

    The first would look like:
    Code:
    repeat(forever) { // your main loop, possibly controlling other mechanisms too
        if ((getJoystickValue(BtnEUp) == 1) && (getMotorEncoder(lift) < 1000)) {
            setMotor(lift,100);
        } else if((getJoystickValue(BtnEDown) == 1) && (getMotorEncoder(lift) > 0)) {
            setMotor(lift, -100);
        } else {
            setMotor(lift, 0);
        }
    }
    Both approaches depend on a well-defined zero - you can reset the encoder, but you need to do that in a known mechanical position. E.g. always start the program with the lift all the way down.
    Don't forget to verify the counting direction of your lift motor.

    Comment


    • #3
      Thanks we are still playing around with this.

      Comment


      • #4
        Below is the code we are using in teleop to raise and lower an arm. It works, however, now the other buttons do not work. We thought the remote would default to the standard button commands? Do I have to reprogram the entire remote or is there something I can do? This is our first time to program the remote and it is proving a challenge.


        #pragma config(Sensor, port2, gyroSensor, sensorVexIQ_Gyro)
        #pragma config(Sensor, port3, colorSensorLeft, sensorVexIQ_ColorGrayscale)
        #pragma config(Motor, motor1, leftMotor, tmotorVexIQ, openLoop, driveLeft, encoder)
        #pragma config(Motor, motor5, middleMotor, tmotorVexIQ, PIDControl, encoder)
        #pragma config(Motor, motor6, rightMotor, tmotorVexIQ, openLoop, reversed, driveRight, encoder)
        #pragma config(Motor, motor11, elelift, tmotorVexIQ, PIDControl, encoder)
        //YOU HAVE TO START THE ROBOT AT WALL LEVEL
        task main()
        {
        while(true)
        {
        if(getJoystickValue(BtnFUp)) //F Button up the basket goes up to post level -
        {
        setMotorTarget(motor11,2000,75); //highest height of basket it will get on the post 2000 is the highest
        }
        else if (getJoystickValue(BtnFDown)) //when you push F Button down the basket goes down to solid color level


        setMotorTarget(motor11,-2000,75); //lowest basket to get on low one color posts
        }

        setMotorSpeed(motor11,0);

        if (getJoystickValue(BtnLUp))

        setMotorSpeed(motor5,10);
        else

        setMotorSpeed(motor5,0);

        if (getJoystickValue(BtnRUp))
        setMotorSpeed(motor5,100);
        }





        Comment

        Working...
        X