I'm new to ROS and I'm having some trouble. I found a ROS package 'video_stream_opencv' on GitHub that I want to use, and I'd like to write some python code that subscribes to one of the image topics that package creates.
How do I import the message definition into my python code? I can't find any *.msg files in that package.
However, if I run:
rosmsg show sensor_msgs/Image
I get the message definition:
std_msgs/Header header
uint32 seq
time stamp
string frame_id
uint32 height
uint32 width
string encoding
uint8 is_bigendian
uint32 step
uint8[] data
I can then use that info to create my own .msg file, right? But then how do I import that into python?
sensor_msgs is a package that should be automatically included in your ros distribution. Since I'm not familiar with python syntax here's how you would include the correct header in a roscpp node:
#include "sensor_msgs/Image.h"
According to a short google research the corresponding python syntax would be something like
from sensor_msgs.msg import Image
Additionally you will need to let CMake know where to search the package by adding sensor_msgs-package in your packages CMakeLists.txt like this:
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg sensor_msgs)
I can't currently try this out, so please give me feedback if everything worked fine.
Related
I want to parse c source code for extracting variables and functions from it. Is there any library available for this purpose?
I tried to achieve it through query language available in tree-sitter parser generator but when I run the program it says undefined reference to the query functions used in the file even I have included the header file (api.h) containing query functions. I tried to resolve these errors but couldn't so looking for some other library which can serve the purpose.
It's better to do it with Clang (e.g. cindex Python API).
For example, to find all function definitions in a translation unit:
#!/usr/bin/env python3
import sys
import clang.cindex
def find_functions(node):
if node.kind == clang.cindex.CursorKind.FUNCTION_DECL:
nm = node.spelling
print(f"Function {nm}")
else:
for c in node.get_children():
find_functions(c)
index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])
print('Translation unit:', tu.spelling)
find_functions(tu.cursor)
Am using R Commander and trying to import a data set in Excel on a pc running Windows. Commands: Data > Import Data > from Excel file. When I do so I get the following R error message:
Loading required package: splines
Loading required package: RcmdrMisc
Loading required package: car
Loading required package: carData
Loading required package: sandwich
Loading required package: effects
lattice theme set by effectsTheme()
See ?effectsTheme for details.
Rcmdr Version 2.5-1
Attaching package: 'Rcmdr'
The following object is masked from 'package:car':
Confint
Error in xlsx_sheets(path) : Evaluation error: 'exdir' does not exist.
Don’t think it’s a problem with Excel file. Have installed R Commander three times and encountered problem consistently. Doesn’t work in csv format either. Mystery given I have RC on another pc and am not having this problem with same Excel file. What is the problem and how can I fix it?
Thanks, RB
Try using the package readxl from the tidyverse to load your file.
It's tried and true and easy to use.
First install the package from CRAN by running:
install.packages("readxl")
Then import the library: library(readxl)
And finally read your excel file into an environment variable
my_spreadsheet <- read_excel("my_excel_file.xlsx")
This should work for both .xlsx files and .xls files
For more information see https://readxl.tidyverse.org/
I built a PyQt application to showcase object detection. The detector was trained using haar classifier, whose ouptut is a cascade.xml file.
I tried to package this application using pyinstaller. However, before this, i made a resources.qrc file which i compiled.
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>cascade.xml</file>
</qresource>
</RCC>
My issue is that when i use this resource, via
:/cascade.xml
the file is not read.
What can i do to fix this.
You first need to create a python module from your .qrc file with pyrcc
pyrcc5 resources.qrc -o resources.py
The output of pyrcc then needs to be imported into your python code
import resources
Then you should be able to access the resource through ':/cascade.xml'. In some cases it may be necessary to use 'qrc:/cascade.xml'
The resource path must still, however, be treated like a file on disk. In order to access its contents you will need to read from the resource. Here's an example of how to read and parse it using lxml
import lxml.etree as etree
from PyQt5 import QtCore
# Import the resource module create by pyrcc
import resources
# QFile knows how to read Qt resources
xml_file = QtCore.QFile(':/cascade.xml')
if xml_file.open(QtCore.QFile.ReadOnly):
# Read the QFile and convert QByteArray output to python string
xml_str = str(xml_file.readAll())
# parse the xml document from string
xml_tree = etree.ElementTree(etree.fromstring(xml_str))
xml_file.close()
When trying to import JAVA modules I receive an error:
// JAVA imports
import lang::java::jdt::Java;
import lang::java::jdt::JDT;
import lang::java::jdt::JavaADT;
Could not load lang::java::jdt::Java
In the console:
rascal>import lang::java::jdt::Java;
|prompt:///|(0,29,<1,0>,<1,29>): Could not import module lang::java::jdt::Java: can not find in search path
Advice: |http://tutor.rascal-mpl.org/Errors/Static/ModuleImport/ModuleImport.html|
I'm using Eclipse and am trying to use the AstNode datatype. Any ideas?
The JDT modules have been replaced a while back by the m3 model.
While they are a bit different, the AST part should be comparable.
Check the m3 ast documentation and the Measuring java recipe.
Is this an old project you are trying to get up and running?
I understand how to import one dart-polymer package into another package and use a component from the imported package.
There seems to be a difference in angular2-dart.
I created an angular2-dart component in package A and import it into package B.
The specific component I want to use is NameComponent.
In polymer I would simply do the following to used the imported component's markup
<name-component></name-component>
Doing something similar does not work in angular2-dart.
I have not been able to find information on importing a component from one dart package into another for angular2-dart.
A graphical summary of what I am trying to do is shown below - package B. The name-component is from package A.
Does anyone know how this is done?
EDIT 1
After making the suggested corrections I receive the following
"P:\Program Files\Dart\dev\dart-sdk\bin\pub.bat" serve web --port=57435
Loading source assets...
Loading angular2 and dart_to_js_script_rewriter transformers...
Serving epimss_ng2_app web on http://localhost:57435
[DirectiveProcessor on epimss_ng2_reg|lib/components.dart]:
ERROR: Invalid argument (url): "Could not read asset at uri asset:epimss_ng2_reg/lib/name_component.html"
[Warning from TemplateCompiler on epimss_ng2_app|lib/app_component.ng_meta.json]:
Could not find Directive entry for name: NameComponent
. Please be aware that Dart transformers have limited support for reusable, pre-defined lists of Directives (aka "directive aliases"). See https://goo.gl/d8XPt0 for details.
Build completed with 1 errors.
[web] GET Served 13 assets.
[web] GET packages/epimss_ng2_reg/components.dart => Could not find asset epimss_ng2_reg|lib/components.dart.
[web] GET Served 17 assets.
I am going to place the components directory directly on lib and see if it makes a difference.
My package is actually packages/epimss_ng2_reg/src/components.dart.
I can only think of 2 things you might be missing.
You need to add the component to directives
#Component(..., directives: const [NameComponent]) af the parent component.
You need to add the Angular2 transformer in pubspec.yaml of the component
transformers:
angular2