View unanswered posts | View active topics It is currently Thu Apr 17, 2014 8:34 am






Reply to topic  [ 2 posts ] 
my robot go when i press start. 
Author Message
Rookie

Joined: Mon Dec 10, 2012 3:20 pm
Posts: 1
Post my robot go when i press start.
#pragma config(Hubs, S1, HTServo, HTMotor, HTMotor, HTMotor)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Motor, mtr_S1_C2_1, left, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_2, front, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, liftleft, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, liftright, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, right, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, back, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C1_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C1_2, hand, tServoStandard)
#pragma config(Servo, srvo_S1_C1_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C1_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C1_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C1_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
{
#include "JoystickDriver.c" //allows computer and robot to communicate, also allows the Brick to talk to Joysticks

int joy1y1; //left motor
int joy1y2; //right motor
int joy1x2; //crab motors
int joy2y1; //lift
int position; //position of hands

int scaleForMotor(int joyvalue){ //ratios joystick value to motor values, exponentially squared

if(joyvalue == 0){
joyvalue=1;
}

float scaledval = ((joyvalue / 127)^2)*100*(joyvalue/abs(joyvalue));

if(abs(scaledval) < 1){
scaledval=0;
}
return scaledval;
}


task main(){

waitForStart();

motor[left]=0; //stop moving, set hands
motor[front]=0;
motor[liftleft]=0;
motor[liftright]=0;
motor[right]=0;
motor[back]=0;
servo[hand]=192;

while(true){

getJoystickSettings(joystick); //reads the current state of the joysticks.

joy1y1=scaleForMotor(joystick.joy1_y1); //interger that translates joysticks to motor values,exponential.
joy1y2=scaleForMotor(joystick.joy1_y2);
joy1x2=scaleForMotor(joystick.joy1_x2);

motor[left]=joy1y1;
motor[right]=joy1y2;

if(joy1y1 > 0 && joy1y2 < 0){ //if rotating clockwise skidsteer, then front and back motors assist the turn
motor[front] = (abs(joy1y1)+ abs(joy1y2))/2;
motor[back]= -1*(abs(joy1y1)+ abs(joy1y2))/2;
}
else{ //otherwise front and back moters crab off of right joystick,x
motor[front]=joy1x2;
motor[back]=joy1x2;
}

if(joy1y1 < 0 && joy1y2 > 0){ //if rotating counter clockwise skidsteer, then front and back motors assist the turn
motor[front] = -1*(abs(joy1y1)+ abs(joy1y2))/2;
motor[back]= (abs(joy1y1)+ abs(joy1y2))/2;
}
else{ //otherwise front and back moters crab off of right joystick,x
motor[front]=joy1x2;
motor[back]=joy1x2;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////// Gunner Controls ///////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


joy2y1=scaleForMotor(joystick.joy2_y1); //interger that translates joysticks to motor values,exponential.
{
motor[liftleft]=joy2y1; //the left gunner joystick controls the lifts up and down, exponential
motor[liftright]=joy2y1;
}
if(joy1Btn(01))
{ // if the blue button is pushed, close the hands
position=120;
}

if(joy1Btn(03))
{ // if the red button is pushed, open the hands
position=192;
}

servo[hand]=position; //set hands every time it loops

}

}


Mon Dec 10, 2012 3:46 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 533
Post Re: my robot go when i press start.
I'm assuming by the title that you would like to have your robot wait until you press a button or switch before it starts the program? If so, you will need what is called an 'idle loop'. These loops are loops that wait until a condition is true but runs no code in the meantime:

Code:
while(SensorValue(bumper1) == 0) //Idle loop, while 'bumper1' is not pressed...
{
//Do nothing at all
}


Usually, these are seen early on in a program to ensure the robot is not doing anything before the 'start' conditions are met.

If this is not what you need, please let us know what specifically you wish to do and we will be more than happy to help you meet that goal.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Mon Dec 10, 2012 5:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.