File size: 3,626 Bytes
0551bb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Test jogging to compare UI jogging vs homing jogging."""

import time
import json
import sys
import os

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from test_client import NovaSimTestClient


def test_ui_jogging():
    """Test UI-style jogging (sending continuous action messages)."""
    print("\n" + "=" * 70)
    print("UI-Style Jogging Test")
    print("=" * 70)
    print("\nThis test simulates how the UI sends jogging commands.")
    print("It sends continuous 'action' messages with joint velocities.\n")

    client = NovaSimTestClient("http://localhost:3004/nova-sim/api/v1")

    try:
        client.connect()
        print("✓ Connected to Nova-Sim")

        # Get initial position
        time.sleep(0.5)
        initial_joints = client.get_joint_positions()
        print(f"\n[1] Initial joint positions:")
        print(f"    [{', '.join(f'{j:7.4f}' for j in initial_joints)}]")

        # Send continuous action messages for joint 6, like the UI does
        print(f"\n[2] Sending continuous 'action' messages (UI style)...")
        print(f"    Jogging joint 6 in negative direction for 3 seconds")

        duration = 3.0
        rate_hz = 10  # UI typically sends at ~10 Hz
        num_messages = int(duration * rate_hz)

        for i in range(num_messages):
            # Send action message with j6 velocity (like UI does)
            client.ws.send(json.dumps({
                'type': 'action',
                'data': {
                    'j6': -0.5  # Negative velocity for joint 6
                }
            }))
            time.sleep(1.0 / rate_hz)
            if (i + 1) % 10 == 0:
                print(f"    Sent {i + 1}/{num_messages} messages")

        # Stop jogging
        client.ws.send(json.dumps({
            'type': 'action',
            'data': {

            }
        }))

        time.sleep(0.5)

        # Get final position
        final_joints = client.get_joint_positions()
        print(f"\n[3] Final joint positions:")
        print(f"    [{', '.join(f'{j:7.4f}' for j in final_joints)}]")

        # Calculate movement
        movement = [abs(final - initial) for final, initial in zip(final_joints, initial_joints)]
        total_movement = sum(movement)

        print(f"\n[4] Results:")
        print(f"    Total movement: {total_movement:.4f} rad")
        print(f"    Joint 6 movement: {movement[5]:.4f} rad")
        print(f"    Joint 6 change: {initial_joints[5]:.4f} -> {final_joints[5]:.4f}")

        if movement[5] > 0.1:
            print(f"\n✓ UI jogging works - joint 6 moved {movement[5]:.4f} rad")
        else:
            print(f"\n✗ UI jogging failed - joint 6 barely moved")

        client.disconnect()
        print("✓ Disconnected")

    except Exception as e:
        print(f"\n✗ Test error: {e}")
        import traceback
        traceback.print_exc()
        try:
            client.disconnect()
        except:
            pass

if __name__ == "__main__":
    print("\n" + "=" * 70)
    print("JOGGING COMPARISON TEST")
    print("=" * 70)
    print("\nThis test compares UI jogging vs homing jogging.")
    print("Both should trigger continuous jogging, but we'll see if they behave differently.\n")

    input("Press Enter to start UI jogging test (or Ctrl+C to exit)...")
    test_ui_jogging()

    time.sleep(2)

    input("\nPress Enter to start homing jogging test (or Ctrl+C to exit)...")
    test_homing_jogging()

    print("\n" + "=" * 70)
    print("Check /tmp/nova_sim_server.log for detailed logs")
    print("Compare the 'Nova Jogger' logs from both tests")
    print("=" * 70)