View unanswered posts | View active topics It is currently Sat Apr 19, 2014 12:08 pm






Reply to topic  [ 4 posts ] 
Refer to motor in function 
Author Message
Rookie

Joined: Mon Jun 11, 2012 9:28 pm
Posts: 37
Post Refer to motor in function
Hello everyone,

I am somewhat of a beginner so sorry if this is a simple question...
I name all my motors, it seems like the best practice.
I have a function which controls a motor, and I want to be able to choose which motor the function applies to when I call it. If I use a string variable in the function declaration and put this in the motor command, I get lots of array errors.
So, how do I do this?

Many thanks,
sqiddster


Mon Jun 11, 2012 9:31 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Refer to motor in function
Could you please post your code? Put it in the
Code:
[code][/code]
tags.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon Jun 11, 2012 9:35 pm
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: Refer to motor in function
Do you mean something like this?
Code:
#pragma config(Motor,  motorA,          rightMotor,    tmotorNormal, openLoop, encoder)
#pragma config(Motor,  motorC,          leftMotor,     tmotorNormal, openLoop, encoder)

void SetMotorPower(tMotor motorID, int power)
{
    motor[motorID] = power;
}


Mon Jun 11, 2012 9:53 pm
Profile
Rookie

Joined: Mon Jun 11, 2012 9:28 pm
Posts: 37
Post Re: Refer to motor in function
MHTS wrote:
Do you mean something like this?
Code:
#pragma config(Motor,  motorA,          rightMotor,    tmotorNormal, openLoop, encoder)
#pragma config(Motor,  motorC,          leftMotor,     tmotorNormal, openLoop, encoder)

void SetMotorPower(tMotor motorID, int power)
{
    motor[motorID] = power;
}


I think that's it! So there's a variable type called tMotor... OK, cool. I was using a string.

Thanks!


Tue Jun 12, 2012 6:11 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.