xTigr
November 30, 2022, 9:34pm
8
Optical sensor update rates:
The optical sensor will send back data to the the brain every 20mS, however, to make the sensor sensitive enough to light the default integration time is 103mS, that means that normally you will see values change approximately every 100mS. The integration time can be changed in VEXcode as necessary, the relevant APIs are.
/**
* @brief set sensor integration time
*/
void integrationTime( double timeMs );
/**
* @brief get sensor integration time…
4 Likes
Vex Electronics Taken Apart:
I got some requests to post the pictures I took while disassembling and reassembling my V5 components, so here they are.
[DISCLAIMER: Don’t take this as a guide in any way. Don’t do this unless you really know what you are doing and are willing to replace the part you are messing with. For the curious of you (like me), I took pictures so you wouldn’t have to do this.]
Let’s start things off with the motor:
Front cap removed:
[Photo Sep 05, 4 23 00 PM.jpg]
Casing separated:
[Photo Sep 05, …
4 Likes
xTigr
February 17, 2023, 2:26pm
11
controller::button::PRESSED:
Here, a couple of examples for you. Obviously move most of the code into usercontrol, except leave the event registration in main if you go that route.
This one using the button pressing() API, it detects the release to press transition.
example using pressing and state flags /*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp …
3 Likes
The guido class, which is generally never used by customers although could be, looks like this.
namespace vex {
class guido {
public:
guido(){};
virtual ~guido(){};
// pure virtual methods that must be implemented
virtual double angle( rotationUnits units = rotationUnits::deg ) = 0;
virtual double heading( rotationUnits units = rotationUnits::deg ) = 0;
virtual void calibrate( int32_t value ) = 0;
virtual bool isCalibrating(void) = 0;
virtual void setHeading( double value, rotationUnits units ) = 0;
virtual double rotation( rotationUnits units = rotationUnits::deg ) = 0;
virtual void setRotation( double value, rotationUnits units ) = 0;
virtual turnType getTurnType( void ) = 0;
};
};
how the GPS and gyro works
2 Likes
A few finds from messing around this season, including some random fun facts.
vex::vision::code
is largely undocumented/unexplained. I believe these work similar to Pixy2 Vision Codes
Suprisingly, vex::pneumatics
isn’t listed anywhere on VEX help resources (they recommend using digital_out
instead). This offers an easier abstraction over digital_out
.
vex::this_thread::sleep_for();
offers an alternative API to vex::task::sleep
, which better matches the standard library implementation of threads.
Headers for libv5rt can be easily accessed via the vscode extension (since lv5rt.a
is a static library). api.vexcode.cloud seems to be generated on these headers using doxygen (or something similar). These include the undocumented C API, but not the actual private API (v5_apiprivate.h
is omitted from the actual production distribution of the V5 SDK).
The actual entrypoint for the V5 API is actually v5_cpp.h
and not v5_vcs.h
. v5_vcs.h
seems to be included in vex.h
as a relic of the older VEX coding studio program.
vex::competition::bStopAllTasksBetweenModes
For some reason vex::inertial::getTurnType
is marked as protected, making it impossible to tell which direction the gyro of an inertial sensor reads as positive.
VEXCode Pro is written using nw.js and uses Monaco for its internal editor.
This is documented, but not well known. vex::triport::installed
allows you to get the status and type of a triport device, similar to how smart port devices have an installed method.
vex::controller::axis::position
returns integers from [-100, 100], while vex::controller::axis::value
returns integers from [-127, 127]. This isn’t really listed anywhere, and could be a footgun if you use value instead of position.
7 Likes
Sylvie
March 7, 2023, 4:24pm
14
teehee~
there is more fun to be had here
4 Likes
LVGL running on VEXcode; uses some undocumented v5 API calls for configuring the brain display properly.
The LittleV Graphics Library (LVGL) has some nice demo code. One example is a music player demo, it needs the latest version of LVGL. I was updating the VEXcode LVGL library repo today to the latest (7.11.0) and thought it might be fun to try the music player on the V5. Works quite nicely.
[IMG_1302]
source the for project is here.
and if you want to change LVGL configuration, the vexcode lvgl library project is here.
1 Like
Vision sensor methods.
Also it’s probably important to mention the comment suggests that these could likely be removed or recieve breaking changes at any time, so probably don’t use these.
2 Likes
Details on controller position vs. value
The whole point of position() returning values in the range +/- 100 was so it could be directly used in APIs that take percentage as a parameter. We kept value() (which existed before the position() function was added) returning +/-127 as that was the traditional range for a VEX controller axis to return.
and for those interested, this is all position() does.
int32_t
controller::axis::position( percentUnits units ) const {
int32_t percent = value() * 100 / 127;
return( percent );
}
The installed() motor class member function will tell you if a motor is installed on a particular port. example of use.
while(1) {
for(int port=PORT1;port<PORT22;port++) {
vex::motor m(port);
if( m.installed() ) {
// do something with a detected motor
}
else {
// no motor on this port
}
}
this_thread::sleep_for(100);
}
detecting if motors are plugged into the brain
1 Like
ok, I see, on the product page.
That’s mostly, but not entirely, wrong.
Internally the raw data we get from the sensor is about that (IIRC, it’s actually 640x480), but it’s in a format that’s not very useful for the color detecting algorithm. That image is converted and scaled down to 316x212 for processing, that’s also the coordinate system used for sending object information back to the V5.
see this kb article.
https://kb.vex.com/hc/en-us/articles/360035951911-Using-the-Vision-Utility-wit…
size of the vision sensor is scaled down from the camera
1 Like
you could have a look at code I posed here.
or the simplified version using graphical setup here.
That’s probably a lot more than you need, it simulates the built in drive code for V5
GitHub repositories containing V5’s default “Drive” program. Useful as a reference for implementing joystick control, or for those programming clawbots, I guess.
2 Likes
If updating from 1.1.1 to 1.1.2, the components that are updated will be.
Internal power control firmware
Inertial sensor
GPS
3-wire port firmware
motors, controllers, everything else, is the same as in 1.1.1
updated part firmware for vexOS 1.1.2
1 Like
It’s essentially the same.
The issue we have is that there is no way to detect a gen2 battery from an older gen1 battery. Gen2 batteries have a much flatter discharge curve, voltage will drop quickly during perhaps last 15% of capacity. We could have tried to add some fancy code looking at voltage over time, but in the end we just decided to keep it simple and do what we did in gen1.
// full range 6400mV to 8200mV
int32_t percent = (volts - 6400) / 18;
// limit to 5% increments
percent = (pe…
IQ gen2 battery percentage
Yes, with the correct tools you could recover Python source code from the brain.
yes, Python source is “compiled” to byte code by the interpreter before it runs (to improve execution speed).
python code is compiled on the brain
1 Like
Noto Sans (various different parts). But we don’t use them directly, they had to be rasterized and compressed.
the font the v5 brain uses
2 Likes
whoa, a scavenger hunt for vex? havnt seen one of these in a while! why dont we bring one to states and or worlds this year?
1 Like
It mainly has been just me posting in this thread for a while, the original scavenger hunt got locked with all the other meme threads when Vex removed a lot of posts.
6 Likes
Pi_way
September 19, 2023, 2:41am
27
A vex::task object does not have to be a function reference:
yea, you have to use a static member function as a callback for tasks (and threads). However, you can pass the current class instance as a parameter to the callback and use that to do instance specific things. Here’s a simple example.
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: …
There is …probably…? a hook in Python, which will yield to the brain’s task scheduler each loop iteration. (calling wait(20, MILLESECONDS) is not strictly required in Python).
Just use sleep (or wait, same thing), wait(1, MSEC) is the closest you can get, there is no binding for yield.
You may also find that just having no delay (sleep etc.) in the loop works, I think I have a hook that calls yield for each loop iteration so python doesn’t ever block the scheduler.
but yield is rarely needed even in C++ code, what’s the actual use case ?
Connecting 2 cortex brains:
Summary
The code linked at the end of this post allows two cortex controllers to be connected using their UART ports. The master cortex (with VEXnet and joystick) controls the slave cortex (no VEXnet) using the example communications protocol.
**Background
**
I’ve posted about serial communications before in the ROBOTC programming tips thread , however, I wanted to show an example that was a little more developed with bi-directional communication between two devices.
For some of the product…
4 Likes