You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is currently no support for serial communications over the VEX V5 brain's RS485 port. I do not have permissions to commit this fix, so here it is. I would suggest creating a new file called V5RS485.h and adding the following:
/*
Software License Agreement (BSD License)
Copyright (c) 2011, Willow Garage, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
Neither the name of Willow Garage, Inc. nor the names of its
contributors may be used to endorse or promote prducts derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
class V5RS485 {
public:
V5RS485(int readPortNum = 19, int writePortNum = 20, int baud = 115200)
{
readPort = new pros::Serial(readPortNum);
writePort = new pros::Serial(writePortNum);
readPort->set_baudrate(baud);
writePort->set_baudrate(baud);
}
void init() {
pros::delay(20);
readPort->flush();
pros::delay(100);
writePort->flush();
}
// read a byte from the serial port. -1 = failure
int read() {
int32_t read = readPort->read_byte();
if(read == PROS_ERR){
std::cout << pros::millis() << " Error read " << read << std::endl;
}
return read;
}
// write data to the connection to ROS
void write(uint8_t* data, int length) {
int freeBytes = writePort->get_write_free();
if(freeBytes > length) { // Enough bytes free in buffer
writePort->write(data, length);
//This delay is necessary to prevent too many bytes being sent at once
//This will prevent send errors
//Without this the current scheduler will not properly space out the writes
//A different solution to this issue would be to edit the scheduler to minimize no-ops
pros::delay(2);
} else {
printf("Serial buffer full!\n");
writePort->write(data, freeBytes);
pros::delay(2);
for(int i = freeBytes; i < length; i++) {
while(writePort->get_write_free() == 0) {
pros::delay(5);
}
writePort->write_byte(data[i]);
pros::delay(3);
}
}
}
// returns milliseconds since start of program
unsigned long time() { return pros::c::millis(); }
private:
//These need to be pointers
pros::Serial *readPort = nullptr;
pros::Serial *writePort = nullptr;
};
#endif
The text was updated successfully, but these errors were encountered:
There is currently no support for serial communications over the VEX V5 brain's RS485 port. I do not have permissions to commit this fix, so here it is. I would suggest creating a new file called V5RS485.h and adding the following:
/*
*/
#ifndef ROSSERIAL_VEX_V5_V5_V5RS485_H
#define ROSSERIAL_VEX_V5_V5_V5RS485_H
#include "pros/apix.h"
class V5RS485 {
public:
V5RS485(int readPortNum = 19, int writePortNum = 20, int baud = 115200)
{
readPort = new pros::Serial(readPortNum);
writePort = new pros::Serial(writePortNum);
readPort->set_baudrate(baud);
writePort->set_baudrate(baud);
}
private:
//These need to be pointers
pros::Serial *readPort = nullptr;
pros::Serial *writePort = nullptr;
};
#endif
The text was updated successfully, but these errors were encountered: