View unanswered posts | View active topics It is currently Thu Dec 18, 2014 3:19 am






Reply to topic  [ 4 posts ] 
JOY1btn problem 
Author Message
Rookie

Joined: Mon Nov 25, 2013 5:57 pm
Posts: 4
Post 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.
}
}
}


Tue Jan 21, 2014 11:53 pm
Profile
Online
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1357
Post 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);
}


Wed Jan 22, 2014 12:18 am
Profile
Rookie

Joined: Mon Nov 25, 2013 5:57 pm
Posts: 4
Post 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.
}
}
}

}


Wed Jan 22, 2014 12:35 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post 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.

_________________
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


Wed Jan 22, 2014 1:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: MHTS 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.