I want to use the same code base for two separate bots (different size for robot config), but don’t know the best way to differentiate both bots.
I know one will be using a distance sensor and one isn’t. However, I don’t know how I’d detect if the sensor is detected.
Say, bot1 uses the sensor, so maybe I can have an if/then statement that assigns the bot its corresponding size. And bot2, who doesn’t have the sensor, would be assigned its own size.
I’m using a VexV5 brain and I’m not sure how to check for the sensor.
Appreciate any help/advice–> maybe there’s a better way to differentiate than using a sensor?
then when building for your other robot you can set the variable to false, which means that the program won’t run.
If your also using vex code pro, you could use the .is_installed() function to do it dynamically really easily.
I don’t know what you’re trying to do, but I would recommend using two different programs for different robots. I can only think of bad things happening later down the line.
I believe the issue that he is having is that he wants to download the same code to two different robots, and the majority of the code will be the same, but there will be a couple of differences for the robot that has the distance sensor.
Similar to if he was developing an app and wanted to use the same source code for both iPhone and android but wanted to add a log in with Apple feature to the iPhone, he needs to be able to identify which robot is which.
I do not currently have access to a brain otherwise I would test out a couple of ideas, but if no one has solved your issue by the time I get back to our lab, I will take a look at it.
Add a sensor (optical, distance, etc.) to both robots. If you use a distance then on one robot put something right in front of the sensor and on the other put something 5in infront. Then, use the value from the sensor to determine which robot it is.
Install a distance sensor on both using the same port and tape over (or just cover) the one on the bot which won’t use it. Then, on startup, test if the value is less than 5mm, and if so, it’s the bot which won’t use the sensor. Otherwise, it’s the bot that will use it. Make sure the untaped bot always starts the program with the sensor clear so the program doesn’t mistake it for the other bot.
@Jouza had the right idea, just test to see if the sensor is installed on the port using the installed() function. Alternatively, do something like using a jumper in a 3wire port on one of the robots and test for that.
Yes, the two bots just have to be initialized with different dimension variables [e.g. width, wheel size, etc] but will be running on the same code base.
Using just code, I’d combine the suggestions of both @jpearman and @Jouza to use the Installed command to set the state of a Boolean used to tell which robot is the code is running on and run the respective code.
Alternatively, you could code the program to detect if the brain is pressed or not within the first 5 seconds, and if so run the respective code. The brain touchscreen is a built in usable sensor on both robots, but this idea may not be applicable if your brain is in a hard to reach location.