使用rosserial_python包.
报通信错误,因为原serial_node.py及SerialClient作了修改,删除了fix_pyserial_for_test项.
使用ros自带的serial_node.py及SerialClient.py,更改一下py名字以区别,import时报错
'module' object is not callable
原因为Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要:
>>> import Person
>>> person = Person.Person('dnawo','man')
>>> print person.Name
或
>>> from Person import *
>>> person = Person('dnawo','man')
>>> print person.Name
https://blog.csdn.net/chenbo163/article/details/52526391
将spq_serial_node中的import spq_SerialClient 改为
from spq_SerialClient import * 即OK
改好后,将文件置于/opt/ros/kinetic/lib/rosserial_python下,方便使用
在使用rosserial_python时, sudo chmod 777 /dev/ttyACM0 给端口权限,然后rosserial_python serial_node.py _:port=/dev/ttyACM0...
会报link error之类的,出现连不上的情况,是因为stm32 nucleo的程序里设置了wait_ms之类的延时函数,试了下在进入这种延时函数后可能会无法连接,单片机cpu不处理.解决方法是加上其他触发条件,如按键,等连接建立了再执行ros部分的功能.
在连上后,正常收发消息时,会报Lost sync with device, restarting...
http://bediyap.com/robotics/rosserial-arduino/ 据说是RAM太小?
因为程序中订阅了robot_pose话题,估计是此话题频率太高,硬件资源不够造成.
还没有找到解决办法,但是似乎这个错误没有什么影响?
报这个错有几率会直接死机,重新订阅一个频率较低的pose topic.
以及如何修改buffer size,启动rosserial_python的serial_node时显示现在是512bytes?
加入舵机控制,SG90 9G舵机,PWM周期20ms,0.5-2.5ms控制0-180度转动范围,实际设置0.75-2.25防烧舵机
#include "mbed.h"
#include <ros.h>#include <std_msgs/String.h>
#include <geometry_msgs/Pose.h>
#include <geometry_msgs/Twist.h>
#include <stdlib.h>
DigitalOut myled(LED1);
DigitalIn myButton(USER_BUTTON);
InterruptIn buttonInt(USER_BUTTON);
//CAMERA
#define BASEPWMLEN 20000
PwmOut pwm_1(D3);
PwmOut pwm_2(D5);
/*
Timeout timer_1;
Timeout timer_2;
DigitalOut my_pwm_1(D6); // IO used by pwm_io function
DigitalOut my_pwm_2(D9); // IO used by pwm_io function
int on_delay = 0;
int off_delay = 0;
void toggleOff_1(void);
void toggleOff_2(void);
void toggleOn_1(void){
my_pwm_1 = 1;
timer_1.attach_us(toggleOff_1, on_delay);
}
void toggleOn_2(void){
my_pwm_2 = 1;
timer_2.attach_us(toggleOff_2, on_delay);
}
void toggleOff_1(void){
my_pwm_1 = 0;
timer_1.attach_us(toggleOn_1, off_delay);
}
void toggleOff_2(void){
my_pwm_2 = 0;
timer_2.attach_us(toggleOn_2, off_delay);
}
// p_us = signal period in micro_seconds
// dc = signal duty-cycle (0.0 to 1.0)
void pwm_io(int pwmindex,int p_us, float dc) {
if(pwmindex==1){
timer_1.detach();
if ((p_us == 0) || (dc == 0)) {
my_pwm_1 = 0;
return;
}
if (dc >= 1) {
my_pwm_1 = 1;
return;
}
on_delay = (int)(p_us * dc);
off_delay = p_us - on_delay;
toggleOn_1();
}
else if(pwmindex==2){
timer_2.detach();
if ((p_us == 0) || (dc == 0)) {
my_pwm_2 = 0;
return;
}