Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   FIRST Tech Challenge (http://www.chiefdelphi.com/forums/forumdisplay.php?f=146)
-   -   [FTC]: Robot C (http://www.chiefdelphi.com/forums/showthread.php?t=78636)

JohnFogarty 13-10-2009 11:46

[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??

ttldomination 13-10-2009 19:03

Re: [FTC]: Robot C
 
Try this link: http://www.robotc.net/teachingmindstorms/index.html

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

Have Fun.

l0jec 13-10-2009 21:21

Re: [FTC]: Robot C
 
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/...botc/index.htm

http://www.education.rec.ri.cmu.edu/...tarted_tetrix/

blhenze 02-11-2009 13:51

Re: [FTC]: Robot C
 
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?

vexman2222 02-11-2009 16:14

Re: [FTC]: Robot C
 
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....:D

jamie_1930 02-11-2009 21:12

Re: [FTC]: Robot C
 
Quote:

Originally Posted by vexman2222 (Post 880876)
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....:D

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.

JohnFogarty 04-11-2009 11:18

Re: [FTC]: Robot C
 
Quote:

Originally Posted by jamie_1930 (Post 880918)
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?

grampashades 06-11-2009 12:52

Re: [FTC]: Robot C
 
Quote:

Originally Posted by jamie_1930 (Post 880918)
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.

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.

JohnFogarty 09-11-2009 10:25

Re: [FTC]: Robot C
 
Quote:

Originally Posted by grampashades (Post 881469)
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.

l0jec 10-11-2009 09:36

Re: [FTC]: Robot C
 
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):

Code:

//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:

Code:

//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

JohnFogarty 10-11-2009 10:39

Re: [FTC]: Robot C
 
Quote:

Originally Posted by l0jec (Post 881931)
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):

Code:

//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:

Code:

//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. :D THANK YOU!!!

BernieH 10-11-2009 10:41

Re: [FTC]: Robot C
 
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 bhenze@sapulpaps.org

Thanks

JohnFogarty 10-11-2009 10:50

Re: [FTC]: Robot C
 
here you go :D
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;
}
}

l0jec 10-11-2009 12:34

Re: [FTC]: Robot C
 
Quote:

Originally Posted by John_1102 (Post 881955)

#include "joystickdriver.c"

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

Don't forget to loop! :)

alphadog0309 10-11-2009 20:21

Re: [FTC]: Robot C
 
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...


All times are GMT -5. The time now is 18:43.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi