Main Page
Namespaces
Namespace List
Namespace Members
All
Variables
Typedefs
Classes
Class List
Class Members
All
Functions
Variables
Files
File List
File Members
All
Functions
Typedefs
Macros
src
ros_lib
V5Hardware.h
Go to the documentation of this file.
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Copyright (c) 2011, Willow Garage, Inc.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* * Neither the name of Willow Garage, Inc. nor the names of its
18
* contributors may be used to endorse or promote prducts derived
19
* from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*/
34
35
#ifndef _ROSSERIAL_VEX_V5_V5_HARDWARE_H_
36
#define _ROSSERIAL_VEX_V5_V5_HARDWARE_H_
37
38
#include "main.h"
39
#include "
ros_lib/rosserial_vex_v5/utils/RingBuf.h
"
40
41
// for the mutex.
42
#include "pros/apix.h"
43
44
#define SERIAL_CLASS int
45
#define ROSVEX_BUFFER_INPUT_SIZE 32
46
47
using
RB
=
RingBufCPP<char, ROSVEX_BUFFER_INPUT_SIZE>
;
48
49
// load the serial reading into a buffer.
50
inline
void
vexRosBufferInput
(
void
* arg) {
51
52
void
** arglist = (
void
**) arg;
53
RB
* inputBuffer = (
RB
*) arglist[0];
54
__FILE* streamOut = (__FILE*) arglist[1];
55
56
int
readcount = 0;
57
while
(1) {
58
char
c = fgetc(streamOut);
59
inputBuffer->
add
(c);
60
}
61
}
62
63
class
V5Hardware
{
64
65
public
:
66
V5Hardware
():
rosvexMutex
(),
inputBuffer
(
rosvexMutex
),
failCount
(),
successCount
() {
67
}
68
69
// any initialization code necessary to use the serial port
70
// note: the serial port initialization for rosserial for VEX Cortex must be implemented in `src/init.cpp`
71
// see that file for more information.
72
void
init
() {
73
serctl(SERCTL_DISABLE_COBS,
NULL
);
74
rosFile
= fopen(
"/ser/sout"
,
"r+"
);
75
76
// not typesafe, be careful!
77
void
** taskArgs = (
void
**) malloc(
sizeof
(
void
*) * 2);
78
taskArgs[0] = &
inputBuffer
;
79
taskArgs[1] =
rosFile
;
80
81
pros::Task reader(
vexRosBufferInput
, taskArgs);
82
}
83
84
// read a byte from the serial port. -1 = failure
85
int
read
() {
86
char
c;
87
// pull serial reading out of the buffer.
88
if
(
inputBuffer
.
pull
(&c)) {
89
char
sucmsg[16];
90
return
c;
91
}
92
93
return
-1;
94
}
95
96
// write data to the connection to ROS
97
void
write
(uint8_t* data,
int
length) {
98
for
(
int
i = 0; i <
length
; i++) {
99
vexroswritechar
(data[i]);
100
}
101
}
102
// returns milliseconds since start of program
103
unsigned
long
time
() {
104
return
pros::c::millis();
105
}
106
private
:
107
int
failCount
;
108
int
successCount
;
109
pros::Mutex
rosvexMutex
;
110
__FILE *
rosFile
;
111
RB
inputBuffer
;
112
113
// writing helper.
114
void
vexroswritechar
(uint8_t data) {
115
fputc(data,
rosFile
);
116
fflush(
rosFile
);
117
}
118
119
// reading helper.
120
char
vexrosreadchar
() {
121
return
fgetc(
rosFile
);
122
}
123
};
124
125
#endif
V5Hardware
Definition:
V5Hardware.h:63
V5Hardware::time
unsigned long time()
Definition:
V5Hardware.h:103
V5Hardware::rosFile
__FILE * rosFile
Definition:
V5Hardware.h:110
V5Hardware::successCount
int successCount
Definition:
V5Hardware.h:108
V5Hardware::inputBuffer
RB inputBuffer
Definition:
V5Hardware.h:111
V5Hardware::failCount
int failCount
Definition:
V5Hardware.h:107
V5Hardware::vexroswritechar
void vexroswritechar(uint8_t data)
Definition:
V5Hardware.h:114
RingBufCPP::add
bool add(Type &obj)
Definition:
RingBuf.h:51
RingBufCPP::pull
bool pull(Type *dest)
Definition:
RingBuf.h:74
V5Hardware::V5Hardware
V5Hardware()
Definition:
V5Hardware.h:66
vexRosBufferInput
void vexRosBufferInput(void *arg)
Definition:
V5Hardware.h:50
RingBuf.h
NULL
#define NULL
Definition:
RingBufHelpers.h:30
V5Hardware::rosvexMutex
pros::Mutex rosvexMutex
Definition:
V5Hardware.h:109
V5Hardware::init
void init()
Definition:
V5Hardware.h:72
length
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
V5Hardware::vexrosreadchar
char vexrosreadchar()
Definition:
V5Hardware.h:120
V5Hardware::write
void write(uint8_t *data, int length)
Definition:
V5Hardware.h:97
V5Hardware::read
int read()
Definition:
V5Hardware.h:85
RingBufCPP< char, ROSVEX_BUFFER_INPUT_SIZE >
rosserial_vex_v5
Author(s): Cannon
autogenerated on Wed Mar 2 2022 00:58:22