|
|
|
@ -7,8 +7,18 @@
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
struct FragmentLink {
|
|
|
|
|
struct Fragment fragment;
|
|
|
|
|
struct FragmentLink *next;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct RobotImp {
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
struct FragmentLink *head;
|
|
|
|
|
struct FragmentLink *free;
|
|
|
|
|
} frag_queue;
|
|
|
|
|
|
|
|
|
|
struct Client* client;
|
|
|
|
|
uint16_t seq;
|
|
|
|
|
|
|
|
|
@ -33,6 +43,7 @@ struct RobotImp {
|
|
|
|
|
SETTING_SDK_CONNECTION,
|
|
|
|
|
CONNECTING_TO_DEVICE_PORT,
|
|
|
|
|
SETTING_SDK_MODE,
|
|
|
|
|
STREAMING_ENABLED,
|
|
|
|
|
RESETTING_SUBNODE,
|
|
|
|
|
SUSBCRIBING_SUBNODE,
|
|
|
|
|
SETTING_MOVEMENT_MODE,
|
|
|
|
@ -98,6 +109,61 @@ robot_heartbeat(Robot robot) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
enqueue_fragment (
|
|
|
|
|
Robot robot,
|
|
|
|
|
const struct Fragment fragment ) {
|
|
|
|
|
|
|
|
|
|
struct FragmentLink *link;
|
|
|
|
|
if(robot->frag_queue.free) {
|
|
|
|
|
link = robot->frag_queue.free;
|
|
|
|
|
robot->frag_queue.free = link->next;
|
|
|
|
|
} else {
|
|
|
|
|
link = malloc(sizeof(struct FragmentLink));
|
|
|
|
|
link->next = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
link->fragment = fragment;
|
|
|
|
|
|
|
|
|
|
if(robot->frag_queue.head) {
|
|
|
|
|
robot->frag_queue.head->next = link;
|
|
|
|
|
} else {
|
|
|
|
|
robot->frag_queue.head = link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
dequeue_fragment (
|
|
|
|
|
Robot robot,
|
|
|
|
|
struct Fragment *fragment ) {
|
|
|
|
|
|
|
|
|
|
fragment->type = 0;
|
|
|
|
|
if(!robot->frag_queue.head)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
struct FragmentLink *link = robot->frag_queue.head;
|
|
|
|
|
*fragment = link->fragment;
|
|
|
|
|
|
|
|
|
|
robot->frag_queue.head = link->next;
|
|
|
|
|
link->next = NULL;
|
|
|
|
|
if(robot->frag_queue.free) {
|
|
|
|
|
robot->frag_queue.free->next = link;
|
|
|
|
|
} else {
|
|
|
|
|
robot->frag_queue.free = link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int robot_poll(Robot robot, struct Fragment* fragment) {
|
|
|
|
|
dequeue_fragment(robot, fragment);
|
|
|
|
|
return fragment->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
robot_work(Robot robot) {
|
|
|
|
|
|
|
|
|
@ -170,6 +236,16 @@ robot_work(Robot robot) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case STREAMING_ENABLED:
|
|
|
|
|
{
|
|
|
|
|
vision_enable (
|
|
|
|
|
&req, robot->seq++, true
|
|
|
|
|
);
|
|
|
|
|
req_send(robot->client->dev_conn, &req);
|
|
|
|
|
robot->state = READY;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case READY:
|
|
|
|
|
{
|
|
|
|
|
if(robot->dirty_wheels) {
|
|
|
|
@ -241,9 +317,42 @@ robot_work(Robot robot) {
|
|
|
|
|
|
|
|
|
|
union Message resp;
|
|
|
|
|
poll_message(robot->client, &resp);
|
|
|
|
|
if(resp.header.cmd) {
|
|
|
|
|
const struct Fragment fragment = {
|
|
|
|
|
.type = FRAGMENT_MESSAGE,
|
|
|
|
|
.message = resp
|
|
|
|
|
};
|
|
|
|
|
enqueue_fragment(robot, fragment);
|
|
|
|
|
}
|
|
|
|
|
switch(resp.header.cmd) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case STREAM_CTRL_CMD:
|
|
|
|
|
if(!resp.resp.sdkconn.retcode)
|
|
|
|
|
robot->state = STREAMING_ENABLED;
|
|
|
|
|
break;
|
|
|
|
|
case VISION_DETECT_INFO_CMD:
|
|
|
|
|
// enqueue rectangles
|
|
|
|
|
for(int i = 0; i < resp.push.vision.count; i++) {
|
|
|
|
|
int type;
|
|
|
|
|
switch(resp.push.vision.type) {
|
|
|
|
|
case VISIONTYPE_SHOULDER:
|
|
|
|
|
case VISIONTYPE_PERSON:
|
|
|
|
|
case VISIONTYPE_GESTURE:
|
|
|
|
|
case VISIONTYPE_ROBOT:
|
|
|
|
|
type = FRAGMENT_RECTANGLE;
|
|
|
|
|
case VISIONTYPE_LINE:
|
|
|
|
|
type = FRAGMENT_LINE;
|
|
|
|
|
case VISIONTYPE_MARKER:
|
|
|
|
|
type = FRAGMENT_MARKER;
|
|
|
|
|
}
|
|
|
|
|
const struct Fragment fragment = {
|
|
|
|
|
.type = type,
|
|
|
|
|
.rect = resp.push.vision.rects[i]
|
|
|
|
|
};
|
|
|
|
|
enqueue_fragment(robot, fragment);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SET_SDK_CONNECTION_CMD:
|
|
|
|
|
// TODO: Do more with this
|
|
|
|
|
if(resp.resp.sdkconn.retcode) {
|
|
|
|
|