forked from dusty-nv/jetson-reinforcement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmPlugin.h
107 lines (87 loc) · 2.88 KB
/
ArmPlugin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* http://github.com/dusty-nv/jetson-reinforcement
*/
#ifndef __GAZEBO_ARM_PLUGIN_H__
#define __GAZEBO_ARM_PLUGIN_H__
#include "deepRL.h"
#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/transport/transport.hh>
#include <gazebo/msgs/msgs.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>
#include <iostream>
#include <gazebo/transport/TransportTypes.hh>
#include <gazebo/msgs/MessageTypes.hh>
#include <gazebo/common/Time.hh>
#include <errno.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <pthread.h>
#include <ctype.h>
#include <stdbool.h>
#include <math.h>
#include <inttypes.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
namespace gazebo
{
/**
* ArmPlugin
*/
class ArmPlugin : public ModelPlugin
{
public:
ArmPlugin();
virtual void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/);
virtual void OnUpdate(const common::UpdateInfo & /*_info*/);
float resetPosition( uint32_t dof ); // center servo positions
bool createAgent();
bool updateAgent();
bool updateJoints();
void onCameraMsg(ConstImageStampedPtr &_msg);
void onCollisionMsg(ConstContactsPtr &contacts);
static const uint32_t DOF = 3; // active degrees of freedom in the arm
private:
float ref[DOF]; // joint reference positions
float vel[DOF]; // joint velocity control
float dT[3]; // IK delta theta
rlAgent* agent; // AI learning agent instance
bool newState; // true if a new frame needs processed
bool newReward; // true if a new reward's been issued
bool endEpisode; // true if this episode is over
float rewardHistory; // value of the last reward issued
Tensor* inputState; // pyTorch input object to the agent
void* inputBuffer[2]; // [0] for CPU and [1] for GPU
size_t inputBufferSize;
size_t inputRawWidth;
size_t inputRawHeight;
float jointRange[DOF][2]; // min/max range of each arm joint
float actionJointDelta; // amount of offset caused to a joint by an action
float actionVelDelta; // amount of velocity offset caused to a joint by an action
int maxEpisodeLength; // maximum number of frames to win episode (or <= 0 for unlimited)
int episodeFrames; // frame counter for the current episode
bool testAnimation; // true for test animation mode
bool loopAnimation; // loop the test animation while true
uint32_t animationStep;
float resetPos[DOF];
float lastGoalDistance;
float avgGoalDelta;
int successfulGrabs;
int totalRuns;
int runHistoryIdx;
int runHistoryMax;
bool runHistory[20];
physics::ModelPtr model;
event::ConnectionPtr updateConnection;
physics::JointController* j2_controller;
gazebo::transport::NodePtr cameraNode;
gazebo::transport::SubscriberPtr cameraSub;
gazebo::transport::NodePtr collisionNode;
gazebo::transport::SubscriberPtr collisionSub;
};
}
#endif