How do I Make User Fuctions?

I’ve noticed numerous people have used fuctions like “Turn Left” and “Go Straight” And I was wondering how do I do that. Also Has Anyone had success with making a precise 90 degree(+,- 3degrees) turn.

-Dustin

Using EasyC 2.x ?? Set the “Programming Setup Window” to “Professional Mode”, select the Tab labeled “Function Blocks” the bottom option is User Functions, click the “+” to see your choices.

This is Not available in EasyC 1.x

is there a way to upgrade form 1.x->2.x?

Go to the Intellitek web site and pay them $50 for a single license upgrade.

Nope No Success With 90 degrees. the best way i can think of is to calculate the circumference of the wheel. and assume for no slipping.

Use the optical encoders and then see how many rotations it takes to turn 90 degrees, you can see the output of the sensor if you leave it hooked up to the comp and code it correctly.

Could i diable the old lisense on easyC1 and use it?

Beats me what you are asking - But, in general, I don’t see how disabling the license on anything will enable you to use “it”; whatever “it” is.

We need more information to be able to answer your question.

Avoid using pronouns. :slight_smile:

Blake

You could also use an Optical Shaft Encoder and figure out how many “turns” the sensor makes in a full turn (180*). Then divide that by 2, to get the 90* turn. The code (I think. I do not have a Optical shaft encoder… :frowning: ) would look something like this.


int turn_degree; 

      StartEncoder ( 1 ) ; // The 1 is the sensor port on the vex micro controller
      turn_degree = GetEncoder ( 1 ) ; //Makes the Encoder value return to the variable "turn_degree"
      while ( 1 )
      {
            SetPWM ( 1 , 255 ) ;
            if ( turn_degree == [90*] ) //Replace [90*] with the actual value
            {
                  SetPWM ( 1 , 127 ) ; //Stop the motor
            }
            else
            {
                  SetPWM ( 1 , 255 ) ; //Run the motor
            }
      }

Or more simple.


      int turn_degree; 

      StartEncoder ( 1 ) ; // The 1 is the sensor port on the vex micro controller
      turn_degree = GetEncoder ( 1 ) ; //Makes the Encoder value return to the variable "turn_degree"
      PresetEncoder ( 1 , [90*] ) ; //Makes the encoder in #1 = 90* value
      while ( 1 )
      {
            SetPWM ( 1 , turn_degree ) ; //Set the motor port #1 to turn_degree which is now =  [90*]
      }

But in order to get the actual value of whatever 90* is, you need to do some testing using the terminal window in EasyC or MPLAB (i think…) and telling it to print the value of the shaft encoder to the terminal window. Here is a little bit more code for that.


int turn_degree; 

      StartEncoder ( 1 ) ; // The 1 is the sensor port on the vex micro controller
      turn_degree = GetEncoder ( 1 ) ;
      PrintToScreen ( "Turn = %d\n" , (int)turn_degree ) ;

Then manually drive your robot (while still connected to the computer)(BE CAREFUL), and turn it until you feel it is close to 90* so it will probably end up +/-5*

Sorry I got WAY off-topic there, but I was bored figured that would help a few people. Good-luck!

Or, if you’re feeling adventurous: invest in a magnetic compass sensor, and adapt it to Vex.

Or… a gyro sensor.

Another side note:
Any sensor (just about, at least…) can be used with the VEX microcontroller. You just have to program it yourself using MPLAB or WPILIB or some other IDE. EasyC can only do so much as far as using the Drag-N-Drop interface (as opposed to the text editor, in EasyC)

An interesting device for direction and movement might be a Standard PC Mouse…

Accually, even EasyC 1.x has under the “Program-Flow” section, “User Code”, in which you can type whatever you want into your program. EasyC won’t be able to help you with the errors, but you have full access to most ALL of the MCC compilers features.

Just gotta know what you’re doing… LOL

For the most part, I do… :wink:

(To show how old I am, I started with the ‘C’ programming language in 1988, and have been working with dedicated Embedded ‘C’ compilers since 2001)

Then manually drive your robot (while still connected to the computer)(BE CAREFUL), and turn it until you feel it is close to 90* so it will probably end up +/-5*

How can you drive it while hooked to the computer? I have looked for a way but I couldn’t figure it out.

you just turn the controller on and with the robot made to print the value of a shaft encoder to the terminal window and program it to move one side of the robot by one of the controllers joysticks, and then move the robot to whatever angle you want.

Ok here is my situation. I have the # value for my shaft encoders, what is the code for making the motor repeat that? I know its a little off topic but I need help.:frowning:

In a loop with the motor running, your program constantly checks the encoder’s count. When the count reaches (or is near) the desired value you turn off the motor (or do whatever else comes next).

Out-of-the-box EasyC does not have a one-line command/function that tells a motor to run until a certain shaft encoder output value is reached. However, you could write a function that does that…

Blake