第四周作业

冰球游戏软件设计

信息流示意图

信息流示意图

后台服务内部信息流示意图

后台服务

注释

  1. 为了平滑运动,尽量符合实际机器人开发中的条件,插值任务的时钟信号频率会远高于输出位置信息的时钟频率。
  2. 冰球信号只在发生碰撞后才产生事件。
  3. 插值任务、定时输出任务、调试信息输出任务已经实现。

编程作业

进度见Github仓库

插值算法类的设计

已完成实现并且在simple_motion项目中使用,可以独立编译成库文件。见Github仓库

需求分析

  1. 不同的插值算法有统一的接口,插值任务只调用基类的接口,并提供当前的时间戳。待计算完成后,插值任务再从算法对象中获取参数。
  2. 同一插值算法中,自动维护状态。提供参数保存等功能。
  3. 最好能做到独立,与工程内其它项目无依赖关系。

基类:Interpolation

头文件(Github)如下:

#pragma once

#ifndef SIMPLE_MOTION_INTERPOLATION_H
#define SIMPLE_MOTION_INTERPOLATION_H

#include <string>

typedef double TimeInS;

/**
 * Interpolation state
 */
enum InterpolationState {
    kIntNotYetConfigured,
    kIntIdle,
    kIntRunning,
    kIntDone,
    kIntError,
};

class Interpolation {
private:
    InterpolationState status;
    std::string type;

protected:
    // axis status message
    double p;
    double v;
    double a;
    double j;

    /**
     * @brief Not allow create instance directly
     */
    Interpolation();

public:
    virtual ~Interpolation();

    /**
     * @brief initialize the interpolation alogrithm (pure virtual function)
     * @param start_position start position
     * @param start_velocity start velocity
     * @return current interpolating status, only kError/kRunning
     */
    virtual InterpolationState start(const TimeInS now,
                                     const double start_position,
                                     const double start_velocity) = 0;

    /**
     * @brief interpolate once (pure virtual function)
     * @param TimeInS current time stamp
     * @return current interpolating status
     */
    virtual InterpolationState move(const TimeInS now) = 0;

    /**
     * @brief return current interpolating status
     * @return interpolating status
     */
    virtual InterpolationState get_status(void);

    /**
     * @brief return the type of this interpolation
     * @return the type of this interpolation
     */
    std::string get_type(void);

    /**
     * @brief return the position
     * @return the position
     */
    double get_position(void);

    /**
     * @brief return the velocity
     * @return the velocity
     */
    double get_velocity(void);

    /**
     * @brief return the acceleration
     * @return the acceleration
     */
    double get_acceleration(void);

    /**
     * @brief return the jerk
     * @return the jerk
     */
    double get_jerk(void);
};


#endif //SIMPLE_MOTION_INTERPOLATION_H

注释:这个类是虚基类,不能实例化,用于提供给插值任务的接口,即需求1。通过start方法来启动,并记录坐标、起始时间等信息;然后通过move方法来更新插值坐标;会返回插值状态(开始、运行中、结束);计算完成后,需要通过get_*方法来获取相应的信息。在实现具体的插值类时,需要实现start方法和move方法。

插值算法的实现

目前已经实现了线性插值(头文件)和梯形插值(头文件)。为了节省篇幅,不在这里贴代码。

posted @ 2016-12-20 22:12  路人233  阅读(311)  评论(1编辑  收藏  举报