Hi,
you were using the source code for ROSbot V1. The ROSbot 2 uses the same IR sensors, but now they are all connected to one hSens port - hSens3, through the analog multiplexer.
We updated the documentation lately and there you can find the correct source code for ROSbot V2:
The section “4.6. Following the object” that you can find under the link above contains some lines of code needed to read values from IR sensor.
//global variables
hSensor& sensMUX(hSens3);
float MUXStepTime = 50; //200ms for scan
float dis1 = 0; //Sharp LF
float dis2 = 0; //Sharp RF
float dis3 = 0; //Sharp LR
float dis4 = 0; //Sharp RR
struct hMUX{
bool p2;
bool p3;
bool p4;
bool active;
float* dis;
hMUX(bool tp2, bool tp3, bool tp4, bool tactive, float* tdis):p2(tp2), p3(tp3), p4(tp4), active(tactive), dis(tdis){}
hMUX(bool tp2, bool tp3, bool tp4, bool tactive):p2(tp2), p3(tp3), p4(tp4), active(tactive){}
};
hMUX tMUX[] = {
hMUX(false, false, false, true, &dis4),//ch0
hMUX(false, false, true, true, &dis3),//ch1
hMUX(false, true, false, false),//ch2
hMUX(false, true, true, false),//ch3
hMUX(true, false, false, false),//ch4
hMUX(true, false, true, false),//ch5
hMUX(true, true, false, true, &dis1),//ch6
hMUX(true, true, true, true, &dis2)//ch7
};
//task for reading values by multiplexer
void IRSensorReadout(){
sensMUX.pin1.enableADC();
sensMUX.pin2.setOut();
sensMUX.pin3.setOut();
sensMUX.pin4.setOut();
for(;;){
for(size_t i = 0; i<8; i++){
if(tMUX[i].active == true){
sensMUX.pin2.write(tMUX[i].p2);
sensMUX.pin3.write(tMUX[i].p3);
sensMUX.pin4.write(tMUX[i].p4);
sys.delay(MUXStepTime);
float temp = 20*(1/(sensMUX.pin1.analogReadRaw()*0.001220703));
if(temp > 30) temp = 30;
if(temp < 4) temp = 4;
*tMUX[i].dis = temp;
}
}
}
}
//creating the task - in hMain loop:
sys.taskCreate(IRSensorReadout);
After implementing the above lines of code, you should be able to read the values from dis1…dis4 variables. If you would like to use the sensors with ROS, just follow the tutorial: