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

No erros... Still doesn't work.
http://www.robotc.net/forums/viewtopic.php?f=52&t=5087
Page 1 of 1

Author:  ducttape [ Wed Nov 07, 2012 10:18 pm ]
Post subject:  No erros... Still doesn't work.

This isn't my first year programming with robotc, however this is the first time I used so many variables. I programmed a tank drive that could be used on one joystick, so pretty much an arcade drive. However, just about nothing works in my program. (Bad being as we have our first regional in 2 days time.)There is no errors but when I attempt to run it, the robot just sits and twitches. I'm not sure what I did wrong any input? Thanks you for looking into this!

Quote:
#pragma config(Hubs, S1, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S1, , sensorI2CMuxController)
#pragma config(Sensor, S2, touch, sensorNone)
#pragma config(Sensor, S3, light, sensorNone)
#pragma config(Sensor, S4, IR, sensorHiTechnicIRSeeker600)
#pragma config(Motor, motorA, Claw, tmotorNXT, PIDControl)
#pragma config(Motor, motorB, Arm, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, mtr_S1_C1_1, driveL, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C1_2, driveR, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S1_C3_1, Lift1, tmotorTetrix, openLoop, reversed)
#pragma config(Motor, mtr_S1_C3_2, Lift2, tmotorTetrix, openLoop)
#pragma config(Servo, srvo_S1_C2_1, Susan, tServoStandard)
#pragma config(Servo, srvo_S1_C2_2, Bar, tServoContinuousRotation)
#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" //Joystick's In Program + bluetooth messages.
void joystickstart (int joy1_y2, int joy1_x2)
{
servo[Susan] = 140; // Puts Servo in its neutral
return;
}
task main()
{
bFloatDuringInactiveMotorPWM = false;
waitForStart(); // wait for start of tele-op phase
int b = 10;// Prevents twitching
int w = -10;
int a = ServoValue [Susan];// Assigns a variable to servo-+
int z = ServoValue [Bar];
servoChangeRate[Bar] = 6;
servoChangeRate[Susan] = 5;// Slows servo down to prevent servo from burning out or break.
while(1 == 1) // Repeats forever.
{
getJoystickSettings(joystick); // Gets Joystick settings
if((joy1_y2 > 15) && (joy1_x2 < 40) && (joy1_x2 > -40))//joy1_ 2 Driver joysztick on the right.
{
motor[driveL] = joy1_y2;
motor[driveR] = joy1_y2;
}
else
{
motor[driveR] = 0;
motor[driveL] = 0; // Says if you have joystick backward then the robot moves backward
}

if((joy1_y2 < 50) && (joy1_x2 > -40) && (joy1_x2 < 40))
{
motor[driveR] = -joy1_y2;
motor[driveL] = joy1_y2;
}
else
{
motor[driveR] = 0;
motor[driveL] = 0; // If you have joystick to the right then the robot will go forward otherwise it'll stop.
}
if((joy1_y2 < -50) && (joy1_x2 > -40) && (joy1_x2 < 40))
{
motor[driveR] = joy1_y2;
motor[driveL] = -joy1_y2;
}
else
{
motor[driveR] = 0;
motor[driveL] = 0; // If you have joystick to the right then the robot will go forward otherwise it'll stop.
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Drivers Remote is all done being programmed. Everything from this point is going to be the Attatchment Controller://
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if ((joystick.joy2_y2) > b)
{
servo[Bar] = z + 5;// Means that the power will be related to how far you push aslong as its > 10
}
else
{
servo[Bar] = z;
}
if ((joystick.joy2_y2) > w)
{
servo[Bar] = z - 5;// Means that the power will be related to how far you push aslong as its > 10
}
else
{
servo[Bar] = z;
}

if(abs(joystick.joy2_y1) > b)
{
motor[Arm] = joystick.joy2_y1;
}

if (joy2Btn(04) == 1)
{
servo[Susan] = a + 5; // Adds 5 to the servo value allowing us to move the servo where we want it to.
}

if (joy2Btn(07) == 1)
{
servo[Susan] = a - 5 > 0; // Subtracts 5 from servo value letting us go the opposite way.
}
if (joy1_TopHat == 0)
{
motor[Lift1] = 75;
motor[Lift2] = 75; // Lift goes up at 75 power
}
if (joy1_TopHat == 4)
{
motor[Lift1] = -75;
motor[Lift2] = -75;// Lift goes down at 75
}
}
}

All input is valued even if you are not sure what is wrong. Thanks! :breakcomputer:

Author:  ducttape [ Thu Nov 08, 2012 12:03 am ]
Post subject:  One more thing.

Did I program the D-pad right? was a bit confused when I did that.

Author:  MHTS [ Thu Nov 08, 2012 12:07 am ]
Post subject:  Re: No erros... Still doesn't work.

Code:
   ...
    while(1 == 1) // Repeats forever.
    {
        getJoystickSettings(joystick); // Gets Joystick settings
        if((joy1_y2 > 15) && (joy1_x2 < 40) && (joy1_x2 > -40))//joy1_ 2 Driver joysztick on the right.
        {
            motor[driveL] = joy1_y2;
            motor[driveR] = joy1_y2;
        }
        else
        {
            motor[driveR] = 0;
            motor[driveL] = 0; // Says if you have joystick backward then the robot moves backward
        }

        if((joy1_y2 < 50) && (joy1_x2 > -40) && (joy1_x2 < 40))
        {
            motor[driveR] = -joy1_y2;
            motor[driveL] = joy1_y2;
        }
        else
        {
            motor[driveR] = 0;
            motor[driveL] = 0; // If you have joystick to the right then the robot will go forward otherwise it'll stop.
        }
        if((joy1_y2 < -50) && (joy1_x2 > -40) && (joy1_x2 < 40))
        {
            motor[driveR] = joy1_y2;
            motor[driveL] = -joy1_y2;
        }
        else
        {
            motor[driveR] = 0;
            motor[driveL] = 0; // If you have joystick to the right then the robot will go forward otherwise it'll stop.
        }

I don't understand what the above code was trying to do. If you just want to do arcade drive with the joystick, try something like below:
Code:
while (true)
{
    getJoystickSettings(joystick); // Gets Joystick settings

    int drivePower = joystick.joy1_y2;    //y axis drives forward and backward
    int turnPower = joystick.joy1_x2;    //x axis turn left and right
    int leftPower = drivePower + turnPower;    //compute the left wheel power
    int rightPower = drivePower - turnPower;    //compute the right wheel power

    //
    // Limit the left wheel power to the range of -100 to 100.
    //
    if (leftPower > 100)
    {
        leftPower = 100;
    }
    else if (leftPower < -100)
    {
        leftPower = -100;
    }

    //
    // Limit the right wheel power to the range of -100 to 100.
    //
    if (rightPower > 100)
    {
        rightPower = 100;
    }
    else if (rightPower < -100)
    {
        rightPower = -100;
    }

    //
    // Program the motors.
    //
    motor[driveL] = leftPower;
    motor[driver] = rightPower;

    wait1Msec(100);
}

This is not the best algorithm but it will work.

Author:  MHTS [ Thu Nov 08, 2012 12:19 am ]
Post subject:  Re: One more thing.

ducttape wrote:
Did I program the D-pad right? was a bit confused when I did that.
Code:
if (joy1_TopHat == 0)
{
   motor[Lift1] = 75;
   motor[Lift2] = 75; // Lift goes up at 75 power
}
 if (joy1_TopHat == 4)
{
   motor[Lift1] = -75;
   motor[Lift2] = -75;// Lift goes down at 75
}

No, this code doesn't work. If I read the code correctly, if you press UP on the D-PAD, the lift goes up at 75% power. If you press DOWN, it goes down at 75% power, but who stops it when nothing is pressed or other direction is pressed? What you really meant was:
Code:
if (joy1_TopHat == 0)
{
   motor[Lift1] = 75;
   motor[Lift2] = 75; // Lift goes up at 75 power
}
else if (joy1_TopHat == 4)
{
   motor[Lift1] = -75;
   motor[Lift2] = -75;// Lift goes down at 75
}
else
{
   motor[Lift1] = 0;
   motor[Lift2] = 0;// stop the lift
}

Author:  ducttape [ Thu Nov 08, 2012 9:18 am ]
Post subject:  Re: No erros... Still doesn't work.

Thanks for the help!

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