RobotC

It doesn’t seem like anyone uses robotc but i have a problem with servos. It seems that there is no way to program their position. Does anyone kno how?

Which release of RobotC?? The older ones were free, the current one is not.

The Servo is just like a Motor, but it does not rotate 360 Degrees, just 120 Degrees.

All you do is send a pulse usually in the range to 0.6mS to 1.5mS

google ‘servo motors’

they have a built in potentiometer which measures their position

i already knew about what a servo is but i need to c an example on how to program a servo.
I use RobotC for IFI 1.13.All i want to do is control a servo. Has anyone ever programed a servo with this compiler?

They are programmed the same way as a motor. So if you had motors speeds of 1(Backwards)-127(Center)-255(Forwards) you can set it to say 50 and you would get a set degree of backwards rotation.

I believe this is right, give it a try.

There appears to be a pretty good reference here.

Seems like all you need to do is add code like:


motor[port]=angle;

where “port” is the port number from 1 to 8, and “angle” is the desired rotation angle from -127 to 127 (0 means centered).

Cheers,

  • Dean

Thank you quazar but i am still having problems getting the servo to move. It is as if the servo doesn’t respond at all. All that i was doing was programming the the back ch.6 buttons to move a simple arm to go up or down. This is how it was with the motor instead of the servo that worked:


	 if(vexRT[Ch6] == 127)
   {
     if(SensorValue[up] == 0)
     {
       motor[port7] = 40;
   }
   else
   {
    motor[port7] = 0;
   }
 }
 if(vexRT[Ch6] == -127)
 {
   if(SensorValue[down] == 0)
   {
     motor[port7] = -40;
   }
  else
  {
    motor[port7] = 0;
  }
}
 if(vexRT[Ch6] == 0)
 {
    motor[port7] = 0;
 }
}

This is what i tried to do with the servo:


if(vexRT[Ch6] == 127)
   {
     if(SensorValue[up] == 0)
     {
       motor[port7] = 30;
   }
   else
   {
    motor[port7] = 0;
   }
 }
 if(vexRT[Ch6] == -127)
 {
   if(SensorValue[down] == 0)
   {
     motor[port7] = -30;
   }
  else
  {
    motor[port7] = 0;
  }
 if(vexRT[Ch6] == 0)
 {
    motor[port7] = 0;
 }
}

According to quazar, the arm should move at a 30 degree angle down and 30 degree angle back up and if no input then I want it to not move. Ofcourse this doesn’t work because it was way too easy. Does someone know what I am doing wrong?

Just to be clear, I haven’t used RobotC - my advice was based on looking at the guide I provided a link to. Also, the number provided to the routine isn’t degrees; it is just a scalar value. In practice, each increment corresponds to about 1/2 of a degree of movement, but that is just approximate and may vary slightly between servos.

As for what is going wrong, it’s hard to say. If you have the program successfully driving a motor, then you should be able to plug a servo into that same port and get at least some motion. It really should be that easy - it is with EasyC and MPLAB. Are you certain that your servo works?

  • Dean

yes i am sure my servo works, but where in that article does it talk about a servo. All of it is just basic commands that i already knew. By googling i found this article: ROBOTC

but i am still confused on what they are saying so it didn’t help me. What is a PID and do not tell me that it is Pelvic inflammatory disease:) !!!

That thread has some confused information on it, though it looks like jkjellman has it right. Vex Motors and Vex Servos use the same signal. If one works, the other should. The PWM value sets position on a servo, and speed on a motor. For MPLAB and EasyC, the range is (0…255), whereas it looks like RobotC uses (-127…127).

For motors, the lowest value causes it to run full-speed CCW, the mid value causes it to stop, and the highest value causes it to run full-speed CW. Values in between set intermediate speeds.

For servos, the lower value causes it to move as far CCW as it can, the mid value causes to to return to center, and the highest value causes it to move as far CW as it can. Values in between set intermediate positions.

This is just the way the vex motors and servos work, and it really doesn’t matter what language you use. If a Vex motor runs fine, but a Vex servo does not when plugged into the same port, running the same software, then I’m not sure what to tell you.

Wikipedia provides a good primer for [PID controllers. You don’t need PID software to drive a Vex servo, since the position sensor and PID control logic are already built into them.

Cheers,

thank you quazar. I still do not know how to control a servo though using robotc. It seems to me that i should buy easyc instead. If u find a way to control a servo using robotc then please inform me of this. For now i think i will stock up on motors and use them even though i don’t get the full functions as a servo.