View unanswered posts | View active topics It is currently Fri Dec 19, 2014 4:59 pm






Reply to topic  [ 2 posts ] 
Please Examine My Code 
Author Message
Rookie

Joined: Sat May 24, 2014 8:44 pm
Posts: 8
Post Please Examine My Code
I have built the Tetrix Ranger Bot with an arm and a gripper. I can get the robot to move around and the arm to lift up and down, but I cannot get the gripper to open and close.

#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, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#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)

#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

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

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

wait1Msec (50);
}
}

//I would like to control servo2 (gripper) with buttons 2 and three, but I cannot get the gripper to work???


Mon May 26, 2014 5:34 pm
Profile
Rookie

Joined: Sat Jun 07, 2014 12:05 pm
Posts: 3
Post Re: Please Examine My Code
After skimming through, it seems that you forgot to declare a variable 'b' and that you confused some a's and b's.
I think this should work:

//Buttons to control gripper

int b = ServoValue[servo2];

if(joy1Btn(2) && b <= 245) // If Button 2 is pressed:
{
b = b + 5;
servo[servo2] = b; // Open Servo 5 to position to 245. (Your comment here doesn't seem to correlate with the code, do you mean to say it raises by 5 increments?)
}

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

wait1Msec (50);


Mon Jun 09, 2014 9:48 am
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.