[FTC]: Robot C

Ok so last year i programmed in NXT-G and it was ok i got our team to win SC, but this year we want to do more complicated stuff we want to use Robot C, i know the basics but the Tele Op functions still esacpe me any help??

Try this link: http://www.robotc.net/teachingmindstorms/index.html

You’ll find the the reserved words page is especially helpful.

Have Fun.

I assume your question is in regards to using JoystickDriver.c for FTC?
Some more FTC specific ROBOTC links are:

http://www.education.rec.ri.cmu.edu/content/events/ftc/robotc/index.htm

http://www.education.rec.ri.cmu.edu/products/getting_started_tetrix/

I’ve had a couple of students attempt to use the RobotC testbed. Everything works great with just the motor. However, when we try to use the servo (Testbed 2) neither the motor or servo work. Any Suggestions?

I might be able to answer both of your questions:rolleyes:

for a basic 2 motor 2 joystick teleOp drive:

joystick.joy1_y1 = motor[motorD]

joystick.joy1_y2 = motor[motorE]

assuming that you have the motors configured with defult names.

For button control you will use if statements:

if(joystick.joy1_buttons == :ahh: )

{
motor[motorD] = 100;
motor[motorE] = 100;
}

I am still a little rusty from last year these might not work…:smiley:

From what we’ve been doing the condition for your if statements should look like this

if(joy1Btn(1) == 1)
{
code here
}

this will make it so execute code when button 1 on joystick 1 is pressed.

so basically if a created a little automous program to run when i press a button would it work?

First you guys want:

motor[motorE] = joystick.joy1_y2;

With C programming you set the thing on the left to the value on the right. The other way around shouldn’t work. *Unless Robot C built it into the compiler to accept it both ways.

Also as a note to save you guys a lot of frustration later. I would suggets you put in a “dead zone” that stops you from powering the motors with too little voltage.

if ( ( joystick.joy1_y2 < -10) || ( joystick.joy1_y2 > 10))
{
motor[motorE] = joystick.joy1_y2;
}
else
{
motor[motorE] = 0;
}

your motors will thank you.

Second I’ve found throughout my tetsing that it is much better to program the buttons as such:

if(joy1Btn(1) )
{
code for what you want to happen here
}
else
{
code to make that stop happening
}

While there is not techinical difference in this case…for whatever reason the software gods seem to prefer it without the “==1”

finally, while techinically yes…you could put autonomous code into the “code here” section but you could also run into some serious problems…unless you keep all of your logic sound. You can easliy start getting in trouble when you try things like this.

That is beastly awsome, i’m going to test this with our robot when i get our 2nd motor controller.

LAWL I installed Windows 7 on our robotics laptop and all the software still works because it was compatible with Vista.

That is generally good advice, but I’m going to go ahead and share some extra insight. Remember that the joystick analog sticks have a range of -127 to 128, but your DC motors only have a range of -100 to 100. While you can directly pass the analog stick value to the motor & ROBOTC will not error, you are losing about 20% of the actual range of the analog stick which will not give you the good fine-grained control your robot is capable of.

The basic solution is to apply a linear scale such as: motor_output = joystick_input / max_joystick_value * max_motor_value.

However, we can do even better if we use a parabolic curve so that we have fine control at low speeds for a larger portion of the analog stick’s range and then ramp up the scaling for the extremities of the analog stick’s range. Below is a function which will do just that (as well as apply a deadzone):

//scaling function
int scaleForMotor(int joyVal) {

  //constants
  const int DEADZONE = 5;
  const int MAX_MOTOR_VAL = 100;
  const float MAX_JOY_VAL = 127.0;

  //check for deadzone
  if(abs(joyVal) < DEADZONE) {
    return 0;
  }

  //calculate scaled value
  int sign = joyVal / abs(joyVal); // 1 or -1
  float ratio = ((joyVal * joyVal) / (MAX_JOY_VAL * MAX_JOY_VAL));
  int scaledVal = (sign * MAX_MOTOR_VAL) * ratio;

  return scaledVal;
}

I have no issues sharing this to help other teams get going, but please attempt to understand what it is doing if you choose to copy it into your code. Feel free to adjust the constants to set your own deadzone or max motor output.
Just place the function in your code above the main task and call it like below:

//scales input from joystick 1 left analog stick's y-axis
motor[someMotor] = scaleForMotor(joystick.joy1_y1);  
//scales input from joystick 1 right analog stick's y-axis
motor[someOtherMotor] = scaleForMotor(joystick.joy1_y2);  

Best of luck,
l0jec

That also looks very good, i understand what you were saying with the Parabolic Curve. :smiley: THANK YOU!!!

Our Team is new to FTC and RobotC. We are trying to build programs that will allow us to use the joysticks with our robot. Would anyone be willing to share a complete program (rather than program segments that don’t explain where the code goes) that would allow joystick 1 to control motorD and Joystick 2 to control motorE?

You can email me off line at [email protected]

Thanks

here you go :smiley:
Make sure your RobotC is set to NXT and TETRIX mode and also go to motor and sensors setup and configure you motors to how you have them set up.

#include “joystickdriver.c”

task main ()
{
{
getJoystickSettings(joystick);
motor[motorD] = joystick.joy1_y1;
motor[motorE] = joystick.joy1_y2;
}
}

Don’t forget to loop! :slight_smile:

i dont know why but i was told and ive seen it done only this way in robotc but it think its supposed to be

if(joy1Btn(1) !=0)
{
action
}

don’t know why i just do it like that…

Yeah the programming Gods like you to do that it’s really just unessesary code, and yeah it’s been a long day i know i forgot the loop XD.

if(joy1Btn(1) )
{
code for what you want to happen here
}
else
{
code to make that stop happening
}

this is still as efficiant i tried it today.

What you’re doing is perfectly valid, but may not be the “cleanest” way.

You need to understand that a boolean true/false in ROBOTC is the same as 1 or 0 where
‘true’ is the same as ‘1’ and ‘false’ is the same as ‘0’. Therefore the follow statements are all logically equivalent:

if(value == true)
if(value == 1)
if(value != false)
if(value != 0)

Since the if statement is conditional on the truth of the argument, you can format the test for truth a number of ways. Understand that the “value == true” argument is going to be evaluated as either true (‘value’ is true(1)) or false (‘value’ is false(0)) and that is what the if() statement actually looks at.
So as long as the value variable in our example here is already a boolean, there is no need to explicitly check it for truth. That is there is no need to explicitly test if true is equal to true of if false is equal to false… just pass the boolean itself to the if() statement like:

if(value)

Where does this tie into checking if a button is pressed using the joy1Btn() function?
Well because those functions return a boolean. That means when you call the function you get back either a true or a false and there is no need to see if that is not equal to 0. Just test against the returned boolean like:

if(joy1Btn(1))
{
  //do stuff
}

Now changing if(joy1Btn(1) != 0) to if(joy1Btn(1)) will not make your code behave any differently, but it will make it much more readable. As someone much wiser once said, any fool can write code that a computer can understand, but a good programmer writes code that a human can understand.

Hope this clears us some of the fog. :wink:

ahh i see… yeah that makes sense… i guess my brain is just wired in some screwed up way haha

Tis exactly right :smiley: