Show motor_nims.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* Motor controller device interface file.
*
* By opening the device and writing in a command (in the form of an
* ascii string), a client can request the motor to move to an arbitrary
* position.
*
* The command syntax is
* move:x=<x>:y=<y>
* where <x> is x coordinate, <y> is y coordinate.
*
* In addition, the opened device will become readable immediately upon
* open, and again whenever the current position changes. Reading the
* device will report the current position.
*
*/
#ifndef __MOTOR_NIMS_H__
#define __MOTOR_NIMS_H__
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <libdev/frame_processor.h>
#include "libmisc/misc.h"
#include "libdev/status_dev.h"
#include "libdev/include/query_dev.h"
#include "link/link.h"
#include "emrun/emrun.h"
#include "sim_motor.h"
#include "stepper_motor.h"
#define MOVE_OFFSET_X 140
#define MOVE_OFFSET_Y 80
#define MOVE_RATIO_X 10
#define MOVE_RATIO_Y 25
//#define CONVERSION
#undef CONVERSION
#define MAX_TEST_POINTS 20
#define NIMS_MOTOR_CONTROLLER_DEV sim_path("/dev/motor/command_motor")
typedef struct motor_nims_pos {
float cx; /* current position */
float cy;
float v; /* current est. velocity */
float tx; /* target position */
float ty;
int busy:1; /*??not sure if this field is useful*/
} motor_nims_pos_t;
typedef enum motor_command {
MOTOR_MOVE,
MOTOR_POS
} motor_command_t;
/*
** Typically we put all our global state into a single structure.
** this makes our life a lot easier if we ever need "more than one".
**
** Most emstar libraries and callbacks can accept a void pointer to
** a state block like this. However, if you're feeling lazy you can
** always just declare it as a global...
**/
typedef struct motor_nims_state {
int serial_fd; /* the open fd of the serial device */
frame_context_t *frame_ref; /* a reference to the de-framing event */
status_context_t *status_ref; /* a reference to our status device */
query_context_t *query_ref; /* a reference to our query device */
/* most recent motor state */
motor_nims_pos_t pos; /* position and velocity */
struct timeval report_time; /* time of last report for computing vel */
//not sure whether this field is useful, since vel is set in the beginning
//when get chance to change velocity?? * /
struct timeval start_time; /* time when the motor started to move */
g_event_t *report_timer;
g_event_t *motor_timer;
int binary_mode_;
motor_global_info_t * sim_motor; /** could either be a simulated or a real motor */
} motor_nims_state_t;
//flags used to parse motor command
typedef enum parse_state_type {
PS_INVALID =0,
PS_BEGIN,
PS_MIDDLE,
PS_END
} parse_state_type_t;
typedef enum return_state {
MOTOR_SUCCESS,
MOTOR_NO_NEED_TO_MOVE,
MOTOR_FAIL,
MOTOR_POS_SUC
} return_state_t;
typedef struct motor_cmd_return_state {
return_state_t state;
float cx;
float cy;
} motor_cmd_return_state_t;
#define BUFSIZE 256
typedef char STRING[BUFSIZE];
long usec_diff( struct timeval * t1, struct timeval * t2);
void motor_complete_process(query_context_t *context);
int motor_process(query_context_t *q, char *command, size_t size, buf_t *print, buf_t *bin);
void motor_usage(query_context_t *q, buf_t *buf);
//frame related
int motor_handle_frame(frame_context_t *ctx, char *frame, size_t len);
int read_test_config(char *fname, float * pt_x, float *pt_y, int max_pts);
#endif
See more files for this project here
EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.
Project homepage:
http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other
mobility_control.h
motor_nims.h
raw_dc_motor_controller.h
sim_motor.h
status_verifier.h
stepper_motor.h
tcp_func.h