View unanswered posts | View active topics It is currently Fri Oct 24, 2014 5:32 pm






Reply to topic  [ 4 posts ] 
Check my code please! 
Author Message
Rookie

Joined: Thu Nov 29, 2012 9:04 pm
Posts: 7
Post Check my code please!
*****************************************************************************************************************************************
#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)
#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 !!*//

#include "JoystickDriver.c" // Tells ROBOTC to include the driver file for the joystick.
task main()
{
while(true)
{
getJoystickSettings(joystick); // Update Buttons and Joysticks

motor[motorD] = joystick.joy1_y1;
motor[motorE] = joystick.joy1_y1;

if (joystick.joy1_x1 > 0)
{
motor[motorD] = joystick.joy1_x1;
motor[motorE] = 0;
}
else
{
motor[motorE] = joystick.joy1_x1;
motor[motorD] = 0;
}
}
}
*****************************************************************************************************************************************
We're trying to control the base motors with only joystick.joy1_y1 and joystick.joy1_x1.
So what's wrong with this code? Any suggestions?


Fri Nov 30, 2012 8:46 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Check my code please!
Please use the code tag like this:
Code:
#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)
#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 !!*//

#include "JoystickDriver.c" // Tells ROBOTC to include the driver file for the joystick.

task main()
{
    while(true)
    {
        getJoystickSettings(joystick); // Update Buttons and Joysticks

        motor[motorD] = joystick.joy1_y1;
        motor[motorE] = joystick.joy1_y1;

        if (joystick.joy1_x1 > 0)
        {
            motor[motorD] = joystick.joy1_x1;
            motor[motorE] = 0;
        }
        else
        {
            motor[motorE] = joystick.joy1_x1;
            motor[motorD] = 0;
        }
    }
}

It looks like you are trying to do arcade drive. If so, it should look something like this:
Code:
#define DEADBAND_THRESHOLD 15
#define BOUND(x) (((x) > 100)? 100: ((x) < -100)? -100: (x))
#define DEADBAND(x) ((abs(x) >= DEADBAND_THRESHOLD)? x: 0)

task main()
{
    while(true)
    {
        getJoystickSettings(joystick); // Update Buttons and Joysticks

        int drivePower = DEADBAND(joystick.joy1_y1);
        int turnPower = DEADBAND(joystick.joy1_x1);

        //
        // Assuming motorD is the left wheel motor and motorE is the right wheel motor.
        //
        motor[motorD] = BOUND(drivePower + turnPower);
        motor[motorE] = BOUND(drivePower - turnPower);

        wait1Msec(100);
    }
}


Fri Nov 30, 2012 9:02 pm
Profile
Rookie

Joined: Thu Nov 29, 2012 9:04 pm
Posts: 7
Post Re: Check my code please!
Will the robot be able to move backwards in this way?


Last edited by vincent6liu on Sun Dec 02, 2012 2:11 pm, edited 1 time in total.



Fri Nov 30, 2012 10:48 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Check my code please!
Yes, it can move forward, backward, turn left and turn right. Whichever direction you want to command it.


Sat Dec 01, 2012 8:25 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.