View unanswered posts | View active topics It is currently Sun Dec 21, 2014 11:28 pm






Reply to topic  [ 2 posts ] 
Set the Power Level??? 
Author Message
Rookie

Joined: Sat May 24, 2014 8:44 pm
Posts: 8
Post Set the Power Level???
Can someone look at my code at tell me how to set the power level on motors D and E?


#pragma config(Hubs, S1, HTMotor, HTServo, none, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop, reversed)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoStandard)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c"

task main()
{
int threshold = 20; /* Int 'threshold' will allow us to ignore low */

while(true) // Infinite loop:

{
getJoystickSettings(joystick);

if(abs(joystick.joy1_y2) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorD] = joystick.joy1_y2; // Motor D is assigned a power level equal to the right analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[motorD] = 0; // Motor D is stopped with a power level of 0.
}

if(abs(joystick.joy1_y1) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorE] = joystick.joy1_y1; // Motor E is assigned a power level equal to the left analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[motorE] = 0; // Motor E is stopped with a power level of 0.
}

// BUTTONS TO CONTROL SERVO ARM
// Control arm via shoulder buttons, 1 and 4... 1=up, 4=down

int a = ServoValue[servo1];

if(joy1Btn(1) && a <= 245) // If Button 1 is pressed:
{
a = a + 5;
servo[servo1] = a; // Raise Servo 5 to position to 245.
}

if(joy1Btn(4) && a >=10) // If Button 4 is pressed:
{
a = a - 5; // Lower Servo 5 positions.
}
servo[servo1] = a;

wait1Msec (50);


//Buttons to control gripper
//This is the code that will not work

int b = ServoValue[servo2];

if(joy1Btn(3) && b <= 245) // If Button 2 is pressed:
{
b = b + 245;
servo[servo2] = b; // Open Servo 5 to position to 245.
}

if(joy1Btn(2) && b >=10) // If Button 3 is pressed:
{
b = b - 25; // Lower Servo 5 positions.
}
servo[servo2] = b;

wait1Msec (50);
}
}


Wed May 28, 2014 11:15 am
Profile
Rookie
User avatar

Joined: Wed Jan 09, 2013 11:48 pm
Posts: 42
Location: Saint Paul, MN
Post Re: Set the Power Level???
Your code should work with your current setup for motorE and motorD with the joysticks:
Code:
if(abs(joystick.joy1_y2) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorD] = joystick.joy1_y2; // Motor D is assigned a power level equal to the right analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[motorD] = 0; // Motor D is stopped with a power level of 0.
}

if(abs(joystick.joy1_y1) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[motorE] = joystick.joy1_y1; // Motor E is assigned a power level equal to the left analog stick's Y-axis reading.
}
else // Else if the readings are within the threshold:
{
motor[motorE] = 0; // Motor E is stopped with a power level of 0.
}


But if it isn't working you could try this:
Code:
motor[motorD] = abs(joystick.joy1_y2) > threshold ? joystick.joy1_y2 : 0;
motor[motorE] = abs(joystick.joy1_y1) > threshold ? joystick.joy1_y1 : 0;

_________________
Head Programmer FTC Team 6699, Tempest

Code:
<Life>
   Fun
</Life>


Thu May 29, 2014 2:16 pm
Profile WWW
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.