I’m trying to make code to select autonomous through programmed buttons on the touchscreen. For testing purposes, I made the screen print the x and y values from Brain.Screen.xPosition() and Brain.Screen.yPostition(). The y-values currently range from anywhere in the 100’s to ~7,000 despite the fact that there is well less than 500 pixels. It is also seems to go lower the closer to the middle of the screen (x-values don’t seem to affect y-values). Sometimes it seems to be completely random even though the x-values are fairly consistent. Does someone know what is going on or is this normal and I just need to program around it (i.e. just ignore y values and only focus on x values)? Thanks in advance!
Doesn’t seem normal. Care to share related snippets of the code? There could be typecasting issues going on.
I have a similar problem where my y-axis values are messed up; maybe not in so much of a chaotic and random way, but definitely messed up. I can try explaining it but I think it is much easier if you just watch the video, but I will give it a go anyway.
Video: https://photos.app.goo.gl/iE56aPyG74ygoriz7
So essentially…the y-axis value increases as I approach the center of the screen and then all of a sudden shoot up anywhere from 800-900. This should not even be possible because the screen is only 239 pixels tall, right?
I first thought my code was to blame so I made a very simple code to test it but the problem persisted. Here it is:
#include "robot-config.h"
int main() {
while(true){
//Brain.Screen.setCursor(1,1); Commenting this or not does not make a difference
Brain.Screen.printAt(1,40,"X: %d",Brain.Screen.xPosition());
Brain.Screen.printAt(1,80,"Y: %d",Brain.Screen.yPosition());
//Brain.Screen.render(); This does not help either
}
}
I tried changing the origin point, originally thinking that was the problem, but it still did not help. (I should have probably put a sleep command, and maybe moved those settings outside the loop, but this is the exact code during the time the video was shot…did not want to change anything). Using Brain.Screen.Render() did not help either; still, don’t really know what that does.
Is this also a problem that the v5 brain is known to have or is this a rare case?
Also for some reason I have a feeling that the string formatting is to blame here because erratic results such as this also occurred when I used the wrong specifier with the gyro. I have no reasons for why or how, just a guess. (I have already tried just guessing a bunch of random specifiers from this website: http://www.cplusplus.com/reference/cstdio/printf/)
try changing the format string to %3d and see what happens.
Yeah, that totally worked! Although I have no idea why. The Y-Axis values now correctly represent where I touch on the screen and never go above 239!
The issue was remnants of 3 digit numbers being left on the screen.
Oh, and the 3 in front of the d clears those three characters? Sorry- I am new to c++ and I would say string formatting as well.
@Lollywash No the 3 sets the int to 3 digits in length so it always prints 3 digits. Therefore it always overrides the previous three digits.