Mr. 1033
21-01-2014, 08:09
Has anyone programmed the Multiplexer with robotc?
We have been working on it and found the following resource:
http://www.robotshop.com/media/files/pdf/htsmux-tutorial-latest-nsx2020.pdf
We were kind of hoping it was a little simpler.
Anyone know of any other way to use it?
Thanks!
Yes, we are using the sensor multiplexor, using the 3rd party driver suite
Here is the appropriate part of our autonomous program. Hope it helps.
#pragma config(Hubs, S2, HTMotor, HTServo, HTMotor, none)
#pragma config(Sensor, S1, HTSMUX, sensorI2CCustom)
#pragma config(Sensor, S3, IRsensor, sensorI2CCustom)
#pragma config(Sensor, S4, GyroSensor, sensorI2CHiTechnicGyro)
#pragma config(Motor, motorA, BlockDrop, tmotorNXT, PIDControl, encoder)
#pragma config(Motor, mtr_S2_C1_1, winch, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C1_2, right, tmotorTetrix, openLoop, encoder)
#pragma config(Motor, mtr_S2_C3_1, arm, tmotorTetrix, openLoop)
#pragma config(Motor, mtr_S2_C3_2, left, tmotorTetrix, openLoop, reversed)
#pragma config(Servo, srvo_S2_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S2_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S2_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S2_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S2_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S2_C2_6, grabber, tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "drivers/hitechnic-gyro.h"
#include "drivers/hitechnic-irseeker-v2.h"
#include "drivers/hitechnic-sensormux.h"
#include "drivers/lego-light.h"
#include "JoystickDriver.c"
const tMUXSensor LightSensorLeft = msensor_S1_1;
const tMUXSensor LightSensorRight = msensor_S1_4;
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Global variables
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
int initialLightLeft, initialLightRight;
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Checks whether light sensor sees white line
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
bool LeftOnBlack(){ //returns true if left light sensor is on black
return (LSvalNorm(LightSensorLeft) <= 10 + initialLightLeft);
}
bool RightOnBlack(){ //returns true if right light sensor is on black
return (LSvalNorm(LightSensorRight) <= 10 + initialLightRight);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// initializeRobot
/////////////////////////////////////////////////////////////////////////////////////////////////////
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.
LSsetActive(LightSensorLeft);//turn on the light
LSsetActive(LightSensorRight);//turn on the light
initialLightLeft=LSvalNorm(LightSensorLeft);
initialLightRight=LSvalNorm(LightSensorRight);
return;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Main Task
//
/////////////////////////////////////////////////////////////////////////////////////////////////////
task main()
{
initializeRobot();
StartTask(printStuff);
waitForStart(); // Wait for the beginning of autonomous phase.
motor[right]=30;motor[left]=30;
//wait until one of the sensors sees white
while (LeftOnBlack() && RightOnBlack() ) {
wait1Msec(1);
}
motor[right]=0;motor[left]=0;
PlaySound(soundBeepBeep);
wait10Msec(50);
}
Our team also uses the HiTechnics Sensor MUX. In fact, we use two of them. Our robot is fully loaded with sensors (8 in total). We actually wish to add one more but ran out of ports, the other two sensor ports are for the motor chains.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.