forked from cyberbotics/webots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotor.cpp
More file actions
156 lines (123 loc) · 3.95 KB
/
Motor.cpp
File metadata and controls
156 lines (123 loc) · 3.95 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright 1996-2023 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define WB_ALLOW_MIXING_C_AND_CPP_API
#include <webots/device.h>
#include <webots/motor.h>
#include <webots/Brake.hpp>
#include <webots/Motor.hpp>
#include <webots/PositionSensor.hpp>
#include <webots/Robot.hpp>
using namespace webots;
void Motor::setAcceleration(double acceleration) {
wb_motor_set_acceleration(getTag(), acceleration);
}
void Motor::setVelocity(double vel) {
wb_motor_set_velocity(getTag(), vel);
}
void Motor::setControlPID(double p, double i, double d) {
wb_motor_set_control_pid(getTag(), p, i, d);
}
// Force
void Motor::setForce(double force) {
wb_motor_set_force(getTag(), force);
}
void Motor::setAvailableForce(double availableForce) {
wb_motor_set_available_force(getTag(), availableForce);
}
void Motor::enableForceFeedback(int sampling_period) {
wb_motor_enable_force_feedback(getTag(), sampling_period);
}
void Motor::disableForceFeedback() {
wb_motor_disable_force_feedback(getTag());
}
int Motor::getForceFeedbackSamplingPeriod() const {
return wb_motor_get_force_feedback_sampling_period(getTag());
}
double Motor::getForceFeedback() const {
return wb_motor_get_force_feedback(getTag());
}
// Torque
void Motor::setTorque(double torque) {
wb_motor_set_force(getTag(), torque);
}
void Motor::setAvailableTorque(double availableTorque) {
wb_motor_set_available_force(getTag(), availableTorque);
}
double Motor::getTorqueFeedback() const {
return wb_motor_get_force_feedback(getTag());
}
void Motor::enableTorqueFeedback(int sampling_period) {
wb_motor_enable_force_feedback(getTag(), sampling_period);
}
void Motor::disableTorqueFeedback() {
wb_motor_disable_force_feedback(getTag());
}
int Motor::getTorqueFeedbackSamplingPeriod() const {
return wb_motor_get_force_feedback_sampling_period(getTag());
}
void Motor::setPosition(double position) {
wb_motor_set_position(getTag(), position);
}
Motor::Type Motor::getType() const {
return Type(wb_motor_get_type(getTag()));
}
double Motor::getTargetPosition() const {
return wb_motor_get_target_position(getTag());
}
double Motor::getMinPosition() const {
return wb_motor_get_min_position(getTag());
}
double Motor::getMaxPosition() const {
return wb_motor_get_max_position(getTag());
}
double Motor::getVelocity() const {
return wb_motor_get_velocity(getTag());
}
double Motor::getMaxVelocity() const {
return wb_motor_get_max_velocity(getTag());
}
double Motor::getAcceleration() const {
return wb_motor_get_acceleration(getTag());
}
double Motor::getAvailableForce() const {
return wb_motor_get_available_force(getTag());
}
double Motor::getMaxForce() const {
return wb_motor_get_max_force(getTag());
}
double Motor::getAvailableTorque() const {
return wb_motor_get_available_torque(getTag());
}
double Motor::getMaxTorque() const {
return wb_motor_get_max_torque(getTag());
}
double Motor::getMultiplier() const {
return wb_motor_get_multiplier(getTag());
}
Brake *Motor::getBrake() {
if (brake == NULL)
brake = dynamic_cast<Brake *>(Robot::getDeviceFromTag(getBrakeTag()));
return brake;
}
int Motor::getBrakeTag() const {
return wb_motor_get_brake(getTag());
}
PositionSensor *Motor::getPositionSensor() {
if (positionSensor == NULL)
positionSensor = dynamic_cast<PositionSensor *>(Robot::getDeviceFromTag(getPositionSensorTag()));
return positionSensor;
}
int Motor::getPositionSensorTag() const {
return wb_motor_get_position_sensor(getTag());
}