View unanswered posts | View active topics It is currently Wed Aug 20, 2014 1:05 am






Reply to topic  [ 5 posts ] 
adding motor control problems 
Author Message
Rookie

Joined: Sat Oct 25, 2008 12:18 am
Posts: 19
Post adding motor control problems
We had some cute driving code that allows us to drive (motorD and E) in either direction as if we were driving forward with just the touch and holding of a button - that is drive normally in one case, and when the button is pressed and held we drive in the opposite direction as if it were forward.
PROBLEM - we have tried to add the control of other motors (motorF) and are having problems - the code compiles then the new motor runs without control, and there is no control of the driving motors. We've put the new motor code into Suggestions?
===CODE===
#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_1, motorF, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, , tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tele-Operation Mode Code Template
//
// This file contains a template for simplified creation of an tele-op program for an FTC
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// initializeRobot
//
// Prior to the start of tele-op mode, you may want to perform some initialization on your robot
// and the variables within your program.
//
// In most cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main Task
//
// The following is the main code for the tele-op robot operation. Customize as appropriate for
// your specific robot.
//
// Game controller / joystick information is sent periodically (about every 50 milliseconds) from
// the FMS (Field Management System) to the robot. Most tele-op programs will follow the following
// logic:
// 1. Loop forever repeating the following actions:
// 2. Get the latest game controller / joystick settings that have been received from the PC.
// 3. Perform appropriate actions based on the joystick + buttons settings. This is usually a
// simple action:
// * Joystick values are usually directly translated into power levels for a motor or
// position of a servo.
// * Buttons are usually used to start/stop a motor or cause a servo to move to a specific
// position.
// 4. Repeat the loop.
//
// Your program needs to continuously loop because you need to continuously respond to changes in
// the game controller settings.
//
// At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////



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

if(joy1Btn(8) != 0) //If Joy1-Button1 is pressed
{
motor[motorD] = joystick.joy1_y1;
motor[motorE] = joystick.joy1_y2; // Run in reverse, but steering not reversed.
if(joy2Btn(5) != 0)
{
motor[motorF] = 128; // Run the loader
}
else
{
motor[motorF] = 0
}
}
else //If Joy1-Button1 is NOT pressed
{
motor[motorD] = -joystick.joy1_y2;
motor[motorE] = -joystick.joy1_y1; // Run as "normal"
if(joy2Btn(5) != 0)
{
motor[motorF] = 128; // Run the loader
}
}
}
}

======another attempt==============

#pragma config(Hubs, S1, HTMotor, HTMotor, none, none)
#pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop, reversed)
#pragma config(Motor, mtr_S1_C2_1, motorF, tmotorNormal, openLoop)
#pragma config(Motor, mtr_S1_C2_2, , tmotorNone, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Tele-Operation Mode Code Template
//
// This file contains a template for simplified creation of an tele-op program for an FTC
// competition.
//
// You need to customize two functions with code unique to your specific robot.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

#include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// initializeRobot
//
// Prior to the start of tele-op mode, you may want to perform some initialization on your robot
// and the variables within your program.
//
// In most cases, you may not have to add any code to this function and it will remain "empty".
//
/////////////////////////////////////////////////////////////////////////////////////////////////////

void initializeRobot()
{
// Place code here to sinitialize servos to starting positions.
// Sensors are automatically configured and setup by ROBOTC. They may need a brief time to stabilize.

return;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main Task
//
// The following is the main code for the tele-op robot operation. Customize as appropriate for
// your specific robot.
//
// Game controller / joystick information is sent periodically (about every 50 milliseconds) from
// the FMS (Field Management System) to the robot. Most tele-op programs will follow the following
// logic:
// 1. Loop forever repeating the following actions:
// 2. Get the latest game controller / joystick settings that have been received from the PC.
// 3. Perform appropriate actions based on the joystick + buttons settings. This is usually a
// simple action:
// * Joystick values are usually directly translated into power levels for a motor or
// position of a servo.
// * Buttons are usually used to start/stop a motor or cause a servo to move to a specific
// position.
// 4. Repeat the loop.
//
// Your program needs to continuously loop because you need to continuously respond to changes in
// the game controller settings.
//
// At the end of the tele-op period, the FMS will autonmatically abort (stop) execution of the program.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////



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

if(joy1Btn(8) != 0) //If Joy1-Button1 is pressed
{
motor[motorD] = joystick.joy1_y1;
motor[motorE] = joystick.joy1_y2; // Run in reverse, but steering not reversed.
}
else //If Joy1-Button1 is NOT pressed
{
motor[motorD] = -joystick.joy1_y2;
motor[motorE] = -joystick.joy1_y1; // Run as "normal"
}
if(joy2Btn(5) != 0) // Run the loader
{
motor[motorF] = 128;
}
}
}


Mon Jan 11, 2010 11:12 am
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: adding motor control problems
Are you using one or two joysticks?
You may just have a typo here:
Code:
if(joy2Btn(5) != 0)

Notice that you are checking button 5 on joystick 2 (not button 5 on joystick 1).

Also, please use the code tags when you post code in the future as it makes it much easier to read.


Mon Jan 11, 2010 3:09 pm
Profile
Rookie

Joined: Sat Oct 25, 2008 12:18 am
Posts: 19
Post Re: adding motor control problems
yes, we are trying to use second joystick for button 5. We've actually tried one or two joysticks, and as I recall, got the same result.

re code tags - not sure what you mean - oh, I think I see a "code" button over the editing window - will do.

Thanks.


Mon Jan 11, 2010 11:14 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: adding motor control problems
I believe I see what you are trying to do.

I've combined your two examples as such:
Code:
//Drive train control
if(joy1Btn(8)) //If Joy1-Button1 is pressed
{
   motor[motorD] = joystick.joy1_y1;
   motor[motorE] = joystick.joy1_y2; // Run in reverse, but steering not reversed.
}
else //If Joy1-Button1 is NOT pressed
{
   motor[motorD] = -joystick.joy1_y2;
   motor[motorE] = -joystick.joy1_y1; // Run as "normal"
}

//Loader control
if(joy2Btn(5))
{
   motor[motorF] = 128; // Run the loader
}
else
{
   motor[motorF] = 0; // Stop the loader
}


Additional questions:
1) Your comment says "Joy1-Button1", but your code says "joy1Btn(8)". Are you using the buttons you think you are?
2) Are you using the dual joystick setting in the joystick debug window & sure you have both joysticks registered/working correctly?


Tue Jan 12, 2010 9:44 am
Profile
Rookie

Joined: Sat Oct 25, 2008 12:18 am
Posts: 19
Post Re: adding motor control problems
Quote:
1) Your comment says "Joy1-Button1", but your code says "joy1Btn(8)". Are you using the buttons you think you are?
2) Are you using the dual joystick setting in the joystick debug window & sure you have both joysticks registered/working correctly?


re 1 - I think the comments were not updated to reflect the code.
re 2 - we do see the second joystick in the debugger window, but I'm not sure they are both working correctly - might need to look at that.

Re code - yes, you have captured the essence - and I see that you moved the loader control outside of the driver control, so I presume that is where it is supposed to be, eh? So the loop reads driver control and then moves on to check for input on the loader control buttons. That's what we thought, but it didn't work, so we tried to incorporate into the driver control conditions - things get messy fast if done there.

Thanks, will be working on this tonight.


Tue Jan 12, 2010 12:32 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.