ROBOTC.net forums
http://robotc.net/forums/

JOY1btn problem
http://robotc.net/forums/viewtopic.php?f=52&t=7769
Page 1 of 1

Author:  roshaanthebeast [ Tue Jan 21, 2014 11:53 pm ]
Post subject:  JOY1btn problem

Hey This is a part of my programming and I am having some issues
So this part of the program is suppose to just spin the flag right or left on full speed with using buttons but i cant seem to figure out the problem.
How do you make the program so that when I press button 4 it goes left and stops when im not pressing it and when I press button 6 it goes right and when i stop pressing it the flag raiser stops.
Thanks to anyone who tries to help us!!!
Team 6007-RoboTitans

THis the part i am having trouble with
if(joy1Btn(4)) // If Button 5 is pressed:
{
motor[Flag] = -100; // Raise Servo 1 to position 200.
}
else // Else if the readings are within the threshold:
{
motor[Flag] = 0;
}
if(joy1Btn(7)) // If Button 6 is pressed:
{
motor[Flag] = 100; // Lower Servo 1 to position 20.
}
else // Else if the readings are within the threshold:
{
motor[Flag] = 0;
}








And this is my full code
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, HTMotor)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, IRSeeker, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3, light, sensorLightActive)
#pragma config(Sensor, S4, sonar, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNXT, openLoop)
#pragma config(Motor, mtr_S1_C1_1, rightMotor, tmotorTetrix, openLoop, reversed, encoder)
#pragma config(Motor, mtr_S1_C1_2, leftMotor, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_1, Arm, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, Flag, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, Hanger, tmotorTetrix, openLoop)
#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)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++
Gripperbot - Remote Control
- NOTE: Gripperbot can be used to pick up game objects from the floor and to raise the flag.
- This program allows you to remotely control your robot using the USB Logitech Joysticks.
- This program also ignores low values that would cause your robot to move when the joysticks fail to
return back to exact center. You may need to adjust the 'threshold' value to get it just right.

Robot Model(s): TETRIX Gripperbot (IR) (Virtual Worlds)

[I/O Port] [Name] [Type] [Description]
Motor Port A gripperMotor NXT Motor Gripper motor
Motor Port D rightMotor TETRIX Motor Right side motor
Motor Port E leftMotor TETRIX Motor Left side motor
Motor Port F armMotor TETRIX Motor Arm motor
Motor Port G spinnerMotor TETRIX Motor Spinner motor

Sensor Port 2 IRSeeker IRSeeker 1200 HiTechnic IRSeeker 1200
Sensor Port 3 light Light Sensor NXT Light Sensor (Active)
Sensor Port 4 sonar Sonar Sensor NXT Sonar Sensor
----------------------------------------------------------------------------------------------------*/

#include "JoystickDriver.c"

task main()
{

int threshold = 10;

//Loop Forever
while(1 == 1)
{
//Get the Latest joystick values
getJoystickSettings(joystick);

//Driving Control
if(abs(joystick.joy1_y1) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold...
{
motor[rightMotor] = joystick.joy1_y1; // ...move the right side of the robot.
}
else // Else the readings are within the threshold, so...
{
motor[rightMotor] = 0; // ...stop the right side of the robot.
}
if(abs(joystick.joy1_y2) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold...
{
motor[leftMotor] = joystick.joy1_y2; // ...move the left side of the robot.
}
else // Else the readings are within the threshold, so...
{
motor[leftMotor] = 0; // ...stop the left side of the robot.
}
if(joy1Btn(4)) // If Button 5 is pressed:
{
motor[Flag] = -100; // Raise Servo 1 to position 200.
}
else // Else if the readings are within the threshold:
{
motor[Flag] = 0;
}
if(joy1Btn(7)) // If Button 6 is pressed:
{
motor[Flag] = 100; // Lower Servo 1 to position 20.
}
else // Else if the readings are within the threshold:
{
motor[Flag] = 0;
}
if(abs(joystick.joy2_y1) > 10) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[Arm] = joystick.joy2_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[Arm] = 0; // Motor E is stopped with a power level of 0.
}
if(abs(joystick.joy2_y2) > 10) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[Hanger] = joystick.joy2_y2; // 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[Hanger] = 0; // Motor E is stopped with a power level of 0.
}
}
}

Author:  MHTS [ Wed Jan 22, 2014 12:18 am ]
Post subject:  Re: JOY1btn problem

A slight optimization of your code.
Code:
while (true)
{
    GetJoystickSettings(joystick);
    if (joy1Btn(4)) // If Button 5 is pressed:
    {
        motor[Flag] = -100; // Raise Servo 1 to position 200.
    }
    else if (joy1Btn(7))
    {
        motor[Flag] = 100; // Lower Servo 1 to position 20.
    }
    else
    {
        motor[Flag] = 0;
    }

    wait1Msec(50);
}

Author:  roshaanthebeast [ Wed Jan 22, 2014 12:35 am ]
Post subject:  Re: JOY1btn problem

yup that worked thanks a lot I appreciate.
There is another problem though
In my code the Arm and the Hanger is not working so can you please go over my code to see if every thing is fine THanks
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, HTMotor)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, IRSeeker, sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S3, light, sensorLightActive)
#pragma config(Sensor, S4, sonar, sensorSONAR)
#pragma config(Motor, motorA, gripperMotor, tmotorNXT, openLoop)
#pragma config(Motor, mtr_S1_C1_1, rightMotor, tmotorTetrix, openLoop, reversed, encoder)
#pragma config(Motor, mtr_S1_C1_2, leftMotor, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S1_C3_1, Arm, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_2, motorG, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_1, Flag, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C4_2, Hanger, tmotorTetrix, openLoop)
#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)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++++
Gripperbot - Remote Control
- NOTE: Gripperbot can be used to pick up game objects from the floor and to raise the flag.
- This program allows you to remotely control your robot using the USB Logitech Joysticks.
- This program also ignores low values that would cause your robot to move when the joysticks fail to
return back to exact center. You may need to adjust the 'threshold' value to get it just right.

Robot Model(s): TETRIX Gripperbot (IR) (Virtual Worlds)

[I/O Port] [Name] [Type] [Description]
Motor Port A gripperMotor NXT Motor Gripper motor
Motor Port D rightMotor TETRIX Motor Right side motor
Motor Port E leftMotor TETRIX Motor Left side motor
Motor Port F armMotor TETRIX Motor Arm motor
Motor Port G spinnerMotor TETRIX Motor Spinner motor

Sensor Port 2 IRSeeker IRSeeker 1200 HiTechnic IRSeeker 1200
Sensor Port 3 light Light Sensor NXT Light Sensor (Active)
Sensor Port 4 sonar Sonar Sensor NXT Sonar Sensor
----------------------------------------------------------------------------------------------------*/

#include "JoystickDriver.c"

task main()
{

int threshold = 10;

//Loop Forever
while(1 == 1)
{
//Get the Latest joystick values
getJoystickSettings(joystick);

//Driving Control
if(abs(joystick.joy1_y1) > threshold) // If the right analog stick's Y-axis readings are either above or below the threshold...
{
motor[rightMotor] = joystick.joy1_y1; // ...move the right side of the robot.
}
else // Else the readings are within the threshold, so...
{
motor[rightMotor] = 0; // ...stop the right side of the robot.
}
if(abs(joystick.joy1_y2) > threshold) // If the left analog stick's Y-axis readings are either above or below the threshold...
{
motor[leftMotor] = joystick.joy1_y2; // ...move the left side of the robot.
}
else // Else the readings are within the threshold, so...
{
motor[leftMotor] = 0; // ...stop the left side of the robot.
}
if (joy1Btn(7)) // If Button 5 is pressed:
{
motor[Flag] = 100; // Raise Servo 1 to position 200.
}
else // Else if the readings are within the threshold:
{
motor[Flag] = 0; // Motor E is stopped with a power level of 0.
}

wait1Msec(50);
}
if(abs(joystick.joy2_y1) > 10) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[Arm] = joystick.joy2_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[Arm] = 0; // Motor E is stopped with a power level of 0.
}
if(abs(joystick.joy2_y2) > 10) // If the left analog stick's Y-axis readings are either above or below the threshold:
{
motor[Hanger] = joystick.joy2_y2; // 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[Hanger] = 0; // Motor E is stopped with a power level of 0.
}
}
}

}

Author:  JohnWatson [ Wed Jan 22, 2014 1:19 am ]
Post subject:  Re: JOY1btn problem

Code:
wait1Msec(50);
}


You have a rogue closing brace } after the wait1MSec command; this 'closes' the infinite while loop and effectively excludes all of the other code (namely the arm and hanger motor control code) from running.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/