Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-attempting rosserial for VEX Cortex #380

Merged
merged 14 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rosserial_vex_cortex/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Changelog for package rosserial_vex_cortex
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
0.1.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all rosserial packages should have the same version number so it should be 0.7.7. But I may be wrong. See with @mikepurvis

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, about to re-commit because my commit broke the building (oops).

-----------------------------
- README fixes
- started tagging versions
- removed unnessary parts of project structure, now depends on rosseril_arduino for message generation.

0.1.0
-----------------------------
Expand Down
26 changes: 3 additions & 23 deletions rosserial_vex_cortex/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
cmake_minimum_required(VERSION 2.8.3)
project(rosserial_vex_cortex)

find_package(catkin REQUIRED COMPONENTS
message_generation
find_package(
catkin REQUIRED COMPONENTS
)

# put the names of custom message files here
# add_message_files(FILES
#
# )

# put the names of custom service files here
# add_service_files(FILES
#
# )

catkin_python_setup()

# uncomment once you include some messages
# generate_messages()

catkin_package(
CATKIN_DEPENDS message_runtime
CATKIN_DEPENDS
)

install(
Expand All @@ -33,8 +18,3 @@ install(
PROGRAMS scripts/genproject.sh
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

catkin_install_python(
PROGRAMS src/${PROJECT_NAME}/make_libraries.py
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
76 changes: 56 additions & 20 deletions rosserial_vex_cortex/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# rosserial for VEX Cortex

This package contains everything needed allow you to run rosserial on the [VEX Cortex](https://www.vexrobotics.com/276-2194.html), on the [PROS Kernel](https://pros.cs.purdue.edu/cortex/index.html).
This package contains everything needed to run rosserial on the [VEX Cortex](https://www.vexrobotics.com/276-2194.html), on the [PROS Kernel](https://pros.cs.purdue.edu/cortex/index.html).

# Requirements
1. Linux (Only tested on Ubuntu 18.04LTS)
2. ROS (Only tested on ROS Melodic) - [installation guide](http://wiki.ros.org/melodic/Installation/Source).
3. PROS - [installation guide](https://pros.cs.purdue.edu/cortex/getting-started/index.html)
Software:
1. Linux (Only tested on Ubuntu 18.04LTS) (possible, but not tested, on windows + virtual machines with USB support)
2. ROS installed on Linux (Only tested on ROS Melodic) - [installation guide](http://wiki.ros.org/melodic/Installation/Source).
3. PROS installed on Linux - [installation guide](https://pros.cs.purdue.edu/cortex/getting-started/index.html)
Hardware:
1. VEX essentials: VEX Cortex, Joystick, VexNet keys, battery
2. VEX Programming Cable
3. (recommended, for debugging) a [USB-serial adapter](https://www.adafruit.com/product/954)
4. Three Male-Male jumper wires for USB-serial adapter

# Setup
Setup a ROS workspace and build rosserial packages (including rosserial_vex_cortex) from source:
Expand All @@ -19,8 +25,8 @@ catkin_make
catkin_make install # this will generate folders in the workspace that contain executable scripts.
```

# Usage Example(Linux)
This will show you how to run the "hello world" example PROS project.
# Usage Example (Linux)
This will show you how to run the "hello world" example PROS project. Plug in the VEX Programming cable to the computer and the joystick, plug the VexNet keys into the Cortex and the joystick. Power cycle the Joystick and Cortex between cortex downloads for optimal usage.

### Step 1 : Run the ROS instance
open a terminal window and run:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/open/Open/

Expand Down Expand Up @@ -49,6 +55,7 @@ This is how rosserial clients are able to communicate with the ROS system.
source <your-workspace-name>/install/setup.bash
rosrun rosserial_arduino serial_node.py _port:=/dev/ttyACM0 _baud:=115200
```
see the `Serial Connections` section below, for more information about how the serial ports are used.

### Step 4: Display a topic in a terminal (technically optional)
open another terminal window and run:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/open/Open/

Expand All @@ -61,28 +68,57 @@ this will display any messages that come through on the "chatter" topic.
If everyting is working properly, then the terminal from step 2 should show outputs of `"Hello World!"` This means the bridge between the cortex and ROS is established.
You are now able to use ROS with the VEX Cortex!

# Debugging on Cortex
PROS does not provide a debugger, but it does provide printing.
use vexroslog(char* out, ...) just like you would use fprintf from the PROS API:

# Physical Serial Connections
The optimal setup for this project is with two physical serial connections, one for rosserial to function, and one for debugging. The default connection for rosserial is the VEX Programming Cable, and the default debugging serial connection is UART2.

Since the The VEX programming cable provides the default rosserial connection, the baud rate of the ROS serial connecting node must be 115200 Hz, which is why the command reads:

```bash
vexroslog("hello, my favorite number is %d", 3);
rosserial_arduino serial_node _port:=/dev/ttyACM0 _baud:=115200
```
remember to include this header in your code for logging!
This overrides the default (57600) Hz.To switch the rosserial/debug serial connections, see `logger.h` in your generated PROS project. If you do end up using UART1 or UART2 for rosserial instead of debugging, update the USB device argument: `_port:=/dev/ttyUSB0` instead, and update the baud rate argument, or simply remove it for the default 57600 Hz.

`include/logger.h`, you can change which serial output to use (stdin/stdout, uart1, or uart2) for debugging.
Also, the USB device path for the VEX Programming cable on linux may either be `/dev/ttyACM0` or `/dev/ttyACM1`. To figure out which to use as an argument, use `pros lsusb`, or unplug/replug the cable from/into the computer and run `dmesg` and look at the last lines.

to view serial output from UART2, (instead of running `pros terminal`, which only works for stdout), use screen:
Viewing the UART debug stream requires a [USB-serial adapter](https://www.adafruit.com/product/954) for your computer, and it needs to be plugged in correctly.
To set up the wires with the cable linked above, use this layout:
[layout](./uartdiagram.png)
You need male-male jumper wires to plug in this adapter.
Run `dmesg` right after plugging in the adapter to identify the USB device path - it is most likely `/dev/ttyUSB0`.

To view serial output from UART2, (instead of running `pros terminal`, which only works for the VEX Programming cable), use screen:
```bash
# to install screen: sudo apt-get install screen
screen /dev/ttyUSB0
screen /dev/ttyUSB0 57600
```
note: this requires a [USB-serial adapter](https://www.adafruit.com/product/954) for your computer, and it needs to be plugged in correctly.
To set up the wires with the cable linked above, use this layout:
[layout](./uartdiagram.png)
Again, you may need to change the above command to use the correct USB device path and baud rate, if you change the default configuration.

You would need male-male jumper wires to plug in this adapter.
to view the UART
PROS does not provide a debugger, but it does provide printing.
use vexroslog(char* out, ...) just like you would use fprintf from the PROS API:

```bash
vexroslog("hello, my favorite number is %d", 3);
```
remember to include this header in your code for logging!
```cpp
#include "logger.h"
```

# Generating Custom Messages
To design you own ROS messages, it is necessary to add the `msgs` directory to this project,
add the `message_generation` dependency, and make several modifications to this project's `CMakeLists.txt`.
This infrastructure is removed from this project by default,
because there are many useful built-in message types that are used commonly across ROS packages anyway.

See documentation and source of sister packages, such as `rosserial_arduino`, for more information about generating custom messages.

# Limitations
Global scope causes segmentation faults. Do not try to use global scope. ROS-related objects in the global scope causes segmentation faults. The cause of this is still unknown, but it may have something to do with the implementation of the global memory segment.
Global scope variables causes segmentation faults. Unlike in the other rosserial examples, avoid ROS objects in the global scope.

This has been developed and tested on ROS melodic, but it should work on many earier/later versions as well.

# Speed
Over the VEX Programming cable/VexNet wireless connection, the simplest messages can stream at upwards of 200Hz. More complex messages, such as sensor_msgs::JointState, can be published at 50hz. The baud rate degrades as the distance from the cortex and the Joystick increases, however.

A wired UART1 or UART2 connection should have higher stability and frequency with arbitrarily-sized messages, with no degradation in baud rate as distance increases.
11 changes: 1 addition & 10 deletions rosserial_vex_cortex/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
rosserial for Cortex/AVR platforms.
</description>
<author>Cannon</author>
<maintainer email="cannonator@gmail.com">Cannon Tuttle</maintainer>
<maintainer email="canyonturtle@gmail.com">Canyon Turtle</maintainer>
<license>BSD</license>
<!--<url>http://ros.org/wiki/rosserial_arduino</url>-->

<buildtool_depend>catkin</buildtool_depend>

<build_depend>message_generation</build_depend>

<!--<run_depend>arduino-core</run_depend>-->
<run_depend>rospy</run_depend>
<run_depend>rosserial_msgs</run_depend>
<run_depend>rosserial_client</run_depend>
<run_depend>message_runtime</run_depend>
<run_depend>rosserial_python</run_depend>
</package>
11 changes: 0 additions & 11 deletions rosserial_vex_cortex/setup.py

This file was deleted.

10 changes: 4 additions & 6 deletions rosserial_vex_cortex/src/ros_lib/CortexHardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@

class CortexHardware {
public:
CortexHardware() {
}
CortexHardware() {}

// any initialization code necessary to use the serial port
void init() {
// uart2 is for debugging, while stdout is initialized automatically.
usartInit(uart2, 115200, SERIAL_8N1);
}
// note: the serial port initialization for rosserial for VEX Cortex must be implemented in `src/init.cpp`
// see that file for more information.
void init() {}

// read a byte from the serial port. -1 = failure
int read() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ inline void setup()
// debug logging
vexroslog("\n\n\n\n\r\t\tROSserial for VEX Cortex V2 - June 2018 - START\n\n\n\n\n\r");

// make a node handle object, string message, and publisher for that message.
ros::NodeHandle nh;
std_msgs::String str_msg;
ros::Publisher chatter("chatter\0", &str_msg);

// set up rosserial, and prepare to publish the chatter message
nh.initNode();
nh.advertise(chatter);

// message data variable.
char* msg = (char*) malloc(20 * sizeof(char));
while (1) {

Expand Down
3 changes: 2 additions & 1 deletion rosserial_vex_cortex/src/ros_lib/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
* configure a UART port (usartOpen()) but cannot set up an LCD (lcdInit()).
*/
void initializeIO() {
usartInit(uart2, 115200, SERIAL_8N1);
// this is needed to configure the debug serial connection for rosserial.
usartInit(uart2, 57600, SERIAL_8N1);
}

/*
Expand Down
16 changes: 8 additions & 8 deletions rosserial_vex_cortex/src/ros_lib/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include "API.h"

// Use screen to access uart2 on the terminal with a serial-usb adapter+cable
// on device USB0 at 115200 baud: screen /dev/ttyUSB0 115200

// VEXROS defines are used only locally.

// debugging works over an alternative serial connection.
Expand All @@ -14,7 +11,12 @@
#define VEXROS_DEBUG_MODE 0

// which serial connection to output debug messages on.
// To switch the serial connections, switch these values.
// note that stdin/stdout being seperate is unique - stdin/stdout can both be replaced with either uart1 or uart2,
// because UART1 and UART2 work as both input and output serial connections.
#define VEXROS_DEBUG_OUTPUT_SERIAL uart2
#define VEXROS_ROSSERIAL_OUTPUT_SERIAL stdout
#define VEXROS_ROSSERIAL_INPUT_SERIAL stdin

// logging function for debugging via print statements in the PROS environment.
// this macro simply adds formatting ontop of the regular pros frintf function.
Expand All @@ -23,11 +25,9 @@
#define vexroslog(fmtstr, ...) fprintf((VEXROS_DEBUG_OUTPUT_SERIAL ), "[%d]: " " " fmtstr " " "\r\n", millis() ,##__VA_ARGS__)

// will print to stdout, used by the serial client.;
// note: stdin/stdout can both be replaced with uart1 or uart2, note that stdin/stdout being seperate is unique
// with uart1/uart2, they work as both reading and writing serial connections.
#define vexroswrite(...) fprintf((stdout), __VA_ARGS__)
#define vexroswritechar(ch) fputc(ch, stdout)
#define vexrosreadchar() fgetc(stdin)
#define vexroswrite(...) fprintf((VEXROS_ROSSERIAL_OUTPUT_SERIAL), __VA_ARGS__)
#define vexroswritechar(ch) fputc(ch, VEXROS_ROSSERIAL_OUTPUT_SERIAL)
#define vexrosreadchar() fgetc(VEXROS_ROSSERIAL_INPUT_SERIAL)

// will only print if debug mode is on (see top of this file).
#define vexroslogdebug(fmtstr, ...) { \
Expand Down
2 changes: 1 addition & 1 deletion rosserial_vex_cortex/src/ros_lib/ros.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "CortexHardware.h"

namespace ros {
typedef NodeHandle_<CortexHardware, 2, 2, 128, 128> NodeHandle;
typedef NodeHandle_<CortexHardware> NodeHandle;
}

#endif
91 changes: 0 additions & 91 deletions rosserial_vex_cortex/src/rosserial_vex_cortex/make_libraries.py

This file was deleted.