View unanswered posts | View active topics It is currently Thu Dec 18, 2014 7:53 pm






Reply to topic  [ 7 posts ] 
Dynamically accessing sensors and motors 
Author Message
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Dynamically accessing sensors and motors
If is possible to access sensors and motors based on a variable? For example:
Code:
void runMotor(string motorName, power){
  motor[motorName] = power;
}
task main(){
  runMotor(leftWheel, 115);
}

or:
Code:
int getSensorVal(string sensorName){
  return SensorValue(sensorName);
}
task main(){
  while(getSensorVal(armPot)) < 300){
    motor[arm] = 60;
  }
}


Of course, I know that these won't compile or work, but I want to be able to implement this type of functionality. I'm trying to write a library, and want to create functions that can be used in a wide variety of situations. Is there any way to accomplish what I'm trying to do?

_________________
sudo rm -rf /


Sat Jan 08, 2011 8:14 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Dynamically accessing sensors and motors
Take a look at the driver suite I've made. I pass variables for sensors all the time :) Just not as strings.

- Xander

Code:
void motorPower(tMotor _mowtoar, int powah) {
  motor[_mowtoar] = powah;
}

void sensorSomething(tSensors _sensoar, TSensorTypes _type) {
  SetSensorType(_sensoar, _type);
}

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jan 09, 2011 2:24 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Dynamically accessing sensors and motors
Of course I should have looked at your drivers! I feel dumb now :oops:. Thanks so much.

_________________
sudo rm -rf /


Sun Jan 09, 2011 10:45 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Dynamically accessing sensors and motors
No need to feel dumb.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jan 09, 2011 10:49 am
Profile WWW
Rookie

Joined: Mon Jan 10, 2011 11:39 pm
Posts: 16
Post Re: Dynamically accessing sensors and motors
Iv have already written a Framework that uses this everywhere. I even write my own commands that access the opcodes directly. Here take a look at this:
Code:
// SensorTypes - Its just like SensorType except it accepts short instead of TSensorTypes.
intrinsic short variable(SensorTypes,       opcdSourceSensorType,     kNumbOfTotalSensors, tSensors);


This allows me to change the sensor type by using my own definitions/variables that use integers instead of the default ones. not very complex but very handy.

Heres its use:
Code:
// Sensors
// This class is designed to get or set sensor values.

void SetupSensor(int iSensor, int iType);
void SensorOutput(int iSensor, int iValue);

void SetupSensor(int iSensor, int iType)
{
  SensorTypes[iSensor] = iType;
}

void SensorOutput(int iSensor, int iValue)
{
  SensorValue[iSensor] = iValue;
}

#if defined(VEX)
void SetupSensor(int iSensor, int iType, int iInterrupt);

void SetupSensor(int iSensor, int iType, int iInterrupt)
{
  SensorTypes[iSensor] = iType;
  ifiInterruptPorts[iSensor] = iInterrupt;
}
#endif

_________________
Regards
Stefan Andres Charsley
charsleysa@gmail.com


Mon Jan 10, 2011 11:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3297
Location: Rotterdam, The Netherlands
Post Re: Dynamically accessing sensors and motors
Accessing the opcodes directly is a completely unsupported way of working. There is no guarantee that the opcodes remain the same between releases, only the ROBOTC API to access them.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Jan 11, 2011 2:03 am
Profile WWW
Rookie

Joined: Mon Jan 10, 2011 11:39 pm
Posts: 16
Post Re: Dynamically accessing sensors and motors
mightor wrote:
Accessing the opcodes directly is a completely unsupported way of working. There is no guarantee that the opcodes remain the same between releases, only the ROBOTC API to access them.

- Xander


Well the RobotC API does the exact same thing as I have done there, no different! And if they change it, so will I! But they hardly ever do, they just add on to the end, so the opcode numbers have like never changed! And accessing the opcodes directly give me an advantage because I wont be limited to the RobotC API, the only restriction I have is the RobotC firmware!

_________________
Regards
Stefan Andres Charsley
charsleysa@gmail.com


Tue Jan 11, 2011 2:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.