-
Notifications
You must be signed in to change notification settings - Fork 0
/
vel_control.cpp
40 lines (38 loc) · 1.19 KB
/
vel_control.cpp
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
#include <chrono>
#include <cmath>
#include <cstdio>
#include <memory>
#include <string>
#include "odrive_cansimple_hardware_interface/cansimple_hardware_interface.hpp"
#include "odrive_cansimple_hardware_interface/cansimple_protocol.hpp"
#include "odrive_cansimple_hardware_interface/socketcan.hpp"
// expect the motor to turn once and then turn back
int main()
{
std::shared_ptr<SocketCan> can_device = std::make_shared<SocketCan>();
std::cout << "can device name?" << std::endl;
std::string can_name;
std::cin >> can_name;
can_device->open(can_name, 1e6);
odrive_cansimple_hardware_interface::CanSimpleAxis axis;
axis.configure(10, 0.05);
int id;
std::cout << "can id?" << std::endl;
std::cin >> id;
axis.attach(can_device, id);
axis.setControllerMode(0x03,0x01);
axis.setAxisRequestedState(0x08);
// NOTE:may need to adjust
//*axis.getCommandKpPtr() = 20;
//*axis.getCommandKpPtr() = 5;
axis.setGains(10, 0.01);
while (1)
{
printf("%f ", *axis.getStatePosPtr());
printf("%f\n", *axis.getStateVelPtr());
//expect the motor turn at 1 rps
*axis.getCommandVelPtr()=2*M_PI;
axis.writeCommand();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}