求助,利用ROS发送jpeg图片失败?-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2218|回复: 0

求助,利用ROS发送jpeg图片失败?

[复制链接]
发表于 2019-11-2 11:39 | 显示全部楼层 |阅读模式
本帖最后由 yimingbaba 于 2019-11-2 11:47 编辑

我从淘宝上买了一块esp32-cam的板子,编译的时候选择CAMERA_MODEL_AI_THINKER可以顺利演示CameraWebServer示例。
我计划把esp32-cam摄像头上的图片利用ros图片消息发送到pc机上,ros pub消息时esp32就崩溃了,报错如下:
Backtrace: 0x32cd94a6:0x3ffbe760 0x4008f0e0:0x3ffbe780 0x4008d9db:0x3ffbe7a0 0x400900f1:0x3ffbe7c0 0x4008703a:0x3ffbe7d0 0x400d10e6:0x3ffb1f40 0x400d1c35:0x3ffb1f60 0x400d1fc6:0x3ffb1f90 0x400d47dd:0x3ffb1fb0 0x4008d8ed:0x3ffb1fd0
ros 侧无报错信息。
程序如下:
#include "esp_camera.h"
#include <WiFi.h>
#include <ros.h>
//#include <sensor_msgs/Image.h>
#include <sensor_msgs/CompressedImage.h>
//#include <std_msgs/String.h>
#include <img_converters.h>
//#define CAMERA_MODEL_AI_THINKER
#define PWDN_GPIO_NUM     32
#define RESET_GPIO_NUM    -1
#define XCLK_GPIO_NUM      0
#define SIOD_GPIO_NUM     26
#define SIOC_GPIO_NUM     27

#define Y9_GPIO_NUM       35
#define Y8_GPIO_NUM       34
#define Y7_GPIO_NUM       39
#define Y6_GPIO_NUM       36
#define Y5_GPIO_NUM       21
#define Y4_GPIO_NUM       19
#define Y3_GPIO_NUM       18
#define Y2_GPIO_NUM        5
#define VSYNC_GPIO_NUM    25
#define HREF_GPIO_NUM     23
#define PCLK_GPIO_NUM     22
camera_fb_t * fb;
ros::NodeHandle  nh;

//sensor_msgs::Image image_msg;
//std_msgs::String image_msg;
sensor_msgs::CompressedImage image_msg;
ros:ublisher chatter("image", &image_msg,1);

const char *ssid= "接入点名称";
const char *password ="接入密码";
// Set the rosserial socket server IP address
IPAddress server(192,168,1,168);
// Set the rosserial socket server port
const uint16_t serverPort = 11411;
//control time
uint16_t period = 10000;
uint32_t last_time = 0;
void setup()
{
  Serial.begin(115200);
  //Serial.setDebugOutput(true);
  Serial.println();
//WiFi 初始化
  Serial.print("WiFi connecting");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

//ros init
  nh.getHardware()->setConnection(server, serverPort);
  nh.initNode();
  nh.advertise(chatter);
  Serial.println("ROS connected.");
//camera init
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer = LEDC_TIMER_0;
  config.pin_d0 = Y2_GPIO_NUM;
  config.pin_d1 = Y3_GPIO_NUM;
  config.pin_d2 = Y4_GPIO_NUM;
  config.pin_d3 = Y5_GPIO_NUM;
  config.pin_d4 = Y6_GPIO_NUM;
  config.pin_d5 = Y7_GPIO_NUM;
  config.pin_d6 = Y8_GPIO_NUM;
  config.pin_d7 = Y9_GPIO_NUM;
  config.pin_xclk = XCLK_GPIO_NUM;
  config.pin_pclk = PCLK_GPIO_NUM;
  config.pin_vsync = VSYNC_GPIO_NUM;
  config.pin_href = HREF_GPIO_NUM;
  config.pin_sscb_sda = SIOD_GPIO_NUM;
  config.pin_sscb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn = PWDN_GPIO_NUM;
  config.pin_reset = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;//从jpeg对应的是bgr8?
  //init with high specs to pre-allocate larger buffers
  if(psramFound()){
    config.frame_size = FRAMESIZE_UXGA;
    config.jpeg_quality = 10;
    config.fb_count = 2;
  } else {
    config.frame_size = FRAMESIZE_SVGA;
    config.jpeg_quality = 12;
    config.fb_count = 1;
  }

  // camera init
  esp_err_t err = esp_camera_init(&config);
  if (err != ESP_OK) {
    Serial.printf("Camera init failed with error 0x%x", err);
    return;
  }
    sensor_t * s = esp_camera_sensor_get();
  //initial sensors are flipped vertically and colors are a bit saturated
  if (s->id.PID == OV3660_PID) {
    s->set_vflip(s, 1);//flip it back
    s->set_brightness(s, 1);//up the blightness just a bit
    s->set_saturation(s, -2);//lower the saturation
  }
  //drop down frame size for higher initial frame rate
  s->set_framesize(s, FRAMESIZE_QVGA);
  Serial.print("Camera Ready!");
}
void loop()
{
  
    esp_camera_fb_return(fb);  //return the frame buffer back to be reused
  if(millis() - last_time >= period)
  {
    last_time = millis();
    if (!nh.connected())
    {
      Serial.println("ROS not Connected");
    }
      // Say hello
   fb= esp_camera_fb_get();  
   if (!fb) {
    Serial.println("Frame buffer could not be acquired");
   }else{
    Serial.println("Sending Jpeg!");
     image_msg.format="jpeg" ;
     Serial.println("format Jpeg ok!");
     image_msg.data_length=fb->len;
      Serial.println("data_lenth ok!");
     image_msg.data=fb->buf;   
      Serial.println("buffer ok!");
     chatter.publish( &image_msg );//执行这一步的时候就崩溃了
     //pc侧执行如下
     //roscore
     // rosrun rosserial_python serial_node.py tcp
     //rosrun image_view image_view image:=image 查看ros图像是否传送成功;
     Serial.println("JPEG is send");
   }

  }
  nh.spinOnce();
  delay(1);
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-1 02:50 , Processed in 0.070785 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表